I would like to customize a marker to add an id (number) on top of it, this id is coming from an attribute of the geojson ("id" in the following example)
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"geometry":{
"type":"Point",
"id":1,
"destination":"Police station",
"coordinates":[
"4.3520735404177699","50.846502697562201"
]
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"id":2,
"destination":"Museum",
"coordinates":[
"4.347903728485107","50.846658450225334"
]
},
...
I'm stuck with L.ExtraMarkers :
var json = L.ExtraMarkers.icon({
icon: 'fa-number',
number: 'x',
iconColor: 'white',
markerColor: 'black',
shape: 'circle',
prefix: 'fa'
});
var geojsonLayer = new L.GeoJSON.AJAX("query_json.php?&do=DCT1",{pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: json});
},
onEachFeature: function (feature,layer) {
var popup = [];
for (var prop in feature.properties) {
popup.push(prop + ": " + feature.properties[prop]);
}
layer.bindPopup(popup.join("<br />"));
}}).addTo(map);
number: 'x', should be the variable "id" coming from the geojson.
I'm also stuck with L.circleMarker :
var stylegeojson = {color:'white', fillColor:'blue', radius:10, opacity:1.0, fillOpacity:1.0, weight:2};
var geojsonLayer = new L.GeoJSON.AJAX("query_json.php?&do=DCT1", {pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, stylegeojson);
// what should I add here to print "id" value on top of it ?
},
}).addTo(map);
I think I have to add an
onEachFeature: function(feature, id) {
but I don't know to write it.
Ideally I'd also like to have a different marker color per "destination"
I am wondering if someone already did this before or has an idea how to do this?