leaflet-with-dashoffset-canvas-fix 1.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2191 -0
- package/LICENSE +26 -0
- package/README.md +3 -0
- package/package.json +149 -0
- package/src/Leaflet.js +24 -0
- package/src/control/Control.Attribution.js +148 -0
- package/src/control/Control.Layers.js +443 -0
- package/src/control/Control.Scale.js +132 -0
- package/src/control/Control.Zoom.js +146 -0
- package/src/control/Control.js +174 -0
- package/src/control/index.js +17 -0
- package/src/core/Browser.js +220 -0
- package/src/core/Class.js +135 -0
- package/src/core/Events.js +344 -0
- package/src/core/Handler.js +57 -0
- package/src/core/Util.js +241 -0
- package/src/core/index.js +15 -0
- package/src/dom/DomEvent.DoubleTap.js +91 -0
- package/src/dom/DomEvent.Pointer.js +97 -0
- package/src/dom/DomEvent.js +315 -0
- package/src/dom/DomUtil.js +349 -0
- package/src/dom/Draggable.js +220 -0
- package/src/dom/PosAnimation.js +113 -0
- package/src/dom/index.js +9 -0
- package/src/geo/LatLng.js +137 -0
- package/src/geo/LatLngBounds.js +251 -0
- package/src/geo/crs/CRS.EPSG3395.js +20 -0
- package/src/geo/crs/CRS.EPSG3857.js +27 -0
- package/src/geo/crs/CRS.EPSG4326.js +23 -0
- package/src/geo/crs/CRS.Earth.js +33 -0
- package/src/geo/crs/CRS.Simple.js +36 -0
- package/src/geo/crs/CRS.js +139 -0
- package/src/geo/crs/index.js +15 -0
- package/src/geo/index.js +7 -0
- package/src/geo/projection/Projection.LonLat.js +28 -0
- package/src/geo/projection/Projection.Mercator.js +49 -0
- package/src/geo/projection/Projection.SphericalMercator.js +44 -0
- package/src/geo/projection/index.js +26 -0
- package/src/geometry/Bounds.js +219 -0
- package/src/geometry/LineUtil.js +306 -0
- package/src/geometry/Point.js +222 -0
- package/src/geometry/PolyUtil.js +129 -0
- package/src/geometry/Transformation.js +79 -0
- package/src/geometry/index.js +8 -0
- package/src/images/layers.svg +1 -0
- package/src/images/logo.svg +1 -0
- package/src/images/marker.svg +1 -0
- package/src/layer/DivOverlay.js +348 -0
- package/src/layer/FeatureGroup.js +94 -0
- package/src/layer/GeoJSON.js +452 -0
- package/src/layer/ImageOverlay.js +270 -0
- package/src/layer/Layer.js +275 -0
- package/src/layer/LayerGroup.js +159 -0
- package/src/layer/Popup.js +506 -0
- package/src/layer/SVGOverlay.js +50 -0
- package/src/layer/Tooltip.js +444 -0
- package/src/layer/VideoOverlay.js +106 -0
- package/src/layer/index.js +24 -0
- package/src/layer/marker/DivIcon.js +74 -0
- package/src/layer/marker/Icon.Default.js +66 -0
- package/src/layer/marker/Icon.js +165 -0
- package/src/layer/marker/Marker.Drag.js +161 -0
- package/src/layer/marker/Marker.js +419 -0
- package/src/layer/marker/index.js +8 -0
- package/src/layer/tile/GridLayer.js +923 -0
- package/src/layer/tile/TileLayer.WMS.js +137 -0
- package/src/layer/tile/TileLayer.js +289 -0
- package/src/layer/tile/index.js +6 -0
- package/src/layer/vector/Canvas.js +493 -0
- package/src/layer/vector/Circle.js +113 -0
- package/src/layer/vector/CircleMarker.js +109 -0
- package/src/layer/vector/Path.js +148 -0
- package/src/layer/vector/Polygon.js +159 -0
- package/src/layer/vector/Polyline.js +307 -0
- package/src/layer/vector/Rectangle.js +57 -0
- package/src/layer/vector/Renderer.getRenderer.js +45 -0
- package/src/layer/vector/Renderer.js +133 -0
- package/src/layer/vector/SVG.Util.js +39 -0
- package/src/layer/vector/SVG.VML.js +144 -0
- package/src/layer/vector/SVG.js +207 -0
- package/src/layer/vector/index.js +14 -0
- package/src/map/Map.js +1751 -0
- package/src/map/handler/Map.BoxZoom.js +152 -0
- package/src/map/handler/Map.DoubleClickZoom.js +55 -0
- package/src/map/handler/Map.Drag.js +235 -0
- package/src/map/handler/Map.Keyboard.js +183 -0
- package/src/map/handler/Map.ScrollWheelZoom.js +91 -0
- package/src/map/handler/Map.TapHold.js +102 -0
- package/src/map/handler/Map.TouchZoom.js +130 -0
- package/src/map/index.js +17 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import {Class} from './Class';
|
|
2
|
+
import * as Util from './Util';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* @class Evented
|
|
6
|
+
* @aka L.Evented
|
|
7
|
+
* @inherits Class
|
|
8
|
+
*
|
|
9
|
+
* A set of methods shared between event-powered classes (like `Map` and `Marker`). Generally, events allow you to execute some function when something happens with an object (e.g. the user clicks on the map, causing the map to fire `'click'` event).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* map.on('click', function(e) {
|
|
15
|
+
* alert(e.latlng);
|
|
16
|
+
* } );
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Leaflet deals with event listeners by reference, so if you want to add a listener and then remove it, define it as a function:
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* function onClick(e) { ... }
|
|
23
|
+
*
|
|
24
|
+
* map.on('click', onClick);
|
|
25
|
+
* map.off('click', onClick);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export var Events = {
|
|
30
|
+
/* @method on(type: String, fn: Function, context?: Object): this
|
|
31
|
+
* Adds a listener function (`fn`) to a particular event type of the object. You can optionally specify the context of the listener (object the this keyword will point to). You can also pass several space-separated types (e.g. `'click dblclick'`).
|
|
32
|
+
*
|
|
33
|
+
* @alternative
|
|
34
|
+
* @method on(eventMap: Object): this
|
|
35
|
+
* Adds a set of type/listener pairs, e.g. `{click: onClick, mousemove: onMouseMove}`
|
|
36
|
+
*/
|
|
37
|
+
on: function (types, fn, context) {
|
|
38
|
+
|
|
39
|
+
// types can be a map of types/handlers
|
|
40
|
+
if (typeof types === 'object') {
|
|
41
|
+
for (var type in types) {
|
|
42
|
+
// we don't process space-separated events here for performance;
|
|
43
|
+
// it's a hot path since Layer uses the on(obj) syntax
|
|
44
|
+
this._on(type, types[type], fn);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} else {
|
|
48
|
+
// types can be a string of space-separated words
|
|
49
|
+
types = Util.splitWords(types);
|
|
50
|
+
|
|
51
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
|
52
|
+
this._on(types[i], fn, context);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
/* @method off(type: String, fn?: Function, context?: Object): this
|
|
60
|
+
* Removes a previously added listener function. If no function is specified, it will remove all the listeners of that particular event from the object. Note that if you passed a custom context to `on`, you must pass the same context to `off` in order to remove the listener.
|
|
61
|
+
*
|
|
62
|
+
* @alternative
|
|
63
|
+
* @method off(eventMap: Object): this
|
|
64
|
+
* Removes a set of type/listener pairs.
|
|
65
|
+
*
|
|
66
|
+
* @alternative
|
|
67
|
+
* @method off: this
|
|
68
|
+
* Removes all listeners to all events on the object. This includes implicitly attached events.
|
|
69
|
+
*/
|
|
70
|
+
off: function (types, fn, context) {
|
|
71
|
+
|
|
72
|
+
if (!arguments.length) {
|
|
73
|
+
// clear all listeners if called without arguments
|
|
74
|
+
delete this._events;
|
|
75
|
+
|
|
76
|
+
} else if (typeof types === 'object') {
|
|
77
|
+
for (var type in types) {
|
|
78
|
+
this._off(type, types[type], fn);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
} else {
|
|
82
|
+
types = Util.splitWords(types);
|
|
83
|
+
|
|
84
|
+
var removeAll = arguments.length === 1;
|
|
85
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
|
86
|
+
if (removeAll) {
|
|
87
|
+
this._off(types[i]);
|
|
88
|
+
} else {
|
|
89
|
+
this._off(types[i], fn, context);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return this;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
// attach listener (without syntactic sugar now)
|
|
98
|
+
_on: function (type, fn, context, _once) {
|
|
99
|
+
if (typeof fn !== 'function') {
|
|
100
|
+
console.warn('wrong listener type: ' + typeof fn);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// check if fn already there
|
|
105
|
+
if (this._listens(type, fn, context) !== false) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (context === this) {
|
|
110
|
+
// Less memory footprint.
|
|
111
|
+
context = undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var newListener = {fn: fn, ctx: context};
|
|
115
|
+
if (_once) {
|
|
116
|
+
newListener.once = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this._events = this._events || {};
|
|
120
|
+
this._events[type] = this._events[type] || [];
|
|
121
|
+
this._events[type].push(newListener);
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
_off: function (type, fn, context) {
|
|
125
|
+
var listeners,
|
|
126
|
+
i,
|
|
127
|
+
len;
|
|
128
|
+
|
|
129
|
+
if (!this._events) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
listeners = this._events[type];
|
|
134
|
+
if (!listeners) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (arguments.length === 1) { // remove all
|
|
139
|
+
if (this._firingCount) {
|
|
140
|
+
// Set all removed listeners to noop
|
|
141
|
+
// so they are not called if remove happens in fire
|
|
142
|
+
for (i = 0, len = listeners.length; i < len; i++) {
|
|
143
|
+
listeners[i].fn = Util.falseFn;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// clear all listeners for a type if function isn't specified
|
|
147
|
+
delete this._events[type];
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof fn !== 'function') {
|
|
152
|
+
console.warn('wrong listener type: ' + typeof fn);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// find fn and remove it
|
|
157
|
+
var index = this._listens(type, fn, context);
|
|
158
|
+
if (index !== false) {
|
|
159
|
+
var listener = listeners[index];
|
|
160
|
+
if (this._firingCount) {
|
|
161
|
+
// set the removed listener to noop so that's not called if remove happens in fire
|
|
162
|
+
listener.fn = Util.falseFn;
|
|
163
|
+
|
|
164
|
+
/* copy array in case events are being fired */
|
|
165
|
+
this._events[type] = listeners = listeners.slice();
|
|
166
|
+
}
|
|
167
|
+
listeners.splice(index, 1);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
// @method fire(type: String, data?: Object, propagate?: Boolean): this
|
|
172
|
+
// Fires an event of the specified type. You can optionally provide a data
|
|
173
|
+
// object — the first argument of the listener function will contain its
|
|
174
|
+
// properties. The event can optionally be propagated to event parents.
|
|
175
|
+
fire: function (type, data, propagate) {
|
|
176
|
+
if (!this.listens(type, propagate)) { return this; }
|
|
177
|
+
|
|
178
|
+
var event = Util.extend({}, data, {
|
|
179
|
+
type: type,
|
|
180
|
+
target: this,
|
|
181
|
+
sourceTarget: data && data.sourceTarget || this
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
if (this._events) {
|
|
185
|
+
var listeners = this._events[type];
|
|
186
|
+
if (listeners) {
|
|
187
|
+
this._firingCount = (this._firingCount + 1) || 1;
|
|
188
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
|
189
|
+
var l = listeners[i];
|
|
190
|
+
// off overwrites l.fn, so we need to copy fn to a var
|
|
191
|
+
var fn = l.fn;
|
|
192
|
+
if (l.once) {
|
|
193
|
+
this.off(type, fn, l.ctx);
|
|
194
|
+
}
|
|
195
|
+
fn.call(l.ctx || this, event);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this._firingCount--;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (propagate) {
|
|
203
|
+
// propagate the event to parents (set with addEventParent)
|
|
204
|
+
this._propagateEvent(event);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return this;
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
// @method listens(type: String, propagate?: Boolean): Boolean
|
|
211
|
+
// @method listens(type: String, fn: Function, context?: Object, propagate?: Boolean): Boolean
|
|
212
|
+
// Returns `true` if a particular event type has any listeners attached to it.
|
|
213
|
+
// The verification can optionally be propagated, it will return `true` if parents have the listener attached to it.
|
|
214
|
+
listens: function (type, fn, context, propagate) {
|
|
215
|
+
if (typeof type !== 'string') {
|
|
216
|
+
console.warn('"string" type argument expected');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// we don't overwrite the input `fn` value, because we need to use it for propagation
|
|
220
|
+
var _fn = fn;
|
|
221
|
+
if (typeof fn !== 'function') {
|
|
222
|
+
propagate = !!fn;
|
|
223
|
+
_fn = undefined;
|
|
224
|
+
context = undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
var listeners = this._events && this._events[type];
|
|
228
|
+
if (listeners && listeners.length) {
|
|
229
|
+
if (this._listens(type, _fn, context) !== false) {
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (propagate) {
|
|
235
|
+
// also check parents for listeners if event propagates
|
|
236
|
+
for (var id in this._eventParents) {
|
|
237
|
+
if (this._eventParents[id].listens(type, fn, context, propagate)) { return true; }
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return false;
|
|
241
|
+
},
|
|
242
|
+
|
|
243
|
+
// returns the index (number) or false
|
|
244
|
+
_listens: function (type, fn, context) {
|
|
245
|
+
if (!this._events) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
var listeners = this._events[type] || [];
|
|
250
|
+
if (!fn) {
|
|
251
|
+
return !!listeners.length;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (context === this) {
|
|
255
|
+
// Less memory footprint.
|
|
256
|
+
context = undefined;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
for (var i = 0, len = listeners.length; i < len; i++) {
|
|
260
|
+
if (listeners[i].fn === fn && listeners[i].ctx === context) {
|
|
261
|
+
return i;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return false;
|
|
265
|
+
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
// @method once(…): this
|
|
269
|
+
// Behaves as [`on(…)`](#evented-on), except the listener will only get fired once and then removed.
|
|
270
|
+
once: function (types, fn, context) {
|
|
271
|
+
|
|
272
|
+
// types can be a map of types/handlers
|
|
273
|
+
if (typeof types === 'object') {
|
|
274
|
+
for (var type in types) {
|
|
275
|
+
// we don't process space-separated events here for performance;
|
|
276
|
+
// it's a hot path since Layer uses the on(obj) syntax
|
|
277
|
+
this._on(type, types[type], fn, true);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
} else {
|
|
281
|
+
// types can be a string of space-separated words
|
|
282
|
+
types = Util.splitWords(types);
|
|
283
|
+
|
|
284
|
+
for (var i = 0, len = types.length; i < len; i++) {
|
|
285
|
+
this._on(types[i], fn, context, true);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return this;
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
// @method addEventParent(obj: Evented): this
|
|
293
|
+
// Adds an event parent - an `Evented` that will receive propagated events
|
|
294
|
+
addEventParent: function (obj) {
|
|
295
|
+
this._eventParents = this._eventParents || {};
|
|
296
|
+
this._eventParents[Util.stamp(obj)] = obj;
|
|
297
|
+
return this;
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
// @method removeEventParent(obj: Evented): this
|
|
301
|
+
// Removes an event parent, so it will stop receiving propagated events
|
|
302
|
+
removeEventParent: function (obj) {
|
|
303
|
+
if (this._eventParents) {
|
|
304
|
+
delete this._eventParents[Util.stamp(obj)];
|
|
305
|
+
}
|
|
306
|
+
return this;
|
|
307
|
+
},
|
|
308
|
+
|
|
309
|
+
_propagateEvent: function (e) {
|
|
310
|
+
for (var id in this._eventParents) {
|
|
311
|
+
this._eventParents[id].fire(e.type, Util.extend({
|
|
312
|
+
layer: e.target,
|
|
313
|
+
propagatedFrom: e.target
|
|
314
|
+
}, e), true);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
// aliases; we should ditch those eventually
|
|
320
|
+
|
|
321
|
+
// @method addEventListener(…): this
|
|
322
|
+
// Alias to [`on(…)`](#evented-on)
|
|
323
|
+
Events.addEventListener = Events.on;
|
|
324
|
+
|
|
325
|
+
// @method removeEventListener(…): this
|
|
326
|
+
// Alias to [`off(…)`](#evented-off)
|
|
327
|
+
|
|
328
|
+
// @method clearAllEventListeners(…): this
|
|
329
|
+
// Alias to [`off()`](#evented-off)
|
|
330
|
+
Events.removeEventListener = Events.clearAllEventListeners = Events.off;
|
|
331
|
+
|
|
332
|
+
// @method addOneTimeEventListener(…): this
|
|
333
|
+
// Alias to [`once(…)`](#evented-once)
|
|
334
|
+
Events.addOneTimeEventListener = Events.once;
|
|
335
|
+
|
|
336
|
+
// @method fireEvent(…): this
|
|
337
|
+
// Alias to [`fire(…)`](#evented-fire)
|
|
338
|
+
Events.fireEvent = Events.fire;
|
|
339
|
+
|
|
340
|
+
// @method hasEventListeners(…): Boolean
|
|
341
|
+
// Alias to [`listens(…)`](#evented-listens)
|
|
342
|
+
Events.hasEventListeners = Events.listens;
|
|
343
|
+
|
|
344
|
+
export var Evented = Class.extend(Events);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {Class} from './Class';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
L.Handler is a base class for handler classes that are used internally to inject
|
|
5
|
+
interaction features like dragging to classes like Map and Marker.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// @class Handler
|
|
9
|
+
// @aka L.Handler
|
|
10
|
+
// Abstract class for map interaction handlers
|
|
11
|
+
|
|
12
|
+
export var Handler = Class.extend({
|
|
13
|
+
initialize: function (map) {
|
|
14
|
+
this._map = map;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// @method enable(): this
|
|
18
|
+
// Enables the handler
|
|
19
|
+
enable: function () {
|
|
20
|
+
if (this._enabled) { return this; }
|
|
21
|
+
|
|
22
|
+
this._enabled = true;
|
|
23
|
+
this.addHooks();
|
|
24
|
+
return this;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// @method disable(): this
|
|
28
|
+
// Disables the handler
|
|
29
|
+
disable: function () {
|
|
30
|
+
if (!this._enabled) { return this; }
|
|
31
|
+
|
|
32
|
+
this._enabled = false;
|
|
33
|
+
this.removeHooks();
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// @method enabled(): Boolean
|
|
38
|
+
// Returns `true` if the handler is enabled
|
|
39
|
+
enabled: function () {
|
|
40
|
+
return !!this._enabled;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// @section Extension methods
|
|
44
|
+
// Classes inheriting from `Handler` must implement the two following methods:
|
|
45
|
+
// @method addHooks()
|
|
46
|
+
// Called when the handler is enabled, should add event hooks.
|
|
47
|
+
// @method removeHooks()
|
|
48
|
+
// Called when the handler is disabled, should remove the event hooks added previously.
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// @section There is static function which can be called without instantiating L.Handler:
|
|
52
|
+
// @function addTo(map: Map, name: String): this
|
|
53
|
+
// Adds a new Handler to the given map with the given name.
|
|
54
|
+
Handler.addTo = function (map, name) {
|
|
55
|
+
map.addHandler(name, this);
|
|
56
|
+
return this;
|
|
57
|
+
};
|
package/src/core/Util.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @namespace Util
|
|
3
|
+
*
|
|
4
|
+
* Various utility functions, used by Leaflet internally.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// @function extend(dest: Object, src?: Object): Object
|
|
8
|
+
// Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter. Has an `L.extend` shortcut.
|
|
9
|
+
export function extend(dest) {
|
|
10
|
+
var i, j, len, src;
|
|
11
|
+
|
|
12
|
+
for (j = 1, len = arguments.length; j < len; j++) {
|
|
13
|
+
src = arguments[j];
|
|
14
|
+
for (i in src) {
|
|
15
|
+
dest[i] = src[i];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return dest;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// @function create(proto: Object, properties?: Object): Object
|
|
22
|
+
// Compatibility polyfill for [Object.create](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/create)
|
|
23
|
+
export var create = Object.create || (function () {
|
|
24
|
+
function F() {}
|
|
25
|
+
return function (proto) {
|
|
26
|
+
F.prototype = proto;
|
|
27
|
+
return new F();
|
|
28
|
+
};
|
|
29
|
+
})();
|
|
30
|
+
|
|
31
|
+
// @function bind(fn: Function, …): Function
|
|
32
|
+
// Returns a new function bound to the arguments passed, like [Function.prototype.bind](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).
|
|
33
|
+
// Has a `L.bind()` shortcut.
|
|
34
|
+
export function bind(fn, obj) {
|
|
35
|
+
var slice = Array.prototype.slice;
|
|
36
|
+
|
|
37
|
+
if (fn.bind) {
|
|
38
|
+
return fn.bind.apply(fn, slice.call(arguments, 1));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var args = slice.call(arguments, 2);
|
|
42
|
+
|
|
43
|
+
return function () {
|
|
44
|
+
return fn.apply(obj, args.length ? args.concat(slice.call(arguments)) : arguments);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @property lastId: Number
|
|
49
|
+
// Last unique ID used by [`stamp()`](#util-stamp)
|
|
50
|
+
export var lastId = 0;
|
|
51
|
+
|
|
52
|
+
// @function stamp(obj: Object): Number
|
|
53
|
+
// Returns the unique ID of an object, assigning it one if it doesn't have it.
|
|
54
|
+
export function stamp(obj) {
|
|
55
|
+
if (!('_leaflet_id' in obj)) {
|
|
56
|
+
obj['_leaflet_id'] = ++lastId;
|
|
57
|
+
}
|
|
58
|
+
return obj._leaflet_id;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// @function throttle(fn: Function, time: Number, context: Object): Function
|
|
62
|
+
// Returns a function which executes function `fn` with the given scope `context`
|
|
63
|
+
// (so that the `this` keyword refers to `context` inside `fn`'s code). The function
|
|
64
|
+
// `fn` will be called no more than one time per given amount of `time`. The arguments
|
|
65
|
+
// received by the bound function will be any arguments passed when binding the
|
|
66
|
+
// function, followed by any arguments passed when invoking the bound function.
|
|
67
|
+
// Has an `L.throttle` shortcut.
|
|
68
|
+
export function throttle(fn, time, context) {
|
|
69
|
+
var lock, args, wrapperFn, later;
|
|
70
|
+
|
|
71
|
+
later = function () {
|
|
72
|
+
// reset lock and call if queued
|
|
73
|
+
lock = false;
|
|
74
|
+
if (args) {
|
|
75
|
+
wrapperFn.apply(context, args);
|
|
76
|
+
args = false;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
wrapperFn = function () {
|
|
81
|
+
if (lock) {
|
|
82
|
+
// called too soon, queue to call later
|
|
83
|
+
args = arguments;
|
|
84
|
+
|
|
85
|
+
} else {
|
|
86
|
+
// call and lock until later
|
|
87
|
+
fn.apply(context, arguments);
|
|
88
|
+
setTimeout(later, time);
|
|
89
|
+
lock = true;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return wrapperFn;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// @function wrapNum(num: Number, range: Number[], includeMax?: Boolean): Number
|
|
97
|
+
// Returns the number `num` modulo `range` in such a way so it lies within
|
|
98
|
+
// `range[0]` and `range[1]`. The returned value will be always smaller than
|
|
99
|
+
// `range[1]` unless `includeMax` is set to `true`.
|
|
100
|
+
export function wrapNum(x, range, includeMax) {
|
|
101
|
+
var max = range[1],
|
|
102
|
+
min = range[0],
|
|
103
|
+
d = max - min;
|
|
104
|
+
return x === max && includeMax ? x : ((x - min) % d + d) % d + min;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// @function falseFn(): Function
|
|
108
|
+
// Returns a function which always returns `false`.
|
|
109
|
+
export function falseFn() { return false; }
|
|
110
|
+
|
|
111
|
+
// @function formatNum(num: Number, precision?: Number|false): Number
|
|
112
|
+
// Returns the number `num` rounded with specified `precision`.
|
|
113
|
+
// The default `precision` value is 6 decimal places.
|
|
114
|
+
// `false` can be passed to skip any processing (can be useful to avoid round-off errors).
|
|
115
|
+
export function formatNum(num, precision) {
|
|
116
|
+
if (precision === false) { return num; }
|
|
117
|
+
var pow = Math.pow(10, precision === undefined ? 6 : precision);
|
|
118
|
+
return Math.round(num * pow) / pow;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// @function trim(str: String): String
|
|
122
|
+
// Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim)
|
|
123
|
+
export function trim(str) {
|
|
124
|
+
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// @function splitWords(str: String): String[]
|
|
128
|
+
// Trims and splits the string on whitespace and returns the array of parts.
|
|
129
|
+
export function splitWords(str) {
|
|
130
|
+
return trim(str).split(/\s+/);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// @function setOptions(obj: Object, options: Object): Object
|
|
134
|
+
// Merges the given properties to the `options` of the `obj` object, returning the resulting options. See `Class options`. Has an `L.setOptions` shortcut.
|
|
135
|
+
export function setOptions(obj, options) {
|
|
136
|
+
if (!Object.prototype.hasOwnProperty.call(obj, 'options')) {
|
|
137
|
+
obj.options = obj.options ? create(obj.options) : {};
|
|
138
|
+
}
|
|
139
|
+
for (var i in options) {
|
|
140
|
+
obj.options[i] = options[i];
|
|
141
|
+
}
|
|
142
|
+
return obj.options;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// @function getParamString(obj: Object, existingUrl?: String, uppercase?: Boolean): String
|
|
146
|
+
// Converts an object into a parameter URL string, e.g. `{a: "foo", b: "bar"}`
|
|
147
|
+
// translates to `'?a=foo&b=bar'`. If `existingUrl` is set, the parameters will
|
|
148
|
+
// be appended at the end. If `uppercase` is `true`, the parameter names will
|
|
149
|
+
// be uppercased (e.g. `'?A=foo&B=bar'`)
|
|
150
|
+
export function getParamString(obj, existingUrl, uppercase) {
|
|
151
|
+
var params = [];
|
|
152
|
+
for (var i in obj) {
|
|
153
|
+
params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]));
|
|
154
|
+
}
|
|
155
|
+
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var templateRe = /\{ *([\w_ -]+) *\}/g;
|
|
159
|
+
|
|
160
|
+
// @function template(str: String, data: Object): String
|
|
161
|
+
// Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
|
|
162
|
+
// and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
|
|
163
|
+
// `('Hello foo, bar')`. You can also specify functions instead of strings for
|
|
164
|
+
// data values — they will be evaluated passing `data` as an argument.
|
|
165
|
+
export function template(str, data) {
|
|
166
|
+
return str.replace(templateRe, function (str, key) {
|
|
167
|
+
var value = data[key];
|
|
168
|
+
|
|
169
|
+
if (value === undefined) {
|
|
170
|
+
throw new Error('No value provided for variable ' + str);
|
|
171
|
+
|
|
172
|
+
} else if (typeof value === 'function') {
|
|
173
|
+
value = value(data);
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// @function isArray(obj): Boolean
|
|
180
|
+
// Compatibility polyfill for [Array.isArray](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)
|
|
181
|
+
export var isArray = Array.isArray || function (obj) {
|
|
182
|
+
return (Object.prototype.toString.call(obj) === '[object Array]');
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// @function indexOf(array: Array, el: Object): Number
|
|
186
|
+
// Compatibility polyfill for [Array.prototype.indexOf](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf)
|
|
187
|
+
export function indexOf(array, el) {
|
|
188
|
+
for (var i = 0; i < array.length; i++) {
|
|
189
|
+
if (array[i] === el) { return i; }
|
|
190
|
+
}
|
|
191
|
+
return -1;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// @property emptyImageUrl: String
|
|
195
|
+
// Data URI string containing a base64-encoded empty GIF image.
|
|
196
|
+
// Used as a hack to free memory from unused images on WebKit-powered
|
|
197
|
+
// mobile devices (by setting image `src` to this string).
|
|
198
|
+
export var emptyImageUrl = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
|
|
199
|
+
|
|
200
|
+
// inspired by https://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
|
201
|
+
|
|
202
|
+
function getPrefixed(name) {
|
|
203
|
+
return window['webkit' + name] || window['moz' + name] || window['ms' + name];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
var lastTime = 0;
|
|
207
|
+
|
|
208
|
+
// fallback for IE 7-8
|
|
209
|
+
function timeoutDefer(fn) {
|
|
210
|
+
var time = +new Date(),
|
|
211
|
+
timeToCall = Math.max(0, 16 - (time - lastTime));
|
|
212
|
+
|
|
213
|
+
lastTime = time + timeToCall;
|
|
214
|
+
return window.setTimeout(fn, timeToCall);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export var requestFn = window.requestAnimationFrame || getPrefixed('RequestAnimationFrame') || timeoutDefer;
|
|
218
|
+
export var cancelFn = window.cancelAnimationFrame || getPrefixed('CancelAnimationFrame') ||
|
|
219
|
+
getPrefixed('CancelRequestAnimationFrame') || function (id) { window.clearTimeout(id); };
|
|
220
|
+
|
|
221
|
+
// @function requestAnimFrame(fn: Function, context?: Object, immediate?: Boolean): Number
|
|
222
|
+
// Schedules `fn` to be executed when the browser repaints. `fn` is bound to
|
|
223
|
+
// `context` if given. When `immediate` is set, `fn` is called immediately if
|
|
224
|
+
// the browser doesn't have native support for
|
|
225
|
+
// [`window.requestAnimationFrame`](https://developer.mozilla.org/docs/Web/API/window/requestAnimationFrame),
|
|
226
|
+
// otherwise it's delayed. Returns a request ID that can be used to cancel the request.
|
|
227
|
+
export function requestAnimFrame(fn, context, immediate) {
|
|
228
|
+
if (immediate && requestFn === timeoutDefer) {
|
|
229
|
+
fn.call(context);
|
|
230
|
+
} else {
|
|
231
|
+
return requestFn.call(window, bind(fn, context));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// @function cancelAnimFrame(id: Number): undefined
|
|
236
|
+
// Cancels a previous `requestAnimFrame`. See also [window.cancelAnimationFrame](https://developer.mozilla.org/docs/Web/API/window/cancelAnimationFrame).
|
|
237
|
+
export function cancelAnimFrame(id) {
|
|
238
|
+
if (id) {
|
|
239
|
+
cancelFn.call(window, id);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Browser from './Browser';
|
|
2
|
+
export {Browser};
|
|
3
|
+
|
|
4
|
+
export {Class} from './Class';
|
|
5
|
+
|
|
6
|
+
import {Evented} from './Events';
|
|
7
|
+
import {Events} from './Events';
|
|
8
|
+
export {Evented};
|
|
9
|
+
export var Mixin = {Events: Events};
|
|
10
|
+
|
|
11
|
+
export {Handler} from './Handler';
|
|
12
|
+
|
|
13
|
+
import * as Util from './Util';
|
|
14
|
+
export {Util};
|
|
15
|
+
export {extend, bind, stamp, setOptions} from './Util';
|