Have to click twice to open popup leaflet

المشرف العام

Administrator
طاقم الإدارة
I am trying to make a map in which a marker can be clicked and a popup opens up with some information. I have successfully done all of that however my first click on any of the markers result in the popup being placed randomly on the map. If I click again, the popup will place itself correctly (on top of the marker). I believe that I am doing something wrong when calling the "onEachFeature" function. Here is the code:

// Importing the data from the geojson$.getJSON("data/dhakaFactories.geojson", function(data){ dhakaFactories = L.geoJson(data, { pointToLayer: function(feature, latlng) { return L.circleMarker(latlng, style); }, onEachFeature: onEachFeature, style: style }).addTo(map);});// Action for each feature of the choroplethfunction onEachFeature(feature, layer){ console.log("onEachFeature"); layer.on({ click: highlightSelection });}// Highlighting the selected administrative areafunction highlightSelection(e){ // Some code her to add text and image to the popup dhakaFactories.bindPopup(image + text);}

أكثر...
 
أعلى