I have created a script that seperates my geojson feature collection into 3 groups with the TimeDimension plugin and it appears to work correctly until i try to add custom icons to each group. Then the part of the code that does the icon change gets ignored and default icons are being loaded
icon
var icon1 = L.icon({
iconUrl: 'img/icon1.png',
iconSize: [47, 69],
iconAnchor: [23.5, 69],
popupAnchor: [0, -69]
});
function
function onEachFeature(feature, layer) {
console.log('Feature before pointToLayer:', feature); // Debugging line
var group = feature.properties.group.toLowerCase();
console.log('Feature Group:', group); // Debugging line
console.log('Feature Properties:', feature.properties); // Debugging line
if (group === 'group1') {
group1LayerGroup.addLayer(layer);
} else if (group === 'group2') {
group2LayerGroup.addLayer(layer);
} else if (group === 'group3') {
group3LayerGroup.addLayer(layer);
} else {
group1LayerGroup.addLayer(layer);
}
}
console.log(
'GeoJSON Data before pointToLayer:',
JSON.stringify(geojsonData, null, 2),
);
console.log('icon:', icon1);
L.geoJSON(geojsonData, {
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
console.log('Feature in pointToLayer:', feature); // Debugging line
console.log('LatLng in pointToLayer:', latlng); // Debugging line
if (feature.properties.hasOwnProperty('last')) {
console.log('Creating Marker with Icon-group1'); // Debugging line
return new L.Marker(latlng, {
icon: icon1,
});
}
console.log('Creating CircleMarker'); // Debugging line
return L.circleMarker(latlng);
},
}).addTo(map); // Ensure the geoJSON layer is added to the map
console.log('After L.geoJSON creation');
All logs appear to be give proper data or at least i think they do. The markers, the groups and the timeline work properly on the loaded page but i don’t get any console logor any errors from anything within pointToLayer.
I tried to see the examples from the timeDimension but none of them have geojson source with groups and custom icons. I tried to isolate the layers and on one point managed to see the popups that not working either being shown in some part of the path of the markers.
I think it’s a problem of either sequence of function utilization or simply something is messing with the icons along the way. Since the rest of the functionality is working i presume that my geojson structure is proper and since i get no warning or error that my structure is correct.
Any ideas?