diff --git a/reference.html b/reference.html index a38465d2..2e853a09 100644 --- a/reference.html +++ b/reference.html @@ -46,9 +46,7 @@ bodyclass: api-page
// create a red polyline from an array of LatLng points
+var latlngs = [
+ [-122.68, 45.51],
+ [-122.43, 37.77],
+ [-118.2, 34.04]
+];
+
+var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
+
+// zoom the map to the polyline
+map.fitBounds(polyline.getBounds());
+
+You can also pass a multi-dimensional array to represent a MultiPolyline shape.
+ +// create a red polyline from an arrays of arrays of LatLng points
+var latlngs = [
+ [
+ [-122.68, 45.51],
+ [-122.43, 37.77],
+ [-118.2, 34.04]
+ ],
+ [
+ [-73.91, 40.78],
+ [-87.62, 41.83],
+ [-96.72, 32.76]
+ ]
+]
+
var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
// zoom the map to the polyline
@@ -2634,7 +2659,7 @@ map.fitBounds(polyline.getBounds());
- Extends FeatureGroup to allow creating multi-polylines (single layer that consists of several polylines that share styling/popup).
- -Factory | - -Description | -
---|---|
L.multiPolyline(
- |
-
-
-
- Instantiates a multi-polyline object given an array of arrays of geographical points (one for each individual polyline) and optionally an options object. | -
MultiPolylines accept all Polyline methods but -have different behavior around their coordinate contents since they can contain -multiple line features:
- -Method | -Returns | -Description | -
---|---|---|
setLatLngs(
- |
-
- this |
- Replace all lines and their paths with the given array of arrays of - geographical points. | -
getLatLngs() |
-
-
|
- Returns an array of arrays of geographical points in each line. | -
openPopup() |
-
- this |
- Opens the popup previously bound by bindPopup. | -
toGeoJSON() |
- Object |
- Returns a GeoJSON representation of the multipolyline (GeoJSON MultiLineString Feature). | -
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.
+// create a red polygon from an arrays of LatLng points
+var latlngs = [
+ [ [-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41] ]
+];
+
+var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
+
+// zoom the map to the polygon
+map.fitBounds(polygon.getBounds());
+
+You can also pass a array of arrays of latlngs, the first array represents the outer shape and the other arrays represent holes in the outer shape.
+ +// create a red polygon from an arrays of LatLng points
+var latlngs = [
+ [ [-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41] ]
+ [ [-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29] ]
+];
+
+var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
+
+// zoom the map to the polygon
+map.fitBounds(polygon.getBounds());
+
+You can also pass a multi-dimensional array to represent a MultiPolyline shape.
+ +// create a red polygon from an arrays of arrays of LatLng points
+var latlngs = [
+ [
+ [ [-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41] ],
+ [ [-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29] ]
+ ],
+ [
+ [ [-109.05, 37],[-109.03, 41],[-102.05, 41],[-102.04, 37],[-109.05, 38] ]
+ ]
+]
+
+var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
+
+// zoom the map to the polygon
+map.fitBounds(polygon.getBounds());
+
+
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. | +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. You can create a a Polygon with multiple separate lines (MultiPolygon) by passing an array of Polygon coordinates. |
Extends FeatureGroup to allow creating multi-polygons (single layer that consists of several polygons that share styling/popup).
- -Factory | - -Description | -
---|---|
L.multiPolygon(
- |
-
-
- Instantiates a multi-polygon object given an array of latlngs arrays (one for each individual polygon) and optionally an options object (the same as for MultiPolyline). | -
MultiPolygons accept all Polyline methods but -have different behavior around their coordinate contents since they can contain -multiple polygon features:
- -Method | -Returns | -Description | -
---|---|---|
setLatLngs(
- |
-
- this |
- Replace all polygons and their paths with the given array of arrays of - geographical points. | -
getLatLngs() |
-
-
|
- Returns an array of arrays of geographical points in each polygon. | -
openPopup() |
-
- this |
- Opens the popup previously bound by bindPopup. | -
toGeoJSON() |
- Object |
- Returns a GeoJSON representation of the multipolygon (GeoJSON MultiPolygon Feature). | -