I am using the booklet / JavaScript for the first time, and I want to display a map with a GeoJSON layer that changes with every move ... Show only points in the area.
This is my code:
// Function to refresh points to display function actualiseGeoJSON() { // Default icon for my points var defaultIcon = L.icon({ iconUrl: '../images/icones/cabane.png', iconSize: [16, 16], iconAnchor: [8, 8], popupAnchor: [0, -8] }); // We create each point with its style (from GeoJSON file) function onEachFeature(feature, layer) { var popupContent = '<a href="' + feature.properties.url + '">' + feature.properties.nom + "</a>"; layer.bindPopup(popupContent); var cabaneIcon = L.icon({ iconUrl: '../images/icones/' + feature.properties.type + '.png', iconSize: [16, 16], iconAnchor: [8, 8], popupAnchor: [0, -8] }); layer.setIcon(cabaneIcon); } // We download the GeoJSON file (by using ajax plugin) var GeoJSONlayer = L.geoJson.ajax('../exportations/exportations.php?format=geojson&bbox=' + map.getBounds().toBBoxString() + '',{ onEachFeature: onEachFeature, pointToLayer: function (feature, latlng) { return L.marker(latlng, {icon: defaultIcon}); } }).addTo(map); } // We create the map var map = L.map('map'); L.tileLayer('http://maps.refuges.info/hiking/{z}/{x}/{y}.png', { attribution: '© Contributeurs d\'<a href="http://openstreetmap.org">OpenStreetMap</a>', maxZoom: 18 }).addTo(map); // An empty base layer var GeoJSONlayer = L.geoJson().addTo(map); // Used to only show your area function onLocationFound(e) { var radius = e.accuracy / 2; L.marker(e.latlng).addTo(map); actualiseGeoJSON(); } function onLocationError(e) { alert(e.message); actualiseGeoJSON(); } function onMove() { // map.removeLayer(GeoJSONlayer); actualiseGeoJSON(); } map.locate({setView: true, maxZoom: 14}); // Datas are modified if map.on('locationerror', onLocationError); map.on('locationfound', onLocationFound); map.on('moveend', onMove);
I tried to remove the layer in my first function, but GeoJSONlayer is not defined. I tried to delete the layer in onMove (), but nothing appears. I tried to delete the layer in the moveend event, but I have a syntax error ...
If someone can help me ...
Sorry for my bad english, french guy and french function names
leosw source share