From 62de364d2edba35e36726a3ee680a0cc592f5e17 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 6 Mar 2015 13:05:28 +0200 Subject: [PATCH] polygon/polyline docs fixes and cleanup --- reference.html | 73 ++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 47 deletions(-) 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]] +];

Creation

@@ -2678,7 +2669,7 @@ map.fitBounds(polyline.getBounds()); - Instantiates a polyline object given an array of geographical points and optionally an options object. You can create a a Polyline with multiple separate lines (MultiPolyline) by passing an array that contains arrays of geographic points. + Instantiates a polyline object given an array of geographical points and optionally an options object. You can create a Polyline object with multiple separate lines (MultiPolyline) by passing an array of arrays of geographic points. @@ -2773,46 +2764,34 @@ map.fitBounds(polyline.getBounds());

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.

Usage example

-
// 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());
- 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. + 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 shapes (MultiPolygon) by passing an array of Polygon coordinates.