decidim 0.26.9 → 0.26.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim might be problematic. Click here for more details.
- 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,26 @@
|
|
1
|
+
/*
|
2
|
+
* @class Projection
|
3
|
+
|
4
|
+
* An object with methods for projecting geographical coordinates of the world onto
|
5
|
+
* a flat surface (and back). See [Map projection](https://en.wikipedia.org/wiki/Map_projection).
|
6
|
+
|
7
|
+
* @property bounds: Bounds
|
8
|
+
* The bounds (specified in CRS units) where the projection is valid
|
9
|
+
|
10
|
+
* @method project(latlng: LatLng): Point
|
11
|
+
* Projects geographical coordinates into a 2D point.
|
12
|
+
* Only accepts actual `L.LatLng` instances, not arrays.
|
13
|
+
|
14
|
+
* @method unproject(point: Point): LatLng
|
15
|
+
* The inverse of `project`. Projects a 2D point into a geographical location.
|
16
|
+
* Only accepts actual `L.Point` instances, not arrays.
|
17
|
+
|
18
|
+
* Note that the projection instances do not inherit from Leaflet's `Class` object,
|
19
|
+
* and can't be instantiated. Also, new classes can't inherit from them,
|
20
|
+
* and methods can't be added to them with the `include` function.
|
21
|
+
|
22
|
+
*/
|
23
|
+
|
24
|
+
export {LonLat} from './Projection.LonLat';
|
25
|
+
export {Mercator} from './Projection.Mercator';
|
26
|
+
export {SphericalMercator} from './Projection.SphericalMercator';
|
@@ -0,0 +1,219 @@
|
|
1
|
+
import {Point, toPoint} from './Point';
|
2
|
+
|
3
|
+
/*
|
4
|
+
* @class Bounds
|
5
|
+
* @aka L.Bounds
|
6
|
+
*
|
7
|
+
* Represents a rectangular area in pixel coordinates.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
*
|
11
|
+
* ```js
|
12
|
+
* var p1 = L.point(10, 10),
|
13
|
+
* p2 = L.point(40, 60),
|
14
|
+
* bounds = L.bounds(p1, p2);
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* All Leaflet methods that accept `Bounds` objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:
|
18
|
+
*
|
19
|
+
* ```js
|
20
|
+
* otherBounds.intersects([[10, 10], [40, 60]]);
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* Note that `Bounds` does not inherit from Leaflet's `Class` object,
|
24
|
+
* which means new classes can't inherit from it, and new methods
|
25
|
+
* can't be added to it with the `include` function.
|
26
|
+
*/
|
27
|
+
|
28
|
+
export function Bounds(a, b) {
|
29
|
+
if (!a) { return; }
|
30
|
+
|
31
|
+
var points = b ? [a, b] : a;
|
32
|
+
|
33
|
+
for (var i = 0, len = points.length; i < len; i++) {
|
34
|
+
this.extend(points[i]);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
Bounds.prototype = {
|
39
|
+
// @method extend(point: Point): this
|
40
|
+
// Extends the bounds to contain the given point.
|
41
|
+
|
42
|
+
// @alternative
|
43
|
+
// @method extend(otherBounds: Bounds): this
|
44
|
+
// Extend the bounds to contain the given bounds
|
45
|
+
extend: function (obj) {
|
46
|
+
var min2, max2;
|
47
|
+
if (!obj) { return this; }
|
48
|
+
|
49
|
+
if (obj instanceof Point || typeof obj[0] === 'number' || 'x' in obj) {
|
50
|
+
min2 = max2 = toPoint(obj);
|
51
|
+
} else {
|
52
|
+
obj = toBounds(obj);
|
53
|
+
min2 = obj.min;
|
54
|
+
max2 = obj.max;
|
55
|
+
|
56
|
+
if (!min2 || !max2) { return this; }
|
57
|
+
}
|
58
|
+
|
59
|
+
// @property min: Point
|
60
|
+
// The top left corner of the rectangle.
|
61
|
+
// @property max: Point
|
62
|
+
// The bottom right corner of the rectangle.
|
63
|
+
if (!this.min && !this.max) {
|
64
|
+
this.min = min2.clone();
|
65
|
+
this.max = max2.clone();
|
66
|
+
} else {
|
67
|
+
this.min.x = Math.min(min2.x, this.min.x);
|
68
|
+
this.max.x = Math.max(max2.x, this.max.x);
|
69
|
+
this.min.y = Math.min(min2.y, this.min.y);
|
70
|
+
this.max.y = Math.max(max2.y, this.max.y);
|
71
|
+
}
|
72
|
+
return this;
|
73
|
+
},
|
74
|
+
|
75
|
+
// @method getCenter(round?: Boolean): Point
|
76
|
+
// Returns the center point of the bounds.
|
77
|
+
getCenter: function (round) {
|
78
|
+
return toPoint(
|
79
|
+
(this.min.x + this.max.x) / 2,
|
80
|
+
(this.min.y + this.max.y) / 2, round);
|
81
|
+
},
|
82
|
+
|
83
|
+
// @method getBottomLeft(): Point
|
84
|
+
// Returns the bottom-left point of the bounds.
|
85
|
+
getBottomLeft: function () {
|
86
|
+
return toPoint(this.min.x, this.max.y);
|
87
|
+
},
|
88
|
+
|
89
|
+
// @method getTopRight(): Point
|
90
|
+
// Returns the top-right point of the bounds.
|
91
|
+
getTopRight: function () { // -> Point
|
92
|
+
return toPoint(this.max.x, this.min.y);
|
93
|
+
},
|
94
|
+
|
95
|
+
// @method getTopLeft(): Point
|
96
|
+
// Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-min)).
|
97
|
+
getTopLeft: function () {
|
98
|
+
return this.min; // left, top
|
99
|
+
},
|
100
|
+
|
101
|
+
// @method getBottomRight(): Point
|
102
|
+
// Returns the bottom-right point of the bounds (i.e. [`this.max`](#bounds-max)).
|
103
|
+
getBottomRight: function () {
|
104
|
+
return this.max; // right, bottom
|
105
|
+
},
|
106
|
+
|
107
|
+
// @method getSize(): Point
|
108
|
+
// Returns the size of the given bounds
|
109
|
+
getSize: function () {
|
110
|
+
return this.max.subtract(this.min);
|
111
|
+
},
|
112
|
+
|
113
|
+
// @method contains(otherBounds: Bounds): Boolean
|
114
|
+
// Returns `true` if the rectangle contains the given one.
|
115
|
+
// @alternative
|
116
|
+
// @method contains(point: Point): Boolean
|
117
|
+
// Returns `true` if the rectangle contains the given point.
|
118
|
+
contains: function (obj) {
|
119
|
+
var min, max;
|
120
|
+
|
121
|
+
if (typeof obj[0] === 'number' || obj instanceof Point) {
|
122
|
+
obj = toPoint(obj);
|
123
|
+
} else {
|
124
|
+
obj = toBounds(obj);
|
125
|
+
}
|
126
|
+
|
127
|
+
if (obj instanceof Bounds) {
|
128
|
+
min = obj.min;
|
129
|
+
max = obj.max;
|
130
|
+
} else {
|
131
|
+
min = max = obj;
|
132
|
+
}
|
133
|
+
|
134
|
+
return (min.x >= this.min.x) &&
|
135
|
+
(max.x <= this.max.x) &&
|
136
|
+
(min.y >= this.min.y) &&
|
137
|
+
(max.y <= this.max.y);
|
138
|
+
},
|
139
|
+
|
140
|
+
// @method intersects(otherBounds: Bounds): Boolean
|
141
|
+
// Returns `true` if the rectangle intersects the given bounds. Two bounds
|
142
|
+
// intersect if they have at least one point in common.
|
143
|
+
intersects: function (bounds) { // (Bounds) -> Boolean
|
144
|
+
bounds = toBounds(bounds);
|
145
|
+
|
146
|
+
var min = this.min,
|
147
|
+
max = this.max,
|
148
|
+
min2 = bounds.min,
|
149
|
+
max2 = bounds.max,
|
150
|
+
xIntersects = (max2.x >= min.x) && (min2.x <= max.x),
|
151
|
+
yIntersects = (max2.y >= min.y) && (min2.y <= max.y);
|
152
|
+
|
153
|
+
return xIntersects && yIntersects;
|
154
|
+
},
|
155
|
+
|
156
|
+
// @method overlaps(otherBounds: Bounds): Boolean
|
157
|
+
// Returns `true` if the rectangle overlaps the given bounds. Two bounds
|
158
|
+
// overlap if their intersection is an area.
|
159
|
+
overlaps: function (bounds) { // (Bounds) -> Boolean
|
160
|
+
bounds = toBounds(bounds);
|
161
|
+
|
162
|
+
var min = this.min,
|
163
|
+
max = this.max,
|
164
|
+
min2 = bounds.min,
|
165
|
+
max2 = bounds.max,
|
166
|
+
xOverlaps = (max2.x > min.x) && (min2.x < max.x),
|
167
|
+
yOverlaps = (max2.y > min.y) && (min2.y < max.y);
|
168
|
+
|
169
|
+
return xOverlaps && yOverlaps;
|
170
|
+
},
|
171
|
+
|
172
|
+
// @method isValid(): Boolean
|
173
|
+
// Returns `true` if the bounds are properly initialized.
|
174
|
+
isValid: function () {
|
175
|
+
return !!(this.min && this.max);
|
176
|
+
},
|
177
|
+
|
178
|
+
|
179
|
+
// @method pad(bufferRatio: Number): Bounds
|
180
|
+
// Returns bounds created by extending or retracting the current bounds by a given ratio in each direction.
|
181
|
+
// For example, a ratio of 0.5 extends the bounds by 50% in each direction.
|
182
|
+
// Negative values will retract the bounds.
|
183
|
+
pad: function (bufferRatio) {
|
184
|
+
var min = this.min,
|
185
|
+
max = this.max,
|
186
|
+
heightBuffer = Math.abs(min.x - max.x) * bufferRatio,
|
187
|
+
widthBuffer = Math.abs(min.y - max.y) * bufferRatio;
|
188
|
+
|
189
|
+
|
190
|
+
return toBounds(
|
191
|
+
toPoint(min.x - heightBuffer, min.y - widthBuffer),
|
192
|
+
toPoint(max.x + heightBuffer, max.y + widthBuffer));
|
193
|
+
},
|
194
|
+
|
195
|
+
|
196
|
+
// @method equals(otherBounds: Bounds): Boolean
|
197
|
+
// Returns `true` if the rectangle is equivalent to the given bounds.
|
198
|
+
equals: function (bounds) {
|
199
|
+
if (!bounds) { return false; }
|
200
|
+
|
201
|
+
bounds = toBounds(bounds);
|
202
|
+
|
203
|
+
return this.min.equals(bounds.getTopLeft()) &&
|
204
|
+
this.max.equals(bounds.getBottomRight());
|
205
|
+
},
|
206
|
+
};
|
207
|
+
|
208
|
+
|
209
|
+
// @factory L.bounds(corner1: Point, corner2: Point)
|
210
|
+
// Creates a Bounds object from two corners coordinate pairs.
|
211
|
+
// @alternative
|
212
|
+
// @factory L.bounds(points: Point[])
|
213
|
+
// Creates a Bounds object from the given array of points.
|
214
|
+
export function toBounds(a, b) {
|
215
|
+
if (!a || a instanceof Bounds) {
|
216
|
+
return a;
|
217
|
+
}
|
218
|
+
return new Bounds(a, b);
|
219
|
+
}
|
@@ -0,0 +1,306 @@
|
|
1
|
+
import {Point, toPoint} from './Point';
|
2
|
+
import * as Util from '../core/Util';
|
3
|
+
import {toLatLng} from '../geo/LatLng';
|
4
|
+
import {centroid} from './PolyUtil';
|
5
|
+
import {toLatLngBounds} from '../geo/LatLngBounds';
|
6
|
+
|
7
|
+
|
8
|
+
/*
|
9
|
+
* @namespace LineUtil
|
10
|
+
*
|
11
|
+
* Various utility functions for polyline points processing, used by Leaflet internally to make polylines lightning-fast.
|
12
|
+
*/
|
13
|
+
|
14
|
+
// Simplify polyline with vertex reduction and Douglas-Peucker simplification.
|
15
|
+
// Improves rendering performance dramatically by lessening the number of points to draw.
|
16
|
+
|
17
|
+
// @function simplify(points: Point[], tolerance: Number): Point[]
|
18
|
+
// Dramatically reduces the number of points in a polyline while retaining
|
19
|
+
// its shape and returns a new array of simplified points, using the
|
20
|
+
// [Ramer-Douglas-Peucker algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm).
|
21
|
+
// Used for a huge performance boost when processing/displaying Leaflet polylines for
|
22
|
+
// each zoom level and also reducing visual noise. tolerance affects the amount of
|
23
|
+
// simplification (lesser value means higher quality but slower and with more points).
|
24
|
+
// Also released as a separated micro-library [Simplify.js](https://mourner.github.io/simplify-js/).
|
25
|
+
export function simplify(points, tolerance) {
|
26
|
+
if (!tolerance || !points.length) {
|
27
|
+
return points.slice();
|
28
|
+
}
|
29
|
+
|
30
|
+
var sqTolerance = tolerance * tolerance;
|
31
|
+
|
32
|
+
// stage 1: vertex reduction
|
33
|
+
points = _reducePoints(points, sqTolerance);
|
34
|
+
|
35
|
+
// stage 2: Douglas-Peucker simplification
|
36
|
+
points = _simplifyDP(points, sqTolerance);
|
37
|
+
|
38
|
+
return points;
|
39
|
+
}
|
40
|
+
|
41
|
+
// @function pointToSegmentDistance(p: Point, p1: Point, p2: Point): Number
|
42
|
+
// Returns the distance between point `p` and segment `p1` to `p2`.
|
43
|
+
export function pointToSegmentDistance(p, p1, p2) {
|
44
|
+
return Math.sqrt(_sqClosestPointOnSegment(p, p1, p2, true));
|
45
|
+
}
|
46
|
+
|
47
|
+
// @function closestPointOnSegment(p: Point, p1: Point, p2: Point): Number
|
48
|
+
// Returns the closest point from a point `p` on a segment `p1` to `p2`.
|
49
|
+
export function closestPointOnSegment(p, p1, p2) {
|
50
|
+
return _sqClosestPointOnSegment(p, p1, p2);
|
51
|
+
}
|
52
|
+
|
53
|
+
// Ramer-Douglas-Peucker simplification, see https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
|
54
|
+
function _simplifyDP(points, sqTolerance) {
|
55
|
+
|
56
|
+
var len = points.length,
|
57
|
+
ArrayConstructor = typeof Uint8Array !== undefined + '' ? Uint8Array : Array,
|
58
|
+
markers = new ArrayConstructor(len);
|
59
|
+
|
60
|
+
markers[0] = markers[len - 1] = 1;
|
61
|
+
|
62
|
+
_simplifyDPStep(points, markers, sqTolerance, 0, len - 1);
|
63
|
+
|
64
|
+
var i,
|
65
|
+
newPoints = [];
|
66
|
+
|
67
|
+
for (i = 0; i < len; i++) {
|
68
|
+
if (markers[i]) {
|
69
|
+
newPoints.push(points[i]);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
return newPoints;
|
74
|
+
}
|
75
|
+
|
76
|
+
function _simplifyDPStep(points, markers, sqTolerance, first, last) {
|
77
|
+
|
78
|
+
var maxSqDist = 0,
|
79
|
+
index, i, sqDist;
|
80
|
+
|
81
|
+
for (i = first + 1; i <= last - 1; i++) {
|
82
|
+
sqDist = _sqClosestPointOnSegment(points[i], points[first], points[last], true);
|
83
|
+
|
84
|
+
if (sqDist > maxSqDist) {
|
85
|
+
index = i;
|
86
|
+
maxSqDist = sqDist;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
if (maxSqDist > sqTolerance) {
|
91
|
+
markers[index] = 1;
|
92
|
+
|
93
|
+
_simplifyDPStep(points, markers, sqTolerance, first, index);
|
94
|
+
_simplifyDPStep(points, markers, sqTolerance, index, last);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
// reduce points that are too close to each other to a single point
|
99
|
+
function _reducePoints(points, sqTolerance) {
|
100
|
+
var reducedPoints = [points[0]];
|
101
|
+
|
102
|
+
for (var i = 1, prev = 0, len = points.length; i < len; i++) {
|
103
|
+
if (_sqDist(points[i], points[prev]) > sqTolerance) {
|
104
|
+
reducedPoints.push(points[i]);
|
105
|
+
prev = i;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
if (prev < len - 1) {
|
109
|
+
reducedPoints.push(points[len - 1]);
|
110
|
+
}
|
111
|
+
return reducedPoints;
|
112
|
+
}
|
113
|
+
|
114
|
+
var _lastCode;
|
115
|
+
|
116
|
+
// @function clipSegment(a: Point, b: Point, bounds: Bounds, useLastCode?: Boolean, round?: Boolean): Point[]|Boolean
|
117
|
+
// Clips the segment a to b by rectangular bounds with the
|
118
|
+
// [Cohen-Sutherland algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm)
|
119
|
+
// (modifying the segment points directly!). Used by Leaflet to only show polyline
|
120
|
+
// points that are on the screen or near, increasing performance.
|
121
|
+
export function clipSegment(a, b, bounds, useLastCode, round) {
|
122
|
+
var codeA = useLastCode ? _lastCode : _getBitCode(a, bounds),
|
123
|
+
codeB = _getBitCode(b, bounds),
|
124
|
+
|
125
|
+
codeOut, p, newCode;
|
126
|
+
|
127
|
+
// save 2nd code to avoid calculating it on the next segment
|
128
|
+
_lastCode = codeB;
|
129
|
+
|
130
|
+
while (true) {
|
131
|
+
// if a,b is inside the clip window (trivial accept)
|
132
|
+
if (!(codeA | codeB)) {
|
133
|
+
return [a, b];
|
134
|
+
}
|
135
|
+
|
136
|
+
// if a,b is outside the clip window (trivial reject)
|
137
|
+
if (codeA & codeB) {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
|
141
|
+
// other cases
|
142
|
+
codeOut = codeA || codeB;
|
143
|
+
p = _getEdgeIntersection(a, b, codeOut, bounds, round);
|
144
|
+
newCode = _getBitCode(p, bounds);
|
145
|
+
|
146
|
+
if (codeOut === codeA) {
|
147
|
+
a = p;
|
148
|
+
codeA = newCode;
|
149
|
+
} else {
|
150
|
+
b = p;
|
151
|
+
codeB = newCode;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
export function _getEdgeIntersection(a, b, code, bounds, round) {
|
157
|
+
var dx = b.x - a.x,
|
158
|
+
dy = b.y - a.y,
|
159
|
+
min = bounds.min,
|
160
|
+
max = bounds.max,
|
161
|
+
x, y;
|
162
|
+
|
163
|
+
if (code & 8) { // top
|
164
|
+
x = a.x + dx * (max.y - a.y) / dy;
|
165
|
+
y = max.y;
|
166
|
+
|
167
|
+
} else if (code & 4) { // bottom
|
168
|
+
x = a.x + dx * (min.y - a.y) / dy;
|
169
|
+
y = min.y;
|
170
|
+
|
171
|
+
} else if (code & 2) { // right
|
172
|
+
x = max.x;
|
173
|
+
y = a.y + dy * (max.x - a.x) / dx;
|
174
|
+
|
175
|
+
} else if (code & 1) { // left
|
176
|
+
x = min.x;
|
177
|
+
y = a.y + dy * (min.x - a.x) / dx;
|
178
|
+
}
|
179
|
+
|
180
|
+
return new Point(x, y, round);
|
181
|
+
}
|
182
|
+
|
183
|
+
export function _getBitCode(p, bounds) {
|
184
|
+
var code = 0;
|
185
|
+
|
186
|
+
if (p.x < bounds.min.x) { // left
|
187
|
+
code |= 1;
|
188
|
+
} else if (p.x > bounds.max.x) { // right
|
189
|
+
code |= 2;
|
190
|
+
}
|
191
|
+
|
192
|
+
if (p.y < bounds.min.y) { // bottom
|
193
|
+
code |= 4;
|
194
|
+
} else if (p.y > bounds.max.y) { // top
|
195
|
+
code |= 8;
|
196
|
+
}
|
197
|
+
|
198
|
+
return code;
|
199
|
+
}
|
200
|
+
|
201
|
+
// square distance (to avoid unnecessary Math.sqrt calls)
|
202
|
+
function _sqDist(p1, p2) {
|
203
|
+
var dx = p2.x - p1.x,
|
204
|
+
dy = p2.y - p1.y;
|
205
|
+
return dx * dx + dy * dy;
|
206
|
+
}
|
207
|
+
|
208
|
+
// return closest point on segment or distance to that point
|
209
|
+
export function _sqClosestPointOnSegment(p, p1, p2, sqDist) {
|
210
|
+
var x = p1.x,
|
211
|
+
y = p1.y,
|
212
|
+
dx = p2.x - x,
|
213
|
+
dy = p2.y - y,
|
214
|
+
dot = dx * dx + dy * dy,
|
215
|
+
t;
|
216
|
+
|
217
|
+
if (dot > 0) {
|
218
|
+
t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
|
219
|
+
|
220
|
+
if (t > 1) {
|
221
|
+
x = p2.x;
|
222
|
+
y = p2.y;
|
223
|
+
} else if (t > 0) {
|
224
|
+
x += dx * t;
|
225
|
+
y += dy * t;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|
229
|
+
dx = p.x - x;
|
230
|
+
dy = p.y - y;
|
231
|
+
|
232
|
+
return sqDist ? dx * dx + dy * dy : new Point(x, y);
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
// @function isFlat(latlngs: LatLng[]): Boolean
|
237
|
+
// Returns true if `latlngs` is a flat array, false is nested.
|
238
|
+
export function isFlat(latlngs) {
|
239
|
+
return !Util.isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined');
|
240
|
+
}
|
241
|
+
|
242
|
+
export function _flat(latlngs) {
|
243
|
+
console.warn('Deprecated use of _flat, please use L.LineUtil.isFlat instead.');
|
244
|
+
return isFlat(latlngs);
|
245
|
+
}
|
246
|
+
|
247
|
+
/* @function polylineCenter(latlngs: LatLng[], crs: CRS): LatLng
|
248
|
+
* Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the passed LatLngs (first ring) from a polyline.
|
249
|
+
*/
|
250
|
+
export function polylineCenter(latlngs, crs) {
|
251
|
+
var i, halfDist, segDist, dist, p1, p2, ratio, center;
|
252
|
+
|
253
|
+
if (!latlngs || latlngs.length === 0) {
|
254
|
+
throw new Error('latlngs not passed');
|
255
|
+
}
|
256
|
+
|
257
|
+
if (!isFlat(latlngs)) {
|
258
|
+
console.warn('latlngs are not flat! Only the first ring will be used');
|
259
|
+
latlngs = latlngs[0];
|
260
|
+
}
|
261
|
+
|
262
|
+
var centroidLatLng = toLatLng([0, 0]);
|
263
|
+
|
264
|
+
var bounds = toLatLngBounds(latlngs);
|
265
|
+
var areaBounds = bounds.getNorthWest().distanceTo(bounds.getSouthWest()) * bounds.getNorthEast().distanceTo(bounds.getNorthWest());
|
266
|
+
// tests showed that below 1700 rounding errors are happening
|
267
|
+
if (areaBounds < 1700) {
|
268
|
+
// getting a inexact center, to move the latlngs near to [0, 0] to prevent rounding errors
|
269
|
+
centroidLatLng = centroid(latlngs);
|
270
|
+
}
|
271
|
+
|
272
|
+
var len = latlngs.length;
|
273
|
+
var points = [];
|
274
|
+
for (i = 0; i < len; i++) {
|
275
|
+
var latlng = toLatLng(latlngs[i]);
|
276
|
+
points.push(crs.project(toLatLng([latlng.lat - centroidLatLng.lat, latlng.lng - centroidLatLng.lng])));
|
277
|
+
}
|
278
|
+
|
279
|
+
for (i = 0, halfDist = 0; i < len - 1; i++) {
|
280
|
+
halfDist += points[i].distanceTo(points[i + 1]) / 2;
|
281
|
+
}
|
282
|
+
|
283
|
+
// The line is so small in the current view that all points are on the same pixel.
|
284
|
+
if (halfDist === 0) {
|
285
|
+
center = points[0];
|
286
|
+
} else {
|
287
|
+
for (i = 0, dist = 0; i < len - 1; i++) {
|
288
|
+
p1 = points[i];
|
289
|
+
p2 = points[i + 1];
|
290
|
+
segDist = p1.distanceTo(p2);
|
291
|
+
dist += segDist;
|
292
|
+
|
293
|
+
if (dist > halfDist) {
|
294
|
+
ratio = (dist - halfDist) / segDist;
|
295
|
+
center = [
|
296
|
+
p2.x - ratio * (p2.x - p1.x),
|
297
|
+
p2.y - ratio * (p2.y - p1.y)
|
298
|
+
];
|
299
|
+
break;
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
var latlngCenter = crs.unproject(toPoint(center));
|
305
|
+
return toLatLng([latlngCenter.lat + centroidLatLng.lat, latlngCenter.lng + centroidLatLng.lng]);
|
306
|
+
}
|