I am pretty new in working with Leaflet js and I have a polygon
var coords = layer.getLatLngs();
L.polygon(coords, { fillColor: 'red', fillOpacity: 0.5, weight: 20, color: 'red', opacity: 0.5, fill: true}).addTo(map);
and I need to add another polygon around it with an offset.
I've tried using leaflet.polylineoffset
, first with polyline
coords.push(coords[0]);
L.polyline(coords, { color: 'purple', weight: 2, opacity: 0.7, fill: false, offset: 10}).addTo(map);
but it didn't close properly
Then, by using polygon
,
L.polygon(coords, { color: 'purple', weight: 2, opacity: 0.7, fill: false, offset: 10, polygon: true }).addTo(map);
it draws one of the line on top of the other polygon
Is there a way to add a polygon around an existing one with an offset?
Best Answer
One possible way to solve this is to actually use
Leaflet.PolylineOffset
plugin, with slight modification of plugin code (only one line):Example after this modification: