diff --git a/reference.html b/reference.html index f806a103..9987207f 100644 --- a/reference.html +++ b/reference.html @@ -2642,26 +2642,17 @@ 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.
+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
+// create a red polyline from an array 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
-map.fitBounds(polyline.getBounds());
+ [[-122.68, 45.51],
+ [-122.43, 37.77],
+ [-118.2, 34.04]],
+ [[-73.91, 40.78],
+ [-87.62, 41.83],
+ [-96.72, 32.76]]
+];
Polyline
object with multiple separate lines (MultiPolyline
) by passing an array of arrays of geographic points.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] ]
-];
+// create a red polygon from an array 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.
+You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing 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] ]
-];
+ [[-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41]], // outer ring
+ [[-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29]] // hole
+];
-var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
+Additionally, you can pass a multi-dimensional array to represent a MultiPolygon
shape.
-// 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] ]
+ [ // first polygon
+ [[-111.03, 41],[-111.04, 45],[-104.05, 45],[-104.05, 41]], // outer ring
+ [[-108.58,37.29],[-108.58,40.71],[-102.50,40.71],[-102.50,37.29]] // hole
],
- [
- [ [-109.05, 37],[-109.03, 41],[-102.05, 41],[-102.04, 37],[-109.05, 38] ]
+ [ // second polygon
+ [[-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());
+];
Creation
@@ -2830,7 +2809,7 @@ map.fitBounds(polygon.getBounds());
- Polygon
with multiple separate shapes (MultiPolygon
) by passing an array of Polygon
coordinates.