Is there any way I can add Leaflet Extramarkers to my legend? From what I googled, it seems I'll have to add an image of markers... however I was hoping I could use the ones I created.
var Icon = L.ExtraMarkers.icon({
icon: 'fa-graduation-cap',
markerColor: theIcon,
shape: 'circle',
prefix: 'fa'
});
function theIcon(ct){
if (ct == "Public"){
Icon.options.markerColor = "orange"
}
else if (ct == "Private"){
Icon.options.markerColor = "cyan"
}
else{
Icon.options.markerColor = "red"
}
return Icon
}
function style(feature, latlng){
switch (feature.properties.Sector){
case 'Public' : return L.marker(latlng,{icon: theIcon("Public")}).addTo(map);
case 'Private' : return L.marker(latlng,{icon: theIcon("Private")}).addTo(map);
}
}
var univ = new L.WFST(
{
url: 'http://localhost:8080/geoserver/HEC/wfs',
typeNS: 'HEC',
typeName: 'Unis',
crs: L.CRS.EPSG4326,
geometryField: 'the_geom',
showExisting: true,
maxFeatures: 500,
},
new L.Format.GeoJSON({
pointToLayer: style,
})
);
Edit:
Code for the legend that I am trying to create is:
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = ['Public', 'Private', 'Selected'];
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + theIcon(grades[i]) + '"></i> ' + grades[i] + '<br>';
}
return div;
};
legend.addTo(map);
markerColor
option to work, since you specifiedtheIcon
function. It should be character string, specifying marker color, and this only ifsvg
option is se totrue
.