decidim 0.26.9 → 0.26.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/decidim/version.rb +1 -1
- data/package-lock.json +7 -7
- data/packages/browserslist-config/package.json +1 -1
- data/packages/core/node_modules/leaflet/CHANGELOG.md +2191 -0
- data/packages/core/node_modules/leaflet/LICENSE +26 -0
- data/packages/core/node_modules/leaflet/README.md +55 -0
- data/packages/core/node_modules/leaflet/dist/images/layers-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/layers.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-shadow.png +0 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js +14419 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js +14512 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.css +661 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js +6 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js.map +1 -0
- data/packages/core/node_modules/leaflet/package.json +149 -0
- data/packages/core/node_modules/leaflet/src/Leaflet.js +24 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Attribution.js +148 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Layers.js +443 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Scale.js +132 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Zoom.js +146 -0
- data/packages/core/node_modules/leaflet/src/control/Control.js +174 -0
- data/packages/core/node_modules/leaflet/src/control/index.js +17 -0
- data/packages/core/node_modules/leaflet/src/core/Browser.js +220 -0
- data/packages/core/node_modules/leaflet/src/core/Class.js +135 -0
- data/packages/core/node_modules/leaflet/src/core/Class.leafdoc +197 -0
- data/packages/core/node_modules/leaflet/src/core/Events.js +344 -0
- data/packages/core/node_modules/leaflet/src/core/Events.leafdoc +143 -0
- data/packages/core/node_modules/leaflet/src/core/Handler.js +57 -0
- data/packages/core/node_modules/leaflet/src/core/Util.js +241 -0
- data/packages/core/node_modules/leaflet/src/core/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.DoubleTap.js +91 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.Pointer.js +97 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.js +315 -0
- data/packages/core/node_modules/leaflet/src/dom/DomUtil.js +349 -0
- data/packages/core/node_modules/leaflet/src/dom/Draggable.js +220 -0
- data/packages/core/node_modules/leaflet/src/dom/PosAnimation.js +113 -0
- data/packages/core/node_modules/leaflet/src/dom/index.js +9 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLng.js +137 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLngBounds.js +251 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3395.js +20 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3857.js +27 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG4326.js +23 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Earth.js +33 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Simple.js +36 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.js +139 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/geo/index.js +7 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.LonLat.js +28 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.Mercator.js +49 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.SphericalMercator.js +44 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/index.js +26 -0
- data/packages/core/node_modules/leaflet/src/geometry/Bounds.js +219 -0
- data/packages/core/node_modules/leaflet/src/geometry/LineUtil.js +306 -0
- data/packages/core/node_modules/leaflet/src/geometry/Point.js +222 -0
- data/packages/core/node_modules/leaflet/src/geometry/PolyUtil.js +129 -0
- data/packages/core/node_modules/leaflet/src/geometry/Transformation.js +79 -0
- data/packages/core/node_modules/leaflet/src/geometry/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/images/layers.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/logo.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/marker.svg +1 -0
- data/packages/core/node_modules/leaflet/src/layer/DivOverlay.js +348 -0
- data/packages/core/node_modules/leaflet/src/layer/FeatureGroup.js +94 -0
- data/packages/core/node_modules/leaflet/src/layer/GeoJSON.js +452 -0
- data/packages/core/node_modules/leaflet/src/layer/ImageOverlay.js +270 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.Interactive.leafdoc +39 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.js +275 -0
- data/packages/core/node_modules/leaflet/src/layer/LayerGroup.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/Popup.js +506 -0
- data/packages/core/node_modules/leaflet/src/layer/SVGOverlay.js +50 -0
- data/packages/core/node_modules/leaflet/src/layer/Tooltip.js +444 -0
- data/packages/core/node_modules/leaflet/src/layer/VideoOverlay.js +106 -0
- data/packages/core/node_modules/leaflet/src/layer/index.js +24 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/DivIcon.js +74 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.Default.js +66 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.js +165 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.Drag.js +161 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.js +419 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/GridLayer.js +923 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.WMS.js +137 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.js +289 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/index.js +6 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Canvas.js +492 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Circle.js +113 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/CircleMarker.js +109 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Path.js +148 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polygon.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polyline.js +307 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Rectangle.js +57 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.getRenderer.js +45 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.js +133 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.Util.js +39 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.VML.js +144 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.js +207 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/index.js +14 -0
- data/packages/core/node_modules/leaflet/src/map/Map.js +1751 -0
- data/packages/core/node_modules/leaflet/src/map/Map.methodOptions.leafdoc +112 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.BoxZoom.js +152 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.DoubleClickZoom.js +55 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Drag.js +235 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Keyboard.js +183 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.ScrollWheelZoom.js +91 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TapHold.js +102 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TouchZoom.js +130 -0
- data/packages/core/node_modules/leaflet/src/map/index.js +17 -0
- data/packages/core/package.json +1 -1
- data/packages/dev/package.json +1 -1
- data/packages/elections/package.json +1 -1
- data/packages/eslint-config/package.json +1 -1
- data/packages/stylelint-config/package.json +1 -1
- data/packages/webpacker/package.json +1 -1
- metadata +148 -42
@@ -0,0 +1,148 @@
|
|
1
|
+
import {Layer} from '../Layer';
|
2
|
+
import * as Util from '../../core/Util';
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @class Path
|
6
|
+
* @aka L.Path
|
7
|
+
* @inherits Interactive layer
|
8
|
+
*
|
9
|
+
* An abstract class that contains options and constants shared between vector
|
10
|
+
* overlays (Polygon, Polyline, Circle). Do not use it directly. Extends `Layer`.
|
11
|
+
*/
|
12
|
+
|
13
|
+
export var Path = Layer.extend({
|
14
|
+
|
15
|
+
// @section
|
16
|
+
// @aka Path options
|
17
|
+
options: {
|
18
|
+
// @option stroke: Boolean = true
|
19
|
+
// Whether to draw stroke along the path. Set it to `false` to disable borders on polygons or circles.
|
20
|
+
stroke: true,
|
21
|
+
|
22
|
+
// @option color: String = '#3388ff'
|
23
|
+
// Stroke color
|
24
|
+
color: '#3388ff',
|
25
|
+
|
26
|
+
// @option weight: Number = 3
|
27
|
+
// Stroke width in pixels
|
28
|
+
weight: 3,
|
29
|
+
|
30
|
+
// @option opacity: Number = 1.0
|
31
|
+
// Stroke opacity
|
32
|
+
opacity: 1,
|
33
|
+
|
34
|
+
// @option lineCap: String= 'round'
|
35
|
+
// A string that defines [shape to be used at the end](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linecap) of the stroke.
|
36
|
+
lineCap: 'round',
|
37
|
+
|
38
|
+
// @option lineJoin: String = 'round'
|
39
|
+
// A string that defines [shape to be used at the corners](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-linejoin) of the stroke.
|
40
|
+
lineJoin: 'round',
|
41
|
+
|
42
|
+
// @option dashArray: String = null
|
43
|
+
// A string that defines the stroke [dash pattern](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dasharray). Doesn't work on `Canvas`-powered layers in [some old browsers](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility).
|
44
|
+
dashArray: null,
|
45
|
+
|
46
|
+
// @option dashOffset: String = null
|
47
|
+
// A string that defines the [distance into the dash pattern to start the dash](https://developer.mozilla.org/docs/Web/SVG/Attribute/stroke-dashoffset). Doesn't work on `Canvas`-powered layers in [some old browsers](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility).
|
48
|
+
dashOffset: null,
|
49
|
+
|
50
|
+
// @option fill: Boolean = depends
|
51
|
+
// Whether to fill the path with color. Set it to `false` to disable filling on polygons or circles.
|
52
|
+
fill: false,
|
53
|
+
|
54
|
+
// @option fillColor: String = *
|
55
|
+
// Fill color. Defaults to the value of the [`color`](#path-color) option
|
56
|
+
fillColor: null,
|
57
|
+
|
58
|
+
// @option fillOpacity: Number = 0.2
|
59
|
+
// Fill opacity.
|
60
|
+
fillOpacity: 0.2,
|
61
|
+
|
62
|
+
// @option fillRule: String = 'evenodd'
|
63
|
+
// A string that defines [how the inside of a shape](https://developer.mozilla.org/docs/Web/SVG/Attribute/fill-rule) is determined.
|
64
|
+
fillRule: 'evenodd',
|
65
|
+
|
66
|
+
// className: '',
|
67
|
+
|
68
|
+
// Option inherited from "Interactive layer" abstract class
|
69
|
+
interactive: true,
|
70
|
+
|
71
|
+
// @option bubblingMouseEvents: Boolean = true
|
72
|
+
// When `true`, a mouse event on this path will trigger the same event on the map
|
73
|
+
// (unless [`L.DomEvent.stopPropagation`](#domevent-stoppropagation) is used).
|
74
|
+
bubblingMouseEvents: true
|
75
|
+
},
|
76
|
+
|
77
|
+
beforeAdd: function (map) {
|
78
|
+
// Renderer is set here because we need to call renderer.getEvents
|
79
|
+
// before this.getEvents.
|
80
|
+
this._renderer = map.getRenderer(this);
|
81
|
+
},
|
82
|
+
|
83
|
+
onAdd: function () {
|
84
|
+
this._renderer._initPath(this);
|
85
|
+
this._reset();
|
86
|
+
this._renderer._addPath(this);
|
87
|
+
},
|
88
|
+
|
89
|
+
onRemove: function () {
|
90
|
+
this._renderer._removePath(this);
|
91
|
+
},
|
92
|
+
|
93
|
+
// @method redraw(): this
|
94
|
+
// Redraws the layer. Sometimes useful after you changed the coordinates that the path uses.
|
95
|
+
redraw: function () {
|
96
|
+
if (this._map) {
|
97
|
+
this._renderer._updatePath(this);
|
98
|
+
}
|
99
|
+
return this;
|
100
|
+
},
|
101
|
+
|
102
|
+
// @method setStyle(style: Path options): this
|
103
|
+
// Changes the appearance of a Path based on the options in the `Path options` object.
|
104
|
+
setStyle: function (style) {
|
105
|
+
Util.setOptions(this, style);
|
106
|
+
if (this._renderer) {
|
107
|
+
this._renderer._updateStyle(this);
|
108
|
+
if (this.options.stroke && style && Object.prototype.hasOwnProperty.call(style, 'weight')) {
|
109
|
+
this._updateBounds();
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return this;
|
113
|
+
},
|
114
|
+
|
115
|
+
// @method bringToFront(): this
|
116
|
+
// Brings the layer to the top of all path layers.
|
117
|
+
bringToFront: function () {
|
118
|
+
if (this._renderer) {
|
119
|
+
this._renderer._bringToFront(this);
|
120
|
+
}
|
121
|
+
return this;
|
122
|
+
},
|
123
|
+
|
124
|
+
// @method bringToBack(): this
|
125
|
+
// Brings the layer to the bottom of all path layers.
|
126
|
+
bringToBack: function () {
|
127
|
+
if (this._renderer) {
|
128
|
+
this._renderer._bringToBack(this);
|
129
|
+
}
|
130
|
+
return this;
|
131
|
+
},
|
132
|
+
|
133
|
+
getElement: function () {
|
134
|
+
return this._path;
|
135
|
+
},
|
136
|
+
|
137
|
+
_reset: function () {
|
138
|
+
// defined in child classes
|
139
|
+
this._project();
|
140
|
+
this._update();
|
141
|
+
},
|
142
|
+
|
143
|
+
_clickTolerance: function () {
|
144
|
+
// used when doing hit detection for Canvas layers
|
145
|
+
return (this.options.stroke ? this.options.weight / 2 : 0) +
|
146
|
+
(this._renderer.options.tolerance || 0);
|
147
|
+
}
|
148
|
+
});
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import {Polyline} from './Polyline';
|
2
|
+
import {LatLng} from '../../geo/LatLng';
|
3
|
+
import * as LineUtil from '../../geometry/LineUtil';
|
4
|
+
import {Point} from '../../geometry/Point';
|
5
|
+
import {Bounds} from '../../geometry/Bounds';
|
6
|
+
import * as PolyUtil from '../../geometry/PolyUtil';
|
7
|
+
|
8
|
+
/*
|
9
|
+
* @class Polygon
|
10
|
+
* @aka L.Polygon
|
11
|
+
* @inherits Polyline
|
12
|
+
*
|
13
|
+
* A class for drawing polygon overlays on a map. Extends `Polyline`.
|
14
|
+
*
|
15
|
+
* 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.
|
16
|
+
*
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
*
|
20
|
+
* ```js
|
21
|
+
* // create a red polygon from an array of LatLng points
|
22
|
+
* var latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]];
|
23
|
+
*
|
24
|
+
* var polygon = L.polygon(latlngs, {color: 'red'}).addTo(map);
|
25
|
+
*
|
26
|
+
* // zoom the map to the polygon
|
27
|
+
* map.fitBounds(polygon.getBounds());
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* 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:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* var latlngs = [
|
34
|
+
* [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
|
35
|
+
* [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
|
36
|
+
* ];
|
37
|
+
* ```
|
38
|
+
*
|
39
|
+
* Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape.
|
40
|
+
*
|
41
|
+
* ```js
|
42
|
+
* var latlngs = [
|
43
|
+
* [ // first polygon
|
44
|
+
* [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring
|
45
|
+
* [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole
|
46
|
+
* ],
|
47
|
+
* [ // second polygon
|
48
|
+
* [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]]
|
49
|
+
* ]
|
50
|
+
* ];
|
51
|
+
* ```
|
52
|
+
*/
|
53
|
+
|
54
|
+
export var Polygon = Polyline.extend({
|
55
|
+
|
56
|
+
options: {
|
57
|
+
fill: true
|
58
|
+
},
|
59
|
+
|
60
|
+
isEmpty: function () {
|
61
|
+
return !this._latlngs.length || !this._latlngs[0].length;
|
62
|
+
},
|
63
|
+
|
64
|
+
// @method getCenter(): LatLng
|
65
|
+
// Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon.
|
66
|
+
getCenter: function () {
|
67
|
+
// throws error when not yet added to map as this center calculation requires projected coordinates
|
68
|
+
if (!this._map) {
|
69
|
+
throw new Error('Must add layer to map before using getCenter()');
|
70
|
+
}
|
71
|
+
return PolyUtil.polygonCenter(this._defaultShape(), this._map.options.crs);
|
72
|
+
},
|
73
|
+
|
74
|
+
_convertLatLngs: function (latlngs) {
|
75
|
+
var result = Polyline.prototype._convertLatLngs.call(this, latlngs),
|
76
|
+
len = result.length;
|
77
|
+
|
78
|
+
// remove last point if it equals first one
|
79
|
+
if (len >= 2 && result[0] instanceof LatLng && result[0].equals(result[len - 1])) {
|
80
|
+
result.pop();
|
81
|
+
}
|
82
|
+
return result;
|
83
|
+
},
|
84
|
+
|
85
|
+
_setLatLngs: function (latlngs) {
|
86
|
+
Polyline.prototype._setLatLngs.call(this, latlngs);
|
87
|
+
if (LineUtil.isFlat(this._latlngs)) {
|
88
|
+
this._latlngs = [this._latlngs];
|
89
|
+
}
|
90
|
+
},
|
91
|
+
|
92
|
+
_defaultShape: function () {
|
93
|
+
return LineUtil.isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0];
|
94
|
+
},
|
95
|
+
|
96
|
+
_clipPoints: function () {
|
97
|
+
// polygons need a different clipping algorithm so we redefine that
|
98
|
+
|
99
|
+
var bounds = this._renderer._bounds,
|
100
|
+
w = this.options.weight,
|
101
|
+
p = new Point(w, w);
|
102
|
+
|
103
|
+
// increase clip padding by stroke width to avoid stroke on clip edges
|
104
|
+
bounds = new Bounds(bounds.min.subtract(p), bounds.max.add(p));
|
105
|
+
|
106
|
+
this._parts = [];
|
107
|
+
if (!this._pxBounds || !this._pxBounds.intersects(bounds)) {
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
|
111
|
+
if (this.options.noClip) {
|
112
|
+
this._parts = this._rings;
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
|
116
|
+
for (var i = 0, len = this._rings.length, clipped; i < len; i++) {
|
117
|
+
clipped = PolyUtil.clipPolygon(this._rings[i], bounds, true);
|
118
|
+
if (clipped.length) {
|
119
|
+
this._parts.push(clipped);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
},
|
123
|
+
|
124
|
+
_updatePath: function () {
|
125
|
+
this._renderer._updatePoly(this, true);
|
126
|
+
},
|
127
|
+
|
128
|
+
// Needed by the `Canvas` renderer for interactivity
|
129
|
+
_containsPoint: function (p) {
|
130
|
+
var inside = false,
|
131
|
+
part, p1, p2, i, j, k, len, len2;
|
132
|
+
|
133
|
+
if (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }
|
134
|
+
|
135
|
+
// ray casting algorithm for detecting if point is in polygon
|
136
|
+
for (i = 0, len = this._parts.length; i < len; i++) {
|
137
|
+
part = this._parts[i];
|
138
|
+
|
139
|
+
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
140
|
+
p1 = part[j];
|
141
|
+
p2 = part[k];
|
142
|
+
|
143
|
+
if (((p1.y > p.y) !== (p2.y > p.y)) && (p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x)) {
|
144
|
+
inside = !inside;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
// also check if it's on polygon stroke
|
150
|
+
return inside || Polyline.prototype._containsPoint.call(this, p, true);
|
151
|
+
}
|
152
|
+
|
153
|
+
});
|
154
|
+
|
155
|
+
|
156
|
+
// @factory L.polygon(latlngs: LatLng[], options?: Polyline options)
|
157
|
+
export function polygon(latlngs, options) {
|
158
|
+
return new Polygon(latlngs, options);
|
159
|
+
}
|
@@ -0,0 +1,307 @@
|
|
1
|
+
import {Path} from './Path';
|
2
|
+
import * as Util from '../../core/Util';
|
3
|
+
import * as LineUtil from '../../geometry/LineUtil';
|
4
|
+
import {LatLng, toLatLng} from '../../geo/LatLng';
|
5
|
+
import {LatLngBounds} from '../../geo/LatLngBounds';
|
6
|
+
import {Bounds} from '../../geometry/Bounds';
|
7
|
+
import {Point} from '../../geometry/Point';
|
8
|
+
|
9
|
+
/*
|
10
|
+
* @class Polyline
|
11
|
+
* @aka L.Polyline
|
12
|
+
* @inherits Path
|
13
|
+
*
|
14
|
+
* A class for drawing polyline overlays on a map. Extends `Path`.
|
15
|
+
*
|
16
|
+
* @example
|
17
|
+
*
|
18
|
+
* ```js
|
19
|
+
* // create a red polyline from an array of LatLng points
|
20
|
+
* var latlngs = [
|
21
|
+
* [45.51, -122.68],
|
22
|
+
* [37.77, -122.43],
|
23
|
+
* [34.04, -118.2]
|
24
|
+
* ];
|
25
|
+
*
|
26
|
+
* var polyline = L.polyline(latlngs, {color: 'red'}).addTo(map);
|
27
|
+
*
|
28
|
+
* // zoom the map to the polyline
|
29
|
+
* map.fitBounds(polyline.getBounds());
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* You can also pass a multi-dimensional array to represent a `MultiPolyline` shape:
|
33
|
+
*
|
34
|
+
* ```js
|
35
|
+
* // create a red polyline from an array of arrays of LatLng points
|
36
|
+
* var latlngs = [
|
37
|
+
* [[45.51, -122.68],
|
38
|
+
* [37.77, -122.43],
|
39
|
+
* [34.04, -118.2]],
|
40
|
+
* [[40.78, -73.91],
|
41
|
+
* [41.83, -87.62],
|
42
|
+
* [32.76, -96.72]]
|
43
|
+
* ];
|
44
|
+
* ```
|
45
|
+
*/
|
46
|
+
|
47
|
+
|
48
|
+
export var Polyline = Path.extend({
|
49
|
+
|
50
|
+
// @section
|
51
|
+
// @aka Polyline options
|
52
|
+
options: {
|
53
|
+
// @option smoothFactor: Number = 1.0
|
54
|
+
// How much to simplify the polyline on each zoom level. More means
|
55
|
+
// better performance and smoother look, and less means more accurate representation.
|
56
|
+
smoothFactor: 1.0,
|
57
|
+
|
58
|
+
// @option noClip: Boolean = false
|
59
|
+
// Disable polyline clipping.
|
60
|
+
noClip: false
|
61
|
+
},
|
62
|
+
|
63
|
+
initialize: function (latlngs, options) {
|
64
|
+
Util.setOptions(this, options);
|
65
|
+
this._setLatLngs(latlngs);
|
66
|
+
},
|
67
|
+
|
68
|
+
// @method getLatLngs(): LatLng[]
|
69
|
+
// Returns an array of the points in the path, or nested arrays of points in case of multi-polyline.
|
70
|
+
getLatLngs: function () {
|
71
|
+
return this._latlngs;
|
72
|
+
},
|
73
|
+
|
74
|
+
// @method setLatLngs(latlngs: LatLng[]): this
|
75
|
+
// Replaces all the points in the polyline with the given array of geographical points.
|
76
|
+
setLatLngs: function (latlngs) {
|
77
|
+
this._setLatLngs(latlngs);
|
78
|
+
return this.redraw();
|
79
|
+
},
|
80
|
+
|
81
|
+
// @method isEmpty(): Boolean
|
82
|
+
// Returns `true` if the Polyline has no LatLngs.
|
83
|
+
isEmpty: function () {
|
84
|
+
return !this._latlngs.length;
|
85
|
+
},
|
86
|
+
|
87
|
+
// @method closestLayerPoint(p: Point): Point
|
88
|
+
// Returns the point closest to `p` on the Polyline.
|
89
|
+
closestLayerPoint: function (p) {
|
90
|
+
var minDistance = Infinity,
|
91
|
+
minPoint = null,
|
92
|
+
closest = LineUtil._sqClosestPointOnSegment,
|
93
|
+
p1, p2;
|
94
|
+
|
95
|
+
for (var j = 0, jLen = this._parts.length; j < jLen; j++) {
|
96
|
+
var points = this._parts[j];
|
97
|
+
|
98
|
+
for (var i = 1, len = points.length; i < len; i++) {
|
99
|
+
p1 = points[i - 1];
|
100
|
+
p2 = points[i];
|
101
|
+
|
102
|
+
var sqDist = closest(p, p1, p2, true);
|
103
|
+
|
104
|
+
if (sqDist < minDistance) {
|
105
|
+
minDistance = sqDist;
|
106
|
+
minPoint = closest(p, p1, p2);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
if (minPoint) {
|
111
|
+
minPoint.distance = Math.sqrt(minDistance);
|
112
|
+
}
|
113
|
+
return minPoint;
|
114
|
+
},
|
115
|
+
|
116
|
+
// @method getCenter(): LatLng
|
117
|
+
// Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline.
|
118
|
+
getCenter: function () {
|
119
|
+
// throws error when not yet added to map as this center calculation requires projected coordinates
|
120
|
+
if (!this._map) {
|
121
|
+
throw new Error('Must add layer to map before using getCenter()');
|
122
|
+
}
|
123
|
+
return LineUtil.polylineCenter(this._defaultShape(), this._map.options.crs);
|
124
|
+
},
|
125
|
+
|
126
|
+
// @method getBounds(): LatLngBounds
|
127
|
+
// Returns the `LatLngBounds` of the path.
|
128
|
+
getBounds: function () {
|
129
|
+
return this._bounds;
|
130
|
+
},
|
131
|
+
|
132
|
+
// @method addLatLng(latlng: LatLng, latlngs?: LatLng[]): this
|
133
|
+
// Adds a given point to the polyline. By default, adds to the first ring of
|
134
|
+
// the polyline in case of a multi-polyline, but can be overridden by passing
|
135
|
+
// a specific ring as a LatLng array (that you can earlier access with [`getLatLngs`](#polyline-getlatlngs)).
|
136
|
+
addLatLng: function (latlng, latlngs) {
|
137
|
+
latlngs = latlngs || this._defaultShape();
|
138
|
+
latlng = toLatLng(latlng);
|
139
|
+
latlngs.push(latlng);
|
140
|
+
this._bounds.extend(latlng);
|
141
|
+
return this.redraw();
|
142
|
+
},
|
143
|
+
|
144
|
+
_setLatLngs: function (latlngs) {
|
145
|
+
this._bounds = new LatLngBounds();
|
146
|
+
this._latlngs = this._convertLatLngs(latlngs);
|
147
|
+
},
|
148
|
+
|
149
|
+
_defaultShape: function () {
|
150
|
+
return LineUtil.isFlat(this._latlngs) ? this._latlngs : this._latlngs[0];
|
151
|
+
},
|
152
|
+
|
153
|
+
// recursively convert latlngs input into actual LatLng instances; calculate bounds along the way
|
154
|
+
_convertLatLngs: function (latlngs) {
|
155
|
+
var result = [],
|
156
|
+
flat = LineUtil.isFlat(latlngs);
|
157
|
+
|
158
|
+
for (var i = 0, len = latlngs.length; i < len; i++) {
|
159
|
+
if (flat) {
|
160
|
+
result[i] = toLatLng(latlngs[i]);
|
161
|
+
this._bounds.extend(result[i]);
|
162
|
+
} else {
|
163
|
+
result[i] = this._convertLatLngs(latlngs[i]);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
return result;
|
168
|
+
},
|
169
|
+
|
170
|
+
_project: function () {
|
171
|
+
var pxBounds = new Bounds();
|
172
|
+
this._rings = [];
|
173
|
+
this._projectLatlngs(this._latlngs, this._rings, pxBounds);
|
174
|
+
|
175
|
+
if (this._bounds.isValid() && pxBounds.isValid()) {
|
176
|
+
this._rawPxBounds = pxBounds;
|
177
|
+
this._updateBounds();
|
178
|
+
}
|
179
|
+
},
|
180
|
+
|
181
|
+
_updateBounds: function () {
|
182
|
+
var w = this._clickTolerance(),
|
183
|
+
p = new Point(w, w);
|
184
|
+
|
185
|
+
if (!this._rawPxBounds) {
|
186
|
+
return;
|
187
|
+
}
|
188
|
+
|
189
|
+
this._pxBounds = new Bounds([
|
190
|
+
this._rawPxBounds.min.subtract(p),
|
191
|
+
this._rawPxBounds.max.add(p)
|
192
|
+
]);
|
193
|
+
},
|
194
|
+
|
195
|
+
// recursively turns latlngs into a set of rings with projected coordinates
|
196
|
+
_projectLatlngs: function (latlngs, result, projectedBounds) {
|
197
|
+
var flat = latlngs[0] instanceof LatLng,
|
198
|
+
len = latlngs.length,
|
199
|
+
i, ring;
|
200
|
+
|
201
|
+
if (flat) {
|
202
|
+
ring = [];
|
203
|
+
for (i = 0; i < len; i++) {
|
204
|
+
ring[i] = this._map.latLngToLayerPoint(latlngs[i]);
|
205
|
+
projectedBounds.extend(ring[i]);
|
206
|
+
}
|
207
|
+
result.push(ring);
|
208
|
+
} else {
|
209
|
+
for (i = 0; i < len; i++) {
|
210
|
+
this._projectLatlngs(latlngs[i], result, projectedBounds);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
},
|
214
|
+
|
215
|
+
// clip polyline by renderer bounds so that we have less to render for performance
|
216
|
+
_clipPoints: function () {
|
217
|
+
var bounds = this._renderer._bounds;
|
218
|
+
|
219
|
+
this._parts = [];
|
220
|
+
if (!this._pxBounds || !this._pxBounds.intersects(bounds)) {
|
221
|
+
return;
|
222
|
+
}
|
223
|
+
|
224
|
+
if (this.options.noClip) {
|
225
|
+
this._parts = this._rings;
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
|
229
|
+
var parts = this._parts,
|
230
|
+
i, j, k, len, len2, segment, points;
|
231
|
+
|
232
|
+
for (i = 0, k = 0, len = this._rings.length; i < len; i++) {
|
233
|
+
points = this._rings[i];
|
234
|
+
|
235
|
+
for (j = 0, len2 = points.length; j < len2 - 1; j++) {
|
236
|
+
segment = LineUtil.clipSegment(points[j], points[j + 1], bounds, j, true);
|
237
|
+
|
238
|
+
if (!segment) { continue; }
|
239
|
+
|
240
|
+
parts[k] = parts[k] || [];
|
241
|
+
parts[k].push(segment[0]);
|
242
|
+
|
243
|
+
// if segment goes out of screen, or it's the last one, it's the end of the line part
|
244
|
+
if ((segment[1] !== points[j + 1]) || (j === len2 - 2)) {
|
245
|
+
parts[k].push(segment[1]);
|
246
|
+
k++;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
},
|
251
|
+
|
252
|
+
// simplify each clipped part of the polyline for performance
|
253
|
+
_simplifyPoints: function () {
|
254
|
+
var parts = this._parts,
|
255
|
+
tolerance = this.options.smoothFactor;
|
256
|
+
|
257
|
+
for (var i = 0, len = parts.length; i < len; i++) {
|
258
|
+
parts[i] = LineUtil.simplify(parts[i], tolerance);
|
259
|
+
}
|
260
|
+
},
|
261
|
+
|
262
|
+
_update: function () {
|
263
|
+
if (!this._map) { return; }
|
264
|
+
|
265
|
+
this._clipPoints();
|
266
|
+
this._simplifyPoints();
|
267
|
+
this._updatePath();
|
268
|
+
},
|
269
|
+
|
270
|
+
_updatePath: function () {
|
271
|
+
this._renderer._updatePoly(this);
|
272
|
+
},
|
273
|
+
|
274
|
+
// Needed by the `Canvas` renderer for interactivity
|
275
|
+
_containsPoint: function (p, closed) {
|
276
|
+
var i, j, k, len, len2, part,
|
277
|
+
w = this._clickTolerance();
|
278
|
+
|
279
|
+
if (!this._pxBounds || !this._pxBounds.contains(p)) { return false; }
|
280
|
+
|
281
|
+
// hit detection for polylines
|
282
|
+
for (i = 0, len = this._parts.length; i < len; i++) {
|
283
|
+
part = this._parts[i];
|
284
|
+
|
285
|
+
for (j = 0, len2 = part.length, k = len2 - 1; j < len2; k = j++) {
|
286
|
+
if (!closed && (j === 0)) { continue; }
|
287
|
+
|
288
|
+
if (LineUtil.pointToSegmentDistance(p, part[k], part[j]) <= w) {
|
289
|
+
return true;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
return false;
|
294
|
+
}
|
295
|
+
});
|
296
|
+
|
297
|
+
// @factory L.polyline(latlngs: LatLng[], options?: Polyline options)
|
298
|
+
// Instantiates a polyline object given an array of geographical points and
|
299
|
+
// optionally an options object. You can create a `Polyline` object with
|
300
|
+
// multiple separate lines (`MultiPolyline`) by passing an array of arrays
|
301
|
+
// of geographic points.
|
302
|
+
export function polyline(latlngs, options) {
|
303
|
+
return new Polyline(latlngs, options);
|
304
|
+
}
|
305
|
+
|
306
|
+
// Retrocompat. Allow plugins to support Leaflet versions before and after 1.1.
|
307
|
+
Polyline._flat = LineUtil._flat;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import {Polygon} from './Polygon';
|
2
|
+
import {toLatLngBounds} from '../../geo/LatLngBounds';
|
3
|
+
|
4
|
+
/*
|
5
|
+
* L.Rectangle extends Polygon and creates a rectangle when passed a LatLngBounds object.
|
6
|
+
*/
|
7
|
+
|
8
|
+
/*
|
9
|
+
* @class Rectangle
|
10
|
+
* @aka L.Rectangle
|
11
|
+
* @inherits Polygon
|
12
|
+
*
|
13
|
+
* A class for drawing rectangle overlays on a map. Extends `Polygon`.
|
14
|
+
*
|
15
|
+
* @example
|
16
|
+
*
|
17
|
+
* ```js
|
18
|
+
* // define rectangle geographical bounds
|
19
|
+
* var bounds = [[54.559322, -5.767822], [56.1210604, -3.021240]];
|
20
|
+
*
|
21
|
+
* // create an orange rectangle
|
22
|
+
* L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);
|
23
|
+
*
|
24
|
+
* // zoom the map to the rectangle bounds
|
25
|
+
* map.fitBounds(bounds);
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
*/
|
29
|
+
|
30
|
+
|
31
|
+
export var Rectangle = Polygon.extend({
|
32
|
+
initialize: function (latLngBounds, options) {
|
33
|
+
Polygon.prototype.initialize.call(this, this._boundsToLatLngs(latLngBounds), options);
|
34
|
+
},
|
35
|
+
|
36
|
+
// @method setBounds(latLngBounds: LatLngBounds): this
|
37
|
+
// Redraws the rectangle with the passed bounds.
|
38
|
+
setBounds: function (latLngBounds) {
|
39
|
+
return this.setLatLngs(this._boundsToLatLngs(latLngBounds));
|
40
|
+
},
|
41
|
+
|
42
|
+
_boundsToLatLngs: function (latLngBounds) {
|
43
|
+
latLngBounds = toLatLngBounds(latLngBounds);
|
44
|
+
return [
|
45
|
+
latLngBounds.getSouthWest(),
|
46
|
+
latLngBounds.getNorthWest(),
|
47
|
+
latLngBounds.getNorthEast(),
|
48
|
+
latLngBounds.getSouthEast()
|
49
|
+
];
|
50
|
+
}
|
51
|
+
});
|
52
|
+
|
53
|
+
|
54
|
+
// @factory L.rectangle(latLngBounds: LatLngBounds, options?: Polyline options)
|
55
|
+
export function rectangle(latLngBounds, options) {
|
56
|
+
return new Rectangle(latLngBounds, options);
|
57
|
+
}
|