Polygon
Quick answer
L.polygon draws closed area features from an array of rings, where the first ring is the outer boundary and later rings cut holes through fillRule evenodd. It inherits every Path style option and adds fill specific behavior and ring accessors.
L.polygon( latlngs , options ) → Polygon
Key points
- Pass a nested array of rings to create holes inside the outer boundary.
- Leaflet closes the ring automatically, so the first point need not be repeated.
- toGeoJSON writes a Polygon and appends the closing coordinate.
Example
var square = [
[39.90, 116.38],
[39.90, 116.42],
[39.93, 116.42],
[39.93, 116.38]
];
var withHole = [
square,
[[39.91, 116.39], [39.91, 116.41], [39.92, 116.41], [39.92, 116.39]]
];var zone = L.polygon(withHole, {
color: '#17694a',
weight: 2,
fillColor: '#17694a',
fillOpacity: 0.25,
fillRule: 'evenodd'
}).addTo(map);
zone.bindPopup('外环减去内环');
zone.on('click', function (e) {
L.DomEvent.stopPropagation(e);
zone.setStyle({ fillOpacity: 0.45 });
});
Notes
- Switching fillRule to nonzero fills holes whose winding matches the outer ring.
- Self intersecting rings render inverted fill areas that look like data errors.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Polygon. https://www.jingweizhi.com/en/leaflet/api/polygon.html (accessed 2026-11-03).