Hi, I am using django-leaflet for displaying some geojson layers in which there are points and other geometries. My idea was to send each iconUrl in the geojson and then style each of them automatically. With polygons all the styles (fill, opacity, color...) work perfect but I can't style point marker's image. They seem to go to another layer where I can't set the style and it gets overwritten with the default style.
L.geoJson(data, {style: getStyle});
function getStyle(feature) {
// Tried different options
// Option 1 :
var icon = L.Icon.extend({ options : { iconUrl: feature.properties.icon.icon_url} });
// Option 2 :
var icon = L.Icon.extend({ iconUrl: feature.properties.icon.icon_url});
// Option 3 :
var icon = L.icon({ iconUrl: feature.properties.icon.icon_url});
return {
fillColor: feature.properties.color || 'gray',
weight: feature.properties.weight || 2,
opacity: feature.properties.border_opacity || 0.8,
color: feature.properties.border_color || 'black',
fillOpacity: feature.properties.fill_opacity || 0.5,
dashArray: feature.properties.dash_array || 1,
icon: icon,
iconUrl: feature.properties.icon.icon_url || '' // Just in case it should be this way
};
}
{
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "LineString",
"coordinates": [
[
-3.92395337374613,
38.984058965480564
],
[
-3.9220487181037775,
38.989367645629486
],
[
-3.92395337374613,
38.984058965480564
]
]
},
{
"type": "Point",
"coordinates": [
-3.92084130141269,
38.9897951477041
]
}
]
},
"type": "Feature",
"properties": {
"border_opacity": 0.1,
"dash_array": "20, 5",
"fill_opacity": 0.8,
"icon": {
"icon_url": "http://localhost:3000/static/img/ct.png"
}
}
},
{
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "LineString",
"coordinates": [
[
-3.9225556358363347,
38.995273702863386
],
[
-3.9223839614994938,
38.99636516690695
],
[
-3.9225556358363347,
38.995273702863386
]
]
},
{
"type": "Point",
"coordinates": [
-3.92427800018094,
38.9930299609743
]
}
]
},
"type": "Feature",
"properties": {
"border_opacity": 0.1,
"dash_array": "20, 5",
"fill_opacity": 0.8,
"icon": {
"icon_url": "http://localhost:3000/static/img/ct.png"
}
}
}
]
}
Everything but the iconUrl works perfectly. But as I previously said, I think markers are being created in a different layer (for them to be in front of everything), so I can't style them. Am I right or there is a way to do this?
Thank you very much.