Legacy
Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Mapbox GL JS.
You are viewing an older version of Mapbox.js. Check out v3.3.1 for the latest.
Polygon
A class for drawing polygon overlays on a map. Extends Polyline. Use Map#addLayer to add it to the map.
Note that points you pass when creating a polygon shouldn't have an additional last point equal to the first one — it's better to filter out such points.
Creation
Factory | Description |
---|---|
L.polygon(
|
Instantiates a polygon object given an array of geographical points and optionally an options object (the same as for Polyline). You can also create a polygon with holes by passing an array of arrays of latlngs, with the first latlngs array representing the exterior ring while the remaining represent the holes inside. |
Methods
Polygon has the same options and methods as Polyline, with the following differences:
Method | Returns | Description |
---|---|---|
toGeoJSON() |
Object |
Returns a GeoJSON representation of the polygon (GeoJSON Polygon Feature). |