change width of outline for leaflet map depending on zoomlevel
I slightly changed your code, and this is working for me:
var myStyle =
{
fillColor: '#1c9099',
color: 'white',
weight: 3
};
var polygon = L.polygon(
[[51.509, -0.08],
[51.503, -0.06],
[51.51, -0.047]]);
polygon.setStyle(myStyle).addTo(map);
map.on('zoomend', function () {
currentZoom = map.getZoom();
if (currentZoom == 15) {
polygon.setStyle({weight: 2});
}
else {
polygon.setStyle({weight: 3});
}
});
First a basic style for the object (here a polygon) is set. By using the setStyle() function it is possible to change specific style attributes, while the rest of the basic style remains the same.