Search code examples
javascriptcssleafletgeojson

Reducing border width of Leaflet polygon


When adding a polygon to a Leaflet map, the border is quite wide (dark blue in image below). For maps of a wide area, this often obscures finer details of the map underneath.

Is it possible to reduce the width of the border, while retaining the other default styling of the polygon?

Currently I am creating the polygon from GeoJSON using

var boundary = { "type": "Feature", "geometry": {"type":"Polygon","coordinates":[....]}};
var poly = L.geoJson(boundary);
map.addLayer(poly);

Map of Hoxton, London

I am using Leaflet 0.7.3 (latest stable release). I'd be interested in solutions that change the style across all instances of leaflet maps, as well as ways to change it for a specific map.


Solution

  • Please read the Leaflet documentation, which specifies a weight option for paths, which you can specify as an option to L.geoJson.

    var poly = L.geoJson(boundary, { weight: 1 });