I have searched posts and tutorials and could not find the answer to my specific application of this feature
Almost all the examples use L.marker
to simply place a marker on the map using various custom icons. This would be fine except I am not just placing markers but rather adding all the geoJson data to layers, then adding those layergroups to the control and then to the map. - I.E. I want all the layer routeca1 to use a red icon. I think I have narrowed this to needing to use the point to layer function:
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {icon: redIcon});
}
I am not using the onEachFeature
function, as I have seen an example on how to do this using that function but cant make that work for what I am doing here.
The map works great without trying to do a different color icon. I have all my points and polygons appearing and controlable by the layercontrol, but when I try to add the point to layer I just get a white map or the same map with no changes depending on where I try to add it in.
I added the icon sections below based off of the Leaflet Tutorial -
var routeca1 = L.layerGroup();
var geojsonFeature1 = [{***random geojson data points here****} ];
L.geoJSON(geojsonFeature1)
.bindPopup(function (layer) {
return '<b>'+'Location ID: '+ layer.feature.properties.locationid +'</b>' + '<br/>' + '<hr />'+ layer.feature.properties.Description + '<br/>' + layer.feature.properties.model + '<br/>' + '<hr />'+ layer.feature.properties.addresscomponents;
}).addTo(routeca1);
var streets = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>', maxZoom: 17, minZoom: 6});
var map = L.map('map', {
center: [34.068, -118.248],
zoom: 10,
layers: [streets, routeca1]
});
var baseLayers = {
"Streets": streets
};
var overlays = {
"CA1": routeca1
};
var MarkerIcon = L.Icon.extend({
options: {
shadowUrl: './leaflet/images/marker-shadow.png',
iconSize: [38, 95],
shadowSize: [50, 64],
iconAnchor: [22, 94],
shadowAnchor: [4, 62],
popupAnchor: [-3, -76]
}
});
var greenIcon = new MarkerIcon({iconUrl: './leaflet/images/marker-icon-green.png'}),
redIcon = new MarkerIcon({iconUrl: './leaflet/images/marker-icon-red.png'}),
blueIcon = new MarkerIcon({iconUrl: './leaflet/images/marker-blue.png'});
L.icon = function (options) {
return new L.Icon(options);
};
L.control.layers(baseLayers, overlays).addTo(map);