How can I have a circle marker or one of a selection of icons depending on a feature's properties using LeafletAjax?
https://github.com/calvinmetcalf/leaflet-ajax
function pointToLayer(feature, latlng){
console.log(feature.properties.shape);
}
var features = new L.GeoJSON.AJAX("/features.json?circuit=555",{
pointToLayer: pointToLayer,
onEachFeature:onEachFeature,
style: function (feature) {
return feature.properties && feature.properties.style;
},
});
I've started to try to build this, but Point to layer is only called once. The console log shows just the first feature's shape.
I have also tried to add the code to the onEachFeature function:
function onEachFeature(feature,layer){
if (feature.properties.shape == 'point'){
feature.marker = L.circleMarker(latlng, {
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
}else if(feature.properties.shape == 'tree'){
feature.marker = L.marker(latlng, {icon: treeIcon});
}
if (feature.properties){
layer.bindPopup(feature.properties['popup_content']);
}
}
Which doesn't work - I have made up the "feature.marker =" bit.
How do I set the marker?
pointToLayer
, what happens if you insertreturn L.marker(latlng);
into the function? What is the result?