I'd like to change the style of certain points based on events, but I can't figure out how to do it.
Here's a working jsfiddle for an example.
var points = new L.geoJson(pointsData, { pointToLayer: function(feature, latlng) { if (feature.properties.name === "Point1") { return L.circleMarker(latlng, { radius: 10, fillColor: "blue", color: "black" }); } else if (feature.properties.name === "Point2") { return L.circleMarker(latlng, { radius: 10, fillColor: "green", color: "white" }); } else if (feature.properties.name === "Point3") { return L.circleMarker(latlng, { radius: 10, fillColor: "orange", color: "purple" }); } } }).addTo(map); In the above example, how would I change the style of, say, Point1 after it's been created?
I haven't found anything in the documentation, or online.
Is it possible?
I ended up splitting the geojson up for each point, and created a function that returns a new geojson object.
point1Data = { ... }; point2Data = { ... }; function createPoint(pointData, radius, fill, stroke) { return new L.geoJson(pointData, { pointToLayer: function (feature, latlng) { return L.circleMarker(latlng, { radius: radius, fillColor: fill, color: stroke, }); } }); } point1.createPoint(point1Data, 10, "red", "black").addTo(map); point1.remove(); point1 = createPoint(point1Data, 10, "black", "red").addTo(map); Here's a working jsfiddle for an example.