Hi Michael, thanks so much for getting back to me - I'm ready to pull my hair out lol. Here's a working example as I'm not using addTo(map).
I wish to create a layer and dynamically add geojson places onto it dynamically. I'm trying to work towards keep different types of geoson based on a particular property to be on a particular layer i.e. primaryLayer, secondaryLayer, so eventually I can just remove or add layers in order to hide/show them with some button presses.
At the moment, as proof of concept, I can't seem to get the logic to customise the geojson markers and popups using the built in leaflet features of pointToLayer and onEachFeature....so frustrating as it works without the leaflet features.....please helppp :(
// *** working logic
// adds new geojson places onto a map one by one using method: AddMapLocationMarker(place)
// create independent layers
var primaryLayer = new L.geoJson();
var secondaryLayer = new L.geoJson();
map.addLayer(primaryLayer);
map.addLayer(secondaryLayer);
// geoJson marker
var geojsonMarkerOptions = {
radius: 8,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
function AddMapLocationMarker(place) {
primaryLayer.addData(place);
}***************
Want to replace the AddMapLocation(place) method with the below modified method in red but it doesnt activate the pointToLayer or onEachFeature.
The map tends to use the default blue markers.
(Side note: noticed if I do map.fitBounds(
primaryLayer.getBounds()) it only shows expands to two points not the whole collection of points).
function AddMapLocationMarker(place) {
primaryLayer.addData(place.addData(place, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
},