leaflet-js 0.6.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.rdoc +32 -0
- data/LICENSE +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +15 -0
- data/leaflet-js.gemspec +28 -0
- data/lib/leaflet-js.rb +10 -0
- data/lib/leaflet.draw/BREAKINGCHANGES.md +54 -0
- data/lib/leaflet.draw/CHANGELOG.md +73 -0
- data/lib/leaflet.draw/Jakefile.js +26 -0
- data/lib/leaflet.draw/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.draw/README.md +364 -0
- data/lib/leaflet.draw/TODO.md +62 -0
- data/lib/leaflet.draw/build/build.html +243 -0
- data/lib/leaflet.draw/build/build.js +189 -0
- data/lib/leaflet.draw/build/deps.js +75 -0
- data/lib/leaflet.draw/build/hintrc.js +47 -0
- data/lib/leaflet.draw/build/leaflet.draw-include.js +42 -0
- data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
- data/lib/leaflet.draw/dist/leaflet.draw-src.js +2429 -0
- data/lib/leaflet.draw/dist/leaflet.draw.css +212 -0
- data/lib/leaflet.draw/dist/leaflet.draw.ie.css +44 -0
- data/lib/leaflet.draw/dist/leaflet.draw.js +10 -0
- data/lib/leaflet.draw/examples/basic.html +106 -0
- data/lib/leaflet.draw/examples/edithandlers.html +67 -0
- data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-shadow.png +0 -0
- data/lib/leaflet.draw/examples/libs/leaflet-src.js +8587 -0
- data/lib/leaflet.draw/examples/libs/leaflet.css +459 -0
- data/lib/leaflet.draw/examples/libs/leaflet.ie.css +51 -0
- data/lib/leaflet.draw/package.json +37 -0
- data/lib/leaflet.draw/spec/after.js +2 -0
- data/lib/leaflet.draw/spec/before.js +3 -0
- data/lib/leaflet.draw/spec/expect.js +1253 -0
- data/lib/leaflet.draw/spec/happen.js +93 -0
- data/lib/leaflet.draw/spec/index.html +36 -0
- data/lib/leaflet.draw/spec/karma.conf.js +69 -0
- data/lib/leaflet.draw/spec/sinon.js +4223 -0
- data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +15 -0
- data/lib/leaflet.draw/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet.draw/src/Control.Draw.js +101 -0
- data/lib/leaflet.draw/src/Leaflet.draw.js +5 -0
- data/lib/leaflet.draw/src/Toolbar.js +187 -0
- data/lib/leaflet.draw/src/Tooltip.js +52 -0
- data/lib/leaflet.draw/src/copyright.js +8 -0
- data/lib/leaflet.draw/src/draw/DrawToolbar.js +107 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +59 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +74 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +97 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +79 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +360 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +41 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +67 -0
- data/lib/leaflet.draw/src/edit/EditToolbar.js +93 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Circle.js +63 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +267 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Rectangle.js +117 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +138 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +109 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +233 -0
- data/lib/leaflet.draw/src/ext/LatLngUtil.js +18 -0
- data/lib/leaflet.draw/src/ext/LineUtil.Intersect.js +15 -0
- data/lib/leaflet.draw/src/ext/Polygon.Intersect.js +27 -0
- data/lib/leaflet.draw/src/ext/Polyline.Intersect.js +85 -0
- data/lib/leaflet.label/CHANGELOG.md +35 -0
- data/lib/leaflet.label/Jakefile.js +21 -0
- data/lib/leaflet.label/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.label/README.md +86 -0
- data/lib/leaflet.label/build/build.js +155 -0
- data/lib/leaflet.label/build/deps.js +24 -0
- data/lib/leaflet.label/build/hint.js +30 -0
- data/lib/leaflet.label/build/hintrc.js +47 -0
- data/lib/leaflet.label/dist/images/death.png +0 -0
- data/lib/leaflet.label/dist/leaflet.label-src.js +359 -0
- data/lib/leaflet.label/dist/leaflet.label.css +33 -0
- data/lib/leaflet.label/dist/leaflet.label.js +9 -0
- data/lib/leaflet.label/example/label.html +82 -0
- data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-shadow.png +0 -0
- data/lib/leaflet.label/libs/leaflet/leaflet-src.js +8587 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.css +459 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +51 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.js +8 -0
- data/lib/leaflet.label/src/FeatureGroup.Label.js +20 -0
- data/lib/leaflet.label/src/Label.js +123 -0
- data/lib/leaflet.label/src/Leaflet.label.js +5 -0
- data/lib/leaflet.label/src/Map.Label.js +7 -0
- data/lib/leaflet.label/src/Marker.Label.js +160 -0
- data/lib/leaflet.label/src/Path.Label.js +55 -0
- data/lib/leaflet.label/src/copyright.js +8 -0
- data/lib/leaflet/CHANGELOG.md +637 -0
- data/lib/leaflet/CONTRIBUTING.md +155 -0
- data/lib/leaflet/Jakefile.js +26 -0
- data/lib/leaflet/LICENSE +23 -0
- data/lib/leaflet/README.md +30 -0
- data/lib/leaflet/build/build.html +243 -0
- data/lib/leaflet/build/build.js +193 -0
- data/lib/leaflet/build/deps.js +256 -0
- data/lib/leaflet/build/hintrc.js +37 -0
- data/lib/leaflet/debug/css/mobile.css +6 -0
- data/lib/leaflet/debug/css/screen.css +5 -0
- data/lib/leaflet/debug/hacks/jitter.html +43 -0
- data/lib/leaflet/debug/leaflet-include.js +59 -0
- data/lib/leaflet/debug/map/canvas.html +47 -0
- data/lib/leaflet/debug/map/controls.html +50 -0
- data/lib/leaflet/debug/map/geolocation.html +35 -0
- data/lib/leaflet/debug/map/image-overlay.html +44 -0
- data/lib/leaflet/debug/map/map-mobile.html +35 -0
- data/lib/leaflet/debug/map/map.html +60 -0
- data/lib/leaflet/debug/map/max-bounds.html +37 -0
- data/lib/leaflet/debug/map/scroll.html +36 -0
- data/lib/leaflet/debug/map/simple-proj.html +45 -0
- data/lib/leaflet/debug/map/wms-marble.html +31 -0
- data/lib/leaflet/debug/map/wms.html +41 -0
- data/lib/leaflet/debug/map/zoomlevels.html +46 -0
- data/lib/leaflet/debug/tests/add_remove_layers.html +88 -0
- data/lib/leaflet/debug/tests/bringtoback.html +38 -0
- data/lib/leaflet/debug/tests/click_on_canvas.html +59 -0
- data/lib/leaflet/debug/tests/click_on_canvas_broken.html +49 -0
- data/lib/leaflet/debug/tests/opacity.html +57 -0
- data/lib/leaflet/debug/tests/remove_while_dragging.html +29 -0
- data/lib/leaflet/debug/tests/removetilewhilepan.html +42 -0
- data/lib/leaflet/debug/tests/reuse_popups.html +41 -0
- data/lib/leaflet/debug/tests/svg_clicks.html +55 -0
- data/lib/leaflet/debug/vector/bounds-extend.html +89 -0
- data/lib/leaflet/debug/vector/feature-group-bounds.html +91 -0
- data/lib/leaflet/debug/vector/geojson-sample.js +53 -0
- data/lib/leaflet/debug/vector/geojson.html +174 -0
- data/lib/leaflet/debug/vector/rectangle.html +54 -0
- data/lib/leaflet/debug/vector/route.js +1 -0
- data/lib/leaflet/debug/vector/touchzoomemu.html +195 -0
- data/lib/leaflet/debug/vector/us-states.js +54 -0
- data/lib/leaflet/debug/vector/vector-bounds.html +70 -0
- data/lib/leaflet/debug/vector/vector-canvas.html +93 -0
- data/lib/leaflet/debug/vector/vector-mobile.html +39 -0
- data/lib/leaflet/debug/vector/vector-simple.html +49 -0
- data/lib/leaflet/debug/vector/vector.html +38 -0
- data/lib/leaflet/dist/images/layers.png +0 -0
- data/lib/leaflet/dist/images/marker-icon-2x.png +0 -0
- data/lib/leaflet/dist/images/marker-icon.png +0 -0
- data/lib/leaflet/dist/images/marker-shadow.png +0 -0
- data/lib/leaflet/dist/leaflet-src.js +8579 -0
- data/lib/leaflet/dist/leaflet.css +459 -0
- data/lib/leaflet/dist/leaflet.ie.css +51 -0
- data/lib/leaflet/dist/leaflet.js +8 -0
- data/lib/leaflet/package.json +22 -0
- data/lib/leaflet/spec/after.js +2 -0
- data/lib/leaflet/spec/before.js +3 -0
- data/lib/leaflet/spec/expect.js +1253 -0
- data/lib/leaflet/spec/happen.js +93 -0
- data/lib/leaflet/spec/index.html +78 -0
- data/lib/leaflet/spec/karma.conf.js +64 -0
- data/lib/leaflet/spec/sinon.js +4223 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +13 -0
- data/lib/leaflet/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet/spec/suites/control/Control.AttributionSpec.js +68 -0
- data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +67 -0
- data/lib/leaflet/spec/suites/control/Control.ScaleSpec.js +6 -0
- data/lib/leaflet/spec/suites/core/ClassSpec.js +156 -0
- data/lib/leaflet/spec/suites/core/EventsSpec.js +336 -0
- data/lib/leaflet/spec/suites/core/UtilSpec.js +212 -0
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +89 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +136 -0
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +118 -0
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +47 -0
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +87 -0
- data/lib/leaflet/spec/suites/geometry/LineUtilSpec.js +75 -0
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +104 -0
- data/lib/leaflet/spec/suites/geometry/PolyUtilSpec.js +27 -0
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +31 -0
- data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +36 -0
- data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +86 -0
- data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +58 -0
- data/lib/leaflet/spec/suites/layer/PopupSpec.js +59 -0
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +87 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +53 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleSpec.js +17 -0
- data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +55 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +55 -0
- data/lib/leaflet/spec/suites/map/MapSpec.js +244 -0
- data/lib/leaflet/src/Leaflet.js +23 -0
- data/lib/leaflet/src/control/Control.Attribution.js +115 -0
- data/lib/leaflet/src/control/Control.Layers.js +243 -0
- data/lib/leaflet/src/control/Control.Scale.js +112 -0
- data/lib/leaflet/src/control/Control.Zoom.js +86 -0
- data/lib/leaflet/src/control/Control.js +107 -0
- data/lib/leaflet/src/copyright.js +4 -0
- data/lib/leaflet/src/core/Browser.js +96 -0
- data/lib/leaflet/src/core/Class.js +106 -0
- data/lib/leaflet/src/core/Events.js +174 -0
- data/lib/leaflet/src/core/Handler.js +28 -0
- data/lib/leaflet/src/core/Util.js +182 -0
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +103 -0
- data/lib/leaflet/src/dom/DomEvent.MsTouch.js +146 -0
- data/lib/leaflet/src/dom/DomEvent.js +211 -0
- data/lib/leaflet/src/dom/DomUtil.js +239 -0
- data/lib/leaflet/src/dom/Draggable.js +198 -0
- data/lib/leaflet/src/dom/PosAnimation.Timer.js +67 -0
- data/lib/leaflet/src/dom/PosAnimation.js +83 -0
- data/lib/leaflet/src/geo/LatLng.js +88 -0
- data/lib/leaflet/src/geo/LatLngBounds.js +153 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +14 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +21 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +10 -0
- data/lib/leaflet/src/geo/crs/CRS.Simple.js +12 -0
- data/lib/leaflet/src/geo/crs/CRS.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.LonLat.js +13 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +56 -0
- data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.js +5 -0
- data/lib/leaflet/src/geometry/Bounds.js +95 -0
- data/lib/leaflet/src/geometry/LineUtil.js +202 -0
- data/lib/leaflet/src/geometry/Point.js +119 -0
- data/lib/leaflet/src/geometry/PolyUtil.js +55 -0
- data/lib/leaflet/src/geometry/Transformation.js +31 -0
- data/lib/leaflet/src/images/marker.svg +1 -0
- data/lib/leaflet/src/layer/FeatureGroup.js +81 -0
- data/lib/leaflet/src/layer/GeoJSON.js +245 -0
- data/lib/leaflet/src/layer/ImageOverlay.js +132 -0
- data/lib/leaflet/src/layer/LayerGroup.js +110 -0
- data/lib/leaflet/src/layer/Popup.js +316 -0
- data/lib/leaflet/src/layer/marker/DivIcon.js +43 -0
- data/lib/leaflet/src/layer/marker/Icon.Default.js +51 -0
- data/lib/leaflet/src/layer/marker/Icon.js +101 -0
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +66 -0
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +72 -0
- data/lib/leaflet/src/layer/marker/Marker.js +275 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +117 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +60 -0
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +83 -0
- data/lib/leaflet/src/layer/tile/TileLayer.js +578 -0
- data/lib/leaflet/src/layer/vector/Circle.js +98 -0
- data/lib/leaflet/src/layer/vector/CircleMarker.js +33 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +47 -0
- data/lib/leaflet/src/layer/vector/Path.Popup.js +65 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +219 -0
- data/lib/leaflet/src/layer/vector/Path.VML.js +125 -0
- data/lib/leaflet/src/layer/vector/Path.js +115 -0
- data/lib/leaflet/src/layer/vector/Polygon.js +81 -0
- data/lib/leaflet/src/layer/vector/Polyline.js +164 -0
- data/lib/leaflet/src/layer/vector/Rectangle.js +27 -0
- data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +196 -0
- data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +37 -0
- data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +30 -0
- data/lib/leaflet/src/map/Map.js +743 -0
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +88 -0
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +90 -0
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +91 -0
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +104 -0
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +23 -0
- data/lib/leaflet/src/map/handler/Map.Drag.js +146 -0
- data/lib/leaflet/src/map/handler/Map.Keyboard.js +147 -0
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +56 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +121 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/marker-icon-2x.png +0 -0
- data/vendor/assets/images/marker-icon.png +0 -0
- data/vendor/assets/images/marker-shadow.png +0 -0
- data/vendor/assets/images/spritesheet.png +0 -0
- data/vendor/assets/javascripts/leaflet.draw.js +39 -0
- data/vendor/assets/javascripts/leaflet.js +145 -0
- data/vendor/assets/javascripts/leaflet.label.js +9 -0
- data/vendor/assets/stylesheets/leaflet.css.erb +459 -0
- data/vendor/assets/stylesheets/leaflet.draw.css.erb +212 -0
- data/vendor/assets/stylesheets/leaflet.draw.ie.css +44 -0
- data/vendor/assets/stylesheets/leaflet.ie.css +51 -0
- data/vendor/assets/stylesheets/leaflet.label.css +33 -0
- metadata +317 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
/*
|
2
|
+
* Extends L.Map to handle panning animations.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Map.include({
|
6
|
+
|
7
|
+
setView: function (center, zoom, forceReset) {
|
8
|
+
|
9
|
+
zoom = this._limitZoom(zoom);
|
10
|
+
center = L.latLng(center);
|
11
|
+
|
12
|
+
if (this._panAnim) {
|
13
|
+
this._panAnim.stop();
|
14
|
+
}
|
15
|
+
|
16
|
+
var zoomChanged = (this._zoom !== zoom),
|
17
|
+
canBeAnimated = this._loaded && !forceReset && !!this._layers;
|
18
|
+
|
19
|
+
if (canBeAnimated) {
|
20
|
+
|
21
|
+
// try animating pan or zoom
|
22
|
+
var animated = zoomChanged ?
|
23
|
+
this.options.zoomAnimation && this._animateZoomIfClose && this._animateZoomIfClose(center, zoom) :
|
24
|
+
this._animatePanIfClose(center);
|
25
|
+
|
26
|
+
if (animated) {
|
27
|
+
// prevent resize handler call, the view will refresh after animation anyway
|
28
|
+
clearTimeout(this._sizeTimer);
|
29
|
+
return this;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
// animation didn't start, just reset the map view
|
34
|
+
this._resetView(center, zoom);
|
35
|
+
|
36
|
+
return this;
|
37
|
+
},
|
38
|
+
|
39
|
+
panBy: function (offset, duration, easeLinearity, noMoveStart) {
|
40
|
+
offset = L.point(offset).round();
|
41
|
+
|
42
|
+
// TODO add options instead of arguments to setView/panTo/panBy/etc.
|
43
|
+
|
44
|
+
if (!offset.x && !offset.y) {
|
45
|
+
return this;
|
46
|
+
}
|
47
|
+
|
48
|
+
if (!this._panAnim) {
|
49
|
+
this._panAnim = new L.PosAnimation();
|
50
|
+
|
51
|
+
this._panAnim.on({
|
52
|
+
'step': this._onPanTransitionStep,
|
53
|
+
'end': this._onPanTransitionEnd
|
54
|
+
}, this);
|
55
|
+
}
|
56
|
+
|
57
|
+
// don't fire movestart if animating inertia
|
58
|
+
if (!noMoveStart) {
|
59
|
+
this.fire('movestart');
|
60
|
+
}
|
61
|
+
|
62
|
+
L.DomUtil.addClass(this._mapPane, 'leaflet-pan-anim');
|
63
|
+
|
64
|
+
var newPos = this._getMapPanePos().subtract(offset);
|
65
|
+
this._panAnim.run(this._mapPane, newPos, duration || 0.25, easeLinearity);
|
66
|
+
|
67
|
+
return this;
|
68
|
+
},
|
69
|
+
|
70
|
+
_onPanTransitionStep: function () {
|
71
|
+
this.fire('move');
|
72
|
+
},
|
73
|
+
|
74
|
+
_onPanTransitionEnd: function () {
|
75
|
+
L.DomUtil.removeClass(this._mapPane, 'leaflet-pan-anim');
|
76
|
+
this.fire('moveend');
|
77
|
+
},
|
78
|
+
|
79
|
+
_animatePanIfClose: function (center) {
|
80
|
+
// difference between the new and current centers in pixels
|
81
|
+
var offset = this._getCenterOffset(center)._floor();
|
82
|
+
|
83
|
+
if (!this.getSize().contains(offset)) { return false; }
|
84
|
+
|
85
|
+
this.panBy(offset);
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
});
|
@@ -0,0 +1,90 @@
|
|
1
|
+
/*
|
2
|
+
* Extends L.Map to handle zoom animations.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Map.mergeOptions({
|
6
|
+
zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android23 && !L.Browser.mobileOpera,
|
7
|
+
zoomAnimationThreshold: 4
|
8
|
+
});
|
9
|
+
|
10
|
+
if (L.DomUtil.TRANSITION) {
|
11
|
+
|
12
|
+
L.Map.addInitHook(function () {
|
13
|
+
// zoom transitions run with the same duration for all layers, so if one of transitionend events
|
14
|
+
// happens after starting zoom animation (propagating to the map pane), we know that it ended globally
|
15
|
+
|
16
|
+
L.DomEvent.on(this._mapPane, L.DomUtil.TRANSITION_END, this._catchTransitionEnd, this);
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
21
|
+
|
22
|
+
_catchTransitionEnd: function () {
|
23
|
+
if (this._animatingZoom) {
|
24
|
+
this._onZoomTransitionEnd();
|
25
|
+
}
|
26
|
+
},
|
27
|
+
|
28
|
+
_animateZoomIfClose: function (center, zoom) {
|
29
|
+
|
30
|
+
if (this._animatingZoom) { return true; }
|
31
|
+
|
32
|
+
// don't animate if zoom difference is too large
|
33
|
+
if (Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { return false; }
|
34
|
+
|
35
|
+
// offset is the pixel coords of the zoom origin relative to the current center
|
36
|
+
var scale = this.getZoomScale(zoom),
|
37
|
+
offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale),
|
38
|
+
origin = this._getCenterLayerPoint()._add(offset);
|
39
|
+
|
40
|
+
// only animate if the zoom origin is within one screen from the current center
|
41
|
+
if (!this.getSize().contains(offset)) { return false; }
|
42
|
+
|
43
|
+
this
|
44
|
+
.fire('movestart')
|
45
|
+
.fire('zoomstart');
|
46
|
+
|
47
|
+
this._animateZoom(center, zoom, origin, scale);
|
48
|
+
|
49
|
+
return true;
|
50
|
+
},
|
51
|
+
|
52
|
+
_animateZoom: function (center, zoom, origin, scale, delta, backwards) {
|
53
|
+
|
54
|
+
this._animatingZoom = true;
|
55
|
+
|
56
|
+
// put transform transition on all layers with leaflet-zoom-animated class
|
57
|
+
L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
|
58
|
+
|
59
|
+
// remember what center/zoom to set after animation
|
60
|
+
this._animateToCenter = center;
|
61
|
+
this._animateToZoom = zoom;
|
62
|
+
|
63
|
+
// disable any dragging during animation
|
64
|
+
if (L.Draggable) {
|
65
|
+
L.Draggable._disabled = true;
|
66
|
+
}
|
67
|
+
|
68
|
+
this.fire('zoomanim', {
|
69
|
+
center: center,
|
70
|
+
zoom: zoom,
|
71
|
+
origin: origin,
|
72
|
+
scale: scale,
|
73
|
+
delta: delta,
|
74
|
+
backwards: backwards
|
75
|
+
});
|
76
|
+
},
|
77
|
+
|
78
|
+
_onZoomTransitionEnd: function () {
|
79
|
+
|
80
|
+
this._animatingZoom = false;
|
81
|
+
|
82
|
+
L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim');
|
83
|
+
|
84
|
+
this._resetView(this._animateToCenter, this._animateToZoom, true, true);
|
85
|
+
|
86
|
+
if (L.Draggable) {
|
87
|
+
L.Draggable._disabled = false;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
});
|
@@ -0,0 +1,91 @@
|
|
1
|
+
/*
|
2
|
+
* Provides L.Map with convenient shortcuts for using browser geolocation features.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Map.include({
|
6
|
+
_defaultLocateOptions: {
|
7
|
+
watch: false,
|
8
|
+
setView: false,
|
9
|
+
maxZoom: Infinity,
|
10
|
+
timeout: 10000,
|
11
|
+
maximumAge: 0,
|
12
|
+
enableHighAccuracy: false
|
13
|
+
},
|
14
|
+
|
15
|
+
locate: function (/*Object*/ options) {
|
16
|
+
|
17
|
+
options = this._locateOptions = L.extend(this._defaultLocateOptions, options);
|
18
|
+
|
19
|
+
if (!navigator.geolocation) {
|
20
|
+
this._handleGeolocationError({
|
21
|
+
code: 0,
|
22
|
+
message: 'Geolocation not supported.'
|
23
|
+
});
|
24
|
+
return this;
|
25
|
+
}
|
26
|
+
|
27
|
+
var onResponse = L.bind(this._handleGeolocationResponse, this),
|
28
|
+
onError = L.bind(this._handleGeolocationError, this);
|
29
|
+
|
30
|
+
if (options.watch) {
|
31
|
+
this._locationWatchId =
|
32
|
+
navigator.geolocation.watchPosition(onResponse, onError, options);
|
33
|
+
} else {
|
34
|
+
navigator.geolocation.getCurrentPosition(onResponse, onError, options);
|
35
|
+
}
|
36
|
+
return this;
|
37
|
+
},
|
38
|
+
|
39
|
+
stopLocate: function () {
|
40
|
+
if (navigator.geolocation) {
|
41
|
+
navigator.geolocation.clearWatch(this._locationWatchId);
|
42
|
+
}
|
43
|
+
if (this._locateOptions) {
|
44
|
+
this._locateOptions.setView = false;
|
45
|
+
}
|
46
|
+
return this;
|
47
|
+
},
|
48
|
+
|
49
|
+
_handleGeolocationError: function (error) {
|
50
|
+
var c = error.code,
|
51
|
+
message = error.message ||
|
52
|
+
(c === 1 ? 'permission denied' :
|
53
|
+
(c === 2 ? 'position unavailable' : 'timeout'));
|
54
|
+
|
55
|
+
if (this._locateOptions.setView && !this._loaded) {
|
56
|
+
this.fitWorld();
|
57
|
+
}
|
58
|
+
|
59
|
+
this.fire('locationerror', {
|
60
|
+
code: c,
|
61
|
+
message: 'Geolocation error: ' + message + '.'
|
62
|
+
});
|
63
|
+
},
|
64
|
+
|
65
|
+
_handleGeolocationResponse: function (pos) {
|
66
|
+
var lat = pos.coords.latitude,
|
67
|
+
lng = pos.coords.longitude,
|
68
|
+
latlng = new L.LatLng(lat, lng),
|
69
|
+
|
70
|
+
latAccuracy = 180 * pos.coords.accuracy / 40075017,
|
71
|
+
lngAccuracy = latAccuracy / Math.cos(L.LatLng.DEG_TO_RAD * lat),
|
72
|
+
|
73
|
+
bounds = L.latLngBounds(
|
74
|
+
[lat - latAccuracy, lng - lngAccuracy],
|
75
|
+
[lat + latAccuracy, lng + lngAccuracy]),
|
76
|
+
|
77
|
+
options = this._locateOptions;
|
78
|
+
|
79
|
+
if (options.setView) {
|
80
|
+
var zoom = Math.min(this.getBoundsZoom(bounds), options.maxZoom);
|
81
|
+
this.setView(latlng, zoom);
|
82
|
+
}
|
83
|
+
|
84
|
+
var event = L.extend({
|
85
|
+
latlng: latlng,
|
86
|
+
bounds: bounds
|
87
|
+
}, pos.coords);
|
88
|
+
|
89
|
+
this.fire('locationfound', event);
|
90
|
+
}
|
91
|
+
});
|
@@ -0,0 +1,104 @@
|
|
1
|
+
/*
|
2
|
+
* L.Handler.ShiftDragZoom is used to add shift-drag zoom interaction to the map
|
3
|
+
* (zoom to a selected bounding box), enabled by default.
|
4
|
+
*/
|
5
|
+
|
6
|
+
L.Map.mergeOptions({
|
7
|
+
boxZoom: true
|
8
|
+
});
|
9
|
+
|
10
|
+
L.Map.BoxZoom = L.Handler.extend({
|
11
|
+
initialize: function (map) {
|
12
|
+
this._map = map;
|
13
|
+
this._container = map._container;
|
14
|
+
this._pane = map._panes.overlayPane;
|
15
|
+
},
|
16
|
+
|
17
|
+
addHooks: function () {
|
18
|
+
L.DomEvent.on(this._container, 'mousedown', this._onMouseDown, this);
|
19
|
+
},
|
20
|
+
|
21
|
+
removeHooks: function () {
|
22
|
+
L.DomEvent.off(this._container, 'mousedown', this._onMouseDown);
|
23
|
+
},
|
24
|
+
|
25
|
+
_onMouseDown: function (e) {
|
26
|
+
if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; }
|
27
|
+
|
28
|
+
L.DomUtil.disableTextSelection();
|
29
|
+
|
30
|
+
this._startLayerPoint = this._map.mouseEventToLayerPoint(e);
|
31
|
+
|
32
|
+
this._box = L.DomUtil.create('div', 'leaflet-zoom-box', this._pane);
|
33
|
+
L.DomUtil.setPosition(this._box, this._startLayerPoint);
|
34
|
+
|
35
|
+
//TODO refactor: move cursor to styles
|
36
|
+
this._container.style.cursor = 'crosshair';
|
37
|
+
|
38
|
+
L.DomEvent
|
39
|
+
.on(document, 'mousemove', this._onMouseMove, this)
|
40
|
+
.on(document, 'mouseup', this._onMouseUp, this)
|
41
|
+
.on(document, 'keydown', this._onKeyDown, this)
|
42
|
+
.preventDefault(e);
|
43
|
+
|
44
|
+
this._map.fire('boxzoomstart');
|
45
|
+
},
|
46
|
+
|
47
|
+
_onMouseMove: function (e) {
|
48
|
+
var startPoint = this._startLayerPoint,
|
49
|
+
box = this._box,
|
50
|
+
|
51
|
+
layerPoint = this._map.mouseEventToLayerPoint(e),
|
52
|
+
offset = layerPoint.subtract(startPoint),
|
53
|
+
|
54
|
+
newPos = new L.Point(
|
55
|
+
Math.min(layerPoint.x, startPoint.x),
|
56
|
+
Math.min(layerPoint.y, startPoint.y));
|
57
|
+
|
58
|
+
L.DomUtil.setPosition(box, newPos);
|
59
|
+
|
60
|
+
// TODO refactor: remove hardcoded 4 pixels
|
61
|
+
box.style.width = (Math.max(0, Math.abs(offset.x) - 4)) + 'px';
|
62
|
+
box.style.height = (Math.max(0, Math.abs(offset.y) - 4)) + 'px';
|
63
|
+
},
|
64
|
+
|
65
|
+
_finish: function () {
|
66
|
+
this._pane.removeChild(this._box);
|
67
|
+
this._container.style.cursor = '';
|
68
|
+
|
69
|
+
L.DomUtil.enableTextSelection();
|
70
|
+
|
71
|
+
L.DomEvent
|
72
|
+
.off(document, 'mousemove', this._onMouseMove)
|
73
|
+
.off(document, 'mouseup', this._onMouseUp)
|
74
|
+
.off(document, 'keydown', this._onKeyDown);
|
75
|
+
},
|
76
|
+
|
77
|
+
_onMouseUp: function (e) {
|
78
|
+
|
79
|
+
this._finish();
|
80
|
+
|
81
|
+
var map = this._map,
|
82
|
+
layerPoint = map.mouseEventToLayerPoint(e);
|
83
|
+
|
84
|
+
if (this._startLayerPoint.equals(layerPoint)) { return; }
|
85
|
+
|
86
|
+
var bounds = new L.LatLngBounds(
|
87
|
+
map.layerPointToLatLng(this._startLayerPoint),
|
88
|
+
map.layerPointToLatLng(layerPoint));
|
89
|
+
|
90
|
+
map.fitBounds(bounds);
|
91
|
+
|
92
|
+
map.fire('boxzoomend', {
|
93
|
+
boxZoomBounds: bounds
|
94
|
+
});
|
95
|
+
},
|
96
|
+
|
97
|
+
_onKeyDown: function (e) {
|
98
|
+
if (e.keyCode === 27) {
|
99
|
+
this._finish();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
});
|
103
|
+
|
104
|
+
L.Map.addInitHook('addHandler', 'boxZoom', L.Map.BoxZoom);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
* L.Handler.DoubleClickZoom is used to handle double-click zoom on the map, enabled by default.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Map.mergeOptions({
|
6
|
+
doubleClickZoom: true
|
7
|
+
});
|
8
|
+
|
9
|
+
L.Map.DoubleClickZoom = L.Handler.extend({
|
10
|
+
addHooks: function () {
|
11
|
+
this._map.on('dblclick', this._onDoubleClick);
|
12
|
+
},
|
13
|
+
|
14
|
+
removeHooks: function () {
|
15
|
+
this._map.off('dblclick', this._onDoubleClick);
|
16
|
+
},
|
17
|
+
|
18
|
+
_onDoubleClick: function (e) {
|
19
|
+
this.setZoomAround(e.containerPoint, this._zoom + 1);
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
L.Map.addInitHook('addHandler', 'doubleClickZoom', L.Map.DoubleClickZoom);
|
@@ -0,0 +1,146 @@
|
|
1
|
+
/*
|
2
|
+
* L.Handler.MapDrag is used to make the map draggable (with panning inertia), enabled by default.
|
3
|
+
*/
|
4
|
+
|
5
|
+
L.Map.mergeOptions({
|
6
|
+
dragging: true,
|
7
|
+
|
8
|
+
inertia: !L.Browser.android23,
|
9
|
+
inertiaDeceleration: 3400, // px/s^2
|
10
|
+
inertiaMaxSpeed: Infinity, // px/s
|
11
|
+
inertiaThreshold: L.Browser.touch ? 32 : 18, // ms
|
12
|
+
easeLinearity: 0.25,
|
13
|
+
|
14
|
+
longPress: true,
|
15
|
+
|
16
|
+
// TODO refactor, move to CRS
|
17
|
+
worldCopyJump: false
|
18
|
+
});
|
19
|
+
|
20
|
+
L.Map.Drag = L.Handler.extend({
|
21
|
+
addHooks: function () {
|
22
|
+
if (!this._draggable) {
|
23
|
+
var map = this._map;
|
24
|
+
|
25
|
+
this._draggable = new L.Draggable(map._mapPane, map._container, map.options.longPress);
|
26
|
+
|
27
|
+
this._draggable.on({
|
28
|
+
'dragstart': this._onDragStart,
|
29
|
+
'drag': this._onDrag,
|
30
|
+
'dragend': this._onDragEnd
|
31
|
+
}, this);
|
32
|
+
|
33
|
+
if (map.options.worldCopyJump) {
|
34
|
+
this._draggable.on('predrag', this._onPreDrag, this);
|
35
|
+
map.on('viewreset', this._onViewReset, this);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
this._draggable.enable();
|
39
|
+
},
|
40
|
+
|
41
|
+
removeHooks: function () {
|
42
|
+
this._draggable.disable();
|
43
|
+
},
|
44
|
+
|
45
|
+
moved: function () {
|
46
|
+
return this._draggable && this._draggable._moved;
|
47
|
+
},
|
48
|
+
|
49
|
+
_onDragStart: function () {
|
50
|
+
var map = this._map;
|
51
|
+
|
52
|
+
if (map._panAnim) {
|
53
|
+
map._panAnim.stop();
|
54
|
+
}
|
55
|
+
|
56
|
+
map
|
57
|
+
.fire('movestart')
|
58
|
+
.fire('dragstart');
|
59
|
+
|
60
|
+
if (map.options.inertia) {
|
61
|
+
this._positions = [];
|
62
|
+
this._times = [];
|
63
|
+
}
|
64
|
+
},
|
65
|
+
|
66
|
+
_onDrag: function () {
|
67
|
+
if (this._map.options.inertia) {
|
68
|
+
var time = this._lastTime = +new Date(),
|
69
|
+
pos = this._lastPos = this._draggable._newPos;
|
70
|
+
|
71
|
+
this._positions.push(pos);
|
72
|
+
this._times.push(time);
|
73
|
+
|
74
|
+
if (time - this._times[0] > 200) {
|
75
|
+
this._positions.shift();
|
76
|
+
this._times.shift();
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
this._map
|
81
|
+
.fire('move')
|
82
|
+
.fire('drag');
|
83
|
+
},
|
84
|
+
|
85
|
+
_onViewReset: function () {
|
86
|
+
// TODO fix hardcoded Earth values
|
87
|
+
var pxCenter = this._map.getSize()._divideBy(2),
|
88
|
+
pxWorldCenter = this._map.latLngToLayerPoint([0, 0]);
|
89
|
+
|
90
|
+
this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x;
|
91
|
+
this._worldWidth = this._map.project([0, 180]).x;
|
92
|
+
},
|
93
|
+
|
94
|
+
_onPreDrag: function () {
|
95
|
+
// TODO refactor to be able to adjust map pane position after zoom
|
96
|
+
var worldWidth = this._worldWidth,
|
97
|
+
halfWidth = Math.round(worldWidth / 2),
|
98
|
+
dx = this._initialWorldOffset,
|
99
|
+
x = this._draggable._newPos.x,
|
100
|
+
newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx,
|
101
|
+
newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx,
|
102
|
+
newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2;
|
103
|
+
|
104
|
+
this._draggable._newPos.x = newX;
|
105
|
+
},
|
106
|
+
|
107
|
+
_onDragEnd: function () {
|
108
|
+
var map = this._map,
|
109
|
+
options = map.options,
|
110
|
+
delay = +new Date() - this._lastTime,
|
111
|
+
|
112
|
+
noInertia = !options.inertia || delay > options.inertiaThreshold || !this._positions[0];
|
113
|
+
|
114
|
+
map.fire('dragend');
|
115
|
+
|
116
|
+
if (noInertia) {
|
117
|
+
map.fire('moveend');
|
118
|
+
|
119
|
+
} else {
|
120
|
+
|
121
|
+
var direction = this._lastPos.subtract(this._positions[0]),
|
122
|
+
duration = (this._lastTime + delay - this._times[0]) / 1000,
|
123
|
+
ease = options.easeLinearity,
|
124
|
+
|
125
|
+
speedVector = direction.multiplyBy(ease / duration),
|
126
|
+
speed = speedVector.distanceTo([0, 0]),
|
127
|
+
|
128
|
+
limitedSpeed = Math.min(options.inertiaMaxSpeed, speed),
|
129
|
+
limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed),
|
130
|
+
|
131
|
+
decelerationDuration = limitedSpeed / (options.inertiaDeceleration * ease),
|
132
|
+
offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round();
|
133
|
+
|
134
|
+
if (!offset.x || !offset.y) {
|
135
|
+
map.fire('moveend');
|
136
|
+
|
137
|
+
} else {
|
138
|
+
L.Util.requestAnimFrame(function () {
|
139
|
+
map.panBy(offset, decelerationDuration, ease, true);
|
140
|
+
});
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
});
|
145
|
+
|
146
|
+
L.Map.addInitHook('addHandler', 'dragging', L.Map.Drag);
|