문제 설명
전단지 geoJSON.onEachFeature는 함수가 아닌가요? (leaflet geoJSON.onEachFeature is not a function?)
img src="https://i.stack.imgur.com/ngbxs.png" alt="enter image description here"></a></p>
저는 아직 전단지를 처음 접하고 문제의 출처를 파악하는 데 어려움을 겪습니다. 내가 놓치고 있는 것이 분명합니까?
참조 솔루션
방법 1:
You get undefined because your layer has no leaflet_id, because the layer is not already added to the map.
Change your code to:
geojson = L.geoJSON(pointfixed, {
pointToLayer: function (feature, latlng){
return L.circleMarker(latlng, {
radius: 3,
fillColor: getColor(feature.properties.Coordinate),
color: "#000",
fillOpacity: 1,
weight: 1
});
},
}).addTo(map);
geojson.eachLayer(function(layer){
layer.bindPopup("<button type='button' onclick = 'addToCart(" + layer._leaflet_id +")'>Add to Cart</button>");
});
(by Ryan 、Falke Design)