Leaflet Popup For Geojson Ajax
With Leaflet, how have popup on each marker when I load geojson layer with Ajax? var map = L.map('map', { center: [44.3, -0.3], zoom: 9 }); var my_layer_geoJson= new
Solution 1:
I would create the geojson layer when the data is received, like so ...
var map = L.map('map', {
center: [44.3, -0.3],
zoom: 9
});
$.ajax({
dataType: "json",
url: "geojson/data.php",
success: function(data) {
L.geoJson(data, {
onEachFeature: onEachFeature
}).addTo(map);
}
}).error(function() {});
functiononEachFeature(feature, layer) {
var popupContent = "<p>Hello world</p>";
layer.bindPopup(popupContent);
}
Here is a working example: http://plnkr.co/edit/jQVoO3KTvfCisdpkjFrI?p=preview
Post a Comment for "Leaflet Popup For Geojson Ajax"