leaflet-ruby 0.3.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGELOG.rdoc +5 -0
  2. data/LICENSE +21 -0
  3. data/README.rdoc +55 -0
  4. data/Rakefile +15 -0
  5. data/leaflet-ruby.gemspec +24 -0
  6. data/lib/leaflet-ruby.rb +18 -0
  7. data/lib/leaflet/CHANGELOG.md +181 -0
  8. data/lib/leaflet/Jakefile.js +65 -0
  9. data/lib/leaflet/LICENSE +22 -0
  10. data/lib/leaflet/README.md +32 -0
  11. data/lib/leaflet/build/build.html +243 -0
  12. data/lib/leaflet/build/build.js +79 -0
  13. data/lib/leaflet/build/deps.js +231 -0
  14. data/lib/leaflet/build/hint.js +30 -0
  15. data/lib/leaflet/build/hintrc.js +44 -0
  16. data/lib/leaflet/debug/control/control-layers.html +47 -0
  17. data/lib/leaflet/debug/control/map-control.html +29 -0
  18. data/lib/leaflet/debug/css/mobile.css +6 -0
  19. data/lib/leaflet/debug/css/screen.css +5 -0
  20. data/lib/leaflet/debug/geojson/geojson-sample.js +53 -0
  21. data/lib/leaflet/debug/geojson/geojson.html +56 -0
  22. data/lib/leaflet/debug/leaflet-include.js +120 -0
  23. data/lib/leaflet/debug/map/canvas.html +46 -0
  24. data/lib/leaflet/debug/map/map-mobile.html +42 -0
  25. data/lib/leaflet/debug/map/map.html +54 -0
  26. data/lib/leaflet/debug/map/max-bounds.html +36 -0
  27. data/lib/leaflet/debug/map/scroll.html +35 -0
  28. data/lib/leaflet/debug/map/wms-marble.html +30 -0
  29. data/lib/leaflet/debug/map/wms.html +37 -0
  30. data/lib/leaflet/debug/vector/editable.html +43 -0
  31. data/lib/leaflet/debug/vector/route.js +1 -0
  32. data/lib/leaflet/debug/vector/vector-bounds.html +69 -0
  33. data/lib/leaflet/debug/vector/vector-canvas.html +92 -0
  34. data/lib/leaflet/debug/vector/vector-mobile.html +38 -0
  35. data/lib/leaflet/debug/vector/vector-simple.html +63 -0
  36. data/lib/leaflet/debug/vector/vector.html +38 -0
  37. data/lib/leaflet/dist/images/layers.png +0 -0
  38. data/lib/leaflet/dist/images/marker-shadow.png +0 -0
  39. data/lib/leaflet/dist/images/marker.png +0 -0
  40. data/lib/leaflet/dist/images/popup-close.png +0 -0
  41. data/lib/leaflet/dist/images/zoom-in.png +0 -0
  42. data/lib/leaflet/dist/images/zoom-out.png +0 -0
  43. data/lib/leaflet/dist/leaflet-src.js +5537 -0
  44. data/lib/leaflet/dist/leaflet.css +323 -0
  45. data/lib/leaflet/dist/leaflet.ie.css +48 -0
  46. data/lib/leaflet/dist/leaflet.js +6 -0
  47. data/lib/leaflet/lib/jasmine/jasmine-html.js +182 -0
  48. data/lib/leaflet/lib/jasmine/jasmine.css +166 -0
  49. data/lib/leaflet/lib/jasmine/jasmine.js +2421 -0
  50. data/lib/leaflet/spec/runner.html +57 -0
  51. data/lib/leaflet/spec/suites/LeafletSpec.js +15 -0
  52. data/lib/leaflet/spec/suites/SpecHelper.js +28 -0
  53. data/lib/leaflet/spec/suites/core/ClassSpec.js +153 -0
  54. data/lib/leaflet/spec/suites/core/EventsSpec.js +110 -0
  55. data/lib/leaflet/spec/suites/core/UtilSpec.js +63 -0
  56. data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
  57. data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +59 -0
  58. data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +1 -0
  59. data/lib/leaflet/spec/suites/geo/LatLngSpec.js +76 -0
  60. data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +42 -0
  61. data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +53 -0
  62. data/lib/leaflet/spec/suites/geometry/PointSpec.js +45 -0
  63. data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +19 -0
  64. data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +1 -0
  65. data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
  66. data/lib/leaflet/spec/suites/map/MapSpec.js +1 -0
  67. data/lib/leaflet/src/Leaflet.js +33 -0
  68. data/lib/leaflet/src/control/Control.Attribution.js +66 -0
  69. data/lib/leaflet/src/control/Control.Layers.js +167 -0
  70. data/lib/leaflet/src/control/Control.Zoom.js +36 -0
  71. data/lib/leaflet/src/control/Control.js +9 -0
  72. data/lib/leaflet/src/core/Browser.js +53 -0
  73. data/lib/leaflet/src/core/Class.js +66 -0
  74. data/lib/leaflet/src/core/Events.js +62 -0
  75. data/lib/leaflet/src/core/Handler.js +29 -0
  76. data/lib/leaflet/src/core/Util.js +108 -0
  77. data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +43 -0
  78. data/lib/leaflet/src/dom/DomEvent.js +154 -0
  79. data/lib/leaflet/src/dom/DomUtil.js +155 -0
  80. data/lib/leaflet/src/dom/Draggable.js +147 -0
  81. data/lib/leaflet/src/dom/transition/Transition.Native.js +102 -0
  82. data/lib/leaflet/src/dom/transition/Transition.Timer.js +126 -0
  83. data/lib/leaflet/src/dom/transition/Transition.js +28 -0
  84. data/lib/leaflet/src/geo/LatLng.js +44 -0
  85. data/lib/leaflet/src/geo/LatLngBounds.js +86 -0
  86. data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +13 -0
  87. data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +17 -0
  88. data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +7 -0
  89. data/lib/leaflet/src/geo/crs/CRS.js +17 -0
  90. data/lib/leaflet/src/geo/projection/Projection.LonLat.js +10 -0
  91. data/lib/leaflet/src/geo/projection/Projection.Mercator.js +51 -0
  92. data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +23 -0
  93. data/lib/leaflet/src/geo/projection/Projection.js +5 -0
  94. data/lib/leaflet/src/geometry/Bounds.js +50 -0
  95. data/lib/leaflet/src/geometry/LineUtil.js +194 -0
  96. data/lib/leaflet/src/geometry/Point.js +66 -0
  97. data/lib/leaflet/src/geometry/PolyUtil.js +59 -0
  98. data/lib/leaflet/src/geometry/Transformation.js +31 -0
  99. data/lib/leaflet/src/layer/FeatureGroup.js +40 -0
  100. data/lib/leaflet/src/layer/GeoJSON.js +104 -0
  101. data/lib/leaflet/src/layer/ImageOverlay.js +58 -0
  102. data/lib/leaflet/src/layer/LayerGroup.js +74 -0
  103. data/lib/leaflet/src/layer/Popup.js +179 -0
  104. data/lib/leaflet/src/layer/marker/Icon.js +58 -0
  105. data/lib/leaflet/src/layer/marker/Marker.Drag.js +57 -0
  106. data/lib/leaflet/src/layer/marker/Marker.Popup.js +42 -0
  107. data/lib/leaflet/src/layer/marker/Marker.js +142 -0
  108. data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +41 -0
  109. data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +47 -0
  110. data/lib/leaflet/src/layer/tile/TileLayer.js +310 -0
  111. data/lib/leaflet/src/layer/vector/Circle.js +68 -0
  112. data/lib/leaflet/src/layer/vector/CircleMarker.js +25 -0
  113. data/lib/leaflet/src/layer/vector/MultiPoly.js +34 -0
  114. data/lib/leaflet/src/layer/vector/Path.Popup.js +24 -0
  115. data/lib/leaflet/src/layer/vector/Path.SVG.js +138 -0
  116. data/lib/leaflet/src/layer/vector/Path.VML.js +93 -0
  117. data/lib/leaflet/src/layer/vector/Path.js +88 -0
  118. data/lib/leaflet/src/layer/vector/Polygon.js +64 -0
  119. data/lib/leaflet/src/layer/vector/Polyline.js +146 -0
  120. data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
  121. data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +146 -0
  122. data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +34 -0
  123. data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +27 -0
  124. data/lib/leaflet/src/map/Map.js +613 -0
  125. data/lib/leaflet/src/map/anim/Map.PanAnimation.js +70 -0
  126. data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +133 -0
  127. data/lib/leaflet/src/map/ext/Map.Control.js +50 -0
  128. data/lib/leaflet/src/map/ext/Map.Geolocation.js +86 -0
  129. data/lib/leaflet/src/map/ext/Map.Popup.js +20 -0
  130. data/lib/leaflet/src/map/handler/Map.BoxZoom.js +73 -0
  131. data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +18 -0
  132. data/lib/leaflet/src/map/handler/Map.Drag.js +81 -0
  133. data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +55 -0
  134. data/lib/leaflet/src/map/handler/Map.TouchZoom.js +93 -0
  135. data/lib/zerista/CRS.Cartesian.js +20 -0
  136. data/lib/zerista/Projection.Identity.js +11 -0
  137. data/lib/zerista/zerista_layer.js +97 -0
  138. data/vendor/assets/javascripts/leaflet.js +139 -0
  139. data/vendor/assets/stylesheets/leaflet.css +1 -0
  140. data/vendor/assets/stylesheets/leaflet.ie.css +1 -0
  141. metadata +185 -0
@@ -0,0 +1,70 @@
1
+ L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
2
+ setView: function (center, zoom, forceReset) {
3
+ zoom = this._limitZoom(zoom);
4
+ var zoomChanged = (this._zoom !== zoom);
5
+
6
+ if (this._loaded && !forceReset && this._layers) {
7
+ // difference between the new and current centers in pixels
8
+ var offset = this._getNewTopLeftPoint(center).subtract(this._getTopLeftPoint());
9
+
10
+ center = new L.LatLng(center.lat, center.lng);
11
+
12
+ var done = (zoomChanged ?
13
+ !!this._zoomToIfCenterInView && this._zoomToIfCenterInView(center, zoom, offset) :
14
+ this._panByIfClose(offset));
15
+
16
+ // exit if animated pan or zoom started
17
+ if (done) {
18
+ return this;
19
+ }
20
+ }
21
+
22
+ // reset the map view
23
+ this._resetView(center, zoom);
24
+
25
+ return this;
26
+ },
27
+
28
+ panBy: function (offset) {
29
+ if (!(offset.x || offset.y)) {
30
+ return this;
31
+ }
32
+
33
+ if (!this._panTransition) {
34
+ this._panTransition = new L.Transition(this._mapPane, {duration: 0.3});
35
+
36
+ this._panTransition.on('step', this._onPanTransitionStep, this);
37
+ this._panTransition.on('end', this._onPanTransitionEnd, this);
38
+ }
39
+ this.fire('movestart');
40
+
41
+ this._panTransition.run({
42
+ position: L.DomUtil.getPosition(this._mapPane).subtract(offset)
43
+ });
44
+
45
+ return this;
46
+ },
47
+
48
+ _onPanTransitionStep: function () {
49
+ this.fire('move');
50
+ },
51
+
52
+ _onPanTransitionEnd: function () {
53
+ this.fire('moveend');
54
+ },
55
+
56
+ _panByIfClose: function (offset) {
57
+ if (this._offsetIsWithinView(offset)) {
58
+ this.panBy(offset);
59
+ return true;
60
+ }
61
+ return false;
62
+ },
63
+
64
+ _offsetIsWithinView: function (offset, multiplyFactor) {
65
+ var m = multiplyFactor || 1,
66
+ size = this.getSize();
67
+ return (Math.abs(offset.x) <= size.x * m) &&
68
+ (Math.abs(offset.y) <= size.y * m);
69
+ }
70
+ });
@@ -0,0 +1,133 @@
1
+ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
2
+ _zoomToIfCenterInView: function (center, zoom, centerOffset) {
3
+
4
+ if (this._animatingZoom) {
5
+ return true;
6
+ }
7
+ if (!this.options.zoomAnimation) {
8
+ return false;
9
+ }
10
+
11
+ var zoomDelta = zoom - this._zoom,
12
+ scale = Math.pow(2, zoomDelta),
13
+ offset = centerOffset.divideBy(1 - 1 / scale);
14
+
15
+ //if offset does not exceed half of the view
16
+ if (!this._offsetIsWithinView(offset, 1)) {
17
+ return false;
18
+ }
19
+
20
+ this._mapPane.className += ' leaflet-zoom-anim';
21
+
22
+ this
23
+ .fire('movestart')
24
+ .fire('zoomstart');
25
+
26
+ var centerPoint = this.containerPointToLayerPoint(this.getSize().divideBy(2)),
27
+ origin = centerPoint.add(offset);
28
+
29
+ this._prepareTileBg();
30
+
31
+ this._runAnimation(center, zoom, scale, origin);
32
+
33
+ return true;
34
+ },
35
+
36
+
37
+ _runAnimation: function (center, zoom, scale, origin) {
38
+ this._animatingZoom = true;
39
+
40
+ this._animateToCenter = center;
41
+ this._animateToZoom = zoom;
42
+
43
+ var transform = L.DomUtil.TRANSFORM;
44
+
45
+ //dumb FireFox hack, I have no idea why this magic zero translate fixes the scale transition problem
46
+ if (L.Browser.gecko || window.opera) {
47
+ this._tileBg.style[transform] += ' translate(0,0)';
48
+ }
49
+
50
+ var scaleStr;
51
+
52
+ // Android doesn't like translate/scale chains, transformOrigin + scale works better but
53
+ // it breaks touch zoom which Anroid doesn't support anyway, so that's a really ugly hack
54
+ // TODO work around this prettier
55
+ if (L.Browser.android) {
56
+ this._tileBg.style[transform + 'Origin'] = origin.x + 'px ' + origin.y + 'px';
57
+ scaleStr = 'scale(' + scale + ')';
58
+ } else {
59
+ scaleStr = L.DomUtil.getScaleString(scale, origin);
60
+ }
61
+
62
+ L.Util.falseFn(this._tileBg.offsetWidth); //hack to make sure transform is updated before running animation
63
+
64
+ var options = {};
65
+ options[transform] = this._tileBg.style[transform] + ' ' + scaleStr;
66
+ this._tileBg.transition.run(options);
67
+ },
68
+
69
+ _prepareTileBg: function () {
70
+ if (!this._tileBg) {
71
+ this._tileBg = this._createPane('leaflet-tile-pane', this._mapPane);
72
+ this._tileBg.style.zIndex = 1;
73
+ }
74
+
75
+ var tilePane = this._tilePane,
76
+ tileBg = this._tileBg;
77
+
78
+ // prepare the background pane to become the main tile pane
79
+ //tileBg.innerHTML = '';
80
+ tileBg.style[L.DomUtil.TRANSFORM] = '';
81
+ tileBg.style.visibility = 'hidden';
82
+
83
+ // tells tile layers to reinitialize their containers
84
+ tileBg.empty = true;
85
+ tilePane.empty = false;
86
+
87
+ this._tilePane = this._panes.tilePane = tileBg;
88
+ this._tileBg = tilePane;
89
+
90
+ if (!this._tileBg.transition) {
91
+ this._tileBg.transition = new L.Transition(this._tileBg, {duration: 0.3, easing: 'cubic-bezier(0.25,0.1,0.25,0.75)'});
92
+ this._tileBg.transition.on('end', this._onZoomTransitionEnd, this);
93
+ }
94
+
95
+ this._stopLoadingBgTiles();
96
+ },
97
+
98
+ // stops loading all tiles in the background layer
99
+ _stopLoadingBgTiles: function () {
100
+ var tiles = [].slice.call(this._tileBg.getElementsByTagName('img'));
101
+
102
+ for (var i = 0, len = tiles.length; i < len; i++) {
103
+ if (!tiles[i].complete) {
104
+ // tiles[i].src = '' - evil, doesn't cancel the request!
105
+ tiles[i].parentNode.removeChild(tiles[i]);
106
+ tiles[i] = null;
107
+ }
108
+ }
109
+ },
110
+
111
+ _onZoomTransitionEnd: function () {
112
+ this._restoreTileFront();
113
+
114
+ L.Util.falseFn(this._tileBg.offsetWidth);
115
+ this._resetView(this._animateToCenter, this._animateToZoom, true, true);
116
+
117
+ this._mapPane.className = this._mapPane.className.replace(' leaflet-zoom-anim', ''); //TODO toggleClass util
118
+ this._animatingZoom = false;
119
+ },
120
+
121
+ _restoreTileFront: function () {
122
+ this._tilePane.innerHTML = '';
123
+ this._tilePane.style.visibility = '';
124
+ this._tilePane.style.zIndex = 2;
125
+ this._tileBg.style.zIndex = 1;
126
+ },
127
+
128
+ _clearTileBg: function () {
129
+ if (!this._animatingZoom && !this.touchZoom._zooming) {
130
+ this._tileBg.innerHTML = '';
131
+ }
132
+ }
133
+ });
@@ -0,0 +1,50 @@
1
+ L.Map.include({
2
+ addControl: function (control) {
3
+ control.onAdd(this);
4
+
5
+ var pos = control.getPosition(),
6
+ corner = this._controlCorners[pos],
7
+ container = control.getContainer();
8
+
9
+ L.DomUtil.addClass(container, 'leaflet-control');
10
+
11
+ if (pos.indexOf('bottom') !== -1) {
12
+ corner.insertBefore(container, corner.firstChild);
13
+ } else {
14
+ corner.appendChild(container);
15
+ }
16
+ return this;
17
+ },
18
+
19
+ removeControl: function (control) {
20
+ var pos = control.getPosition(),
21
+ corner = this._controlCorners[pos],
22
+ container = control.getContainer();
23
+
24
+ corner.removeChild(container);
25
+
26
+ if (control.onRemove) {
27
+ control.onRemove(this);
28
+ }
29
+ return this;
30
+ },
31
+
32
+ _initControlPos: function () {
33
+ var corners = this._controlCorners = {},
34
+ classPart = 'leaflet-',
35
+ top = classPart + 'top',
36
+ bottom = classPart + 'bottom',
37
+ left = classPart + 'left',
38
+ right = classPart + 'right',
39
+ controlContainer = L.DomUtil.create('div', classPart + 'control-container', this._container);
40
+
41
+ if (L.Browser.touch) {
42
+ controlContainer.className += ' ' + classPart + 'big-buttons';
43
+ }
44
+
45
+ corners.topLeft = L.DomUtil.create('div', top + ' ' + left, controlContainer);
46
+ corners.topRight = L.DomUtil.create('div', top + ' ' + right, controlContainer);
47
+ corners.bottomLeft = L.DomUtil.create('div', bottom + ' ' + left, controlContainer);
48
+ corners.bottomRight = L.DomUtil.create('div', bottom + ' ' + right, controlContainer);
49
+ }
50
+ });
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Provides L.Map with convenient shortcuts for W3C geolocation.
3
+ */
4
+
5
+ L.Map.include({
6
+ locate: function (/*Object*/ options) {
7
+
8
+ this._locationOptions = options = L.Util.extend({
9
+ watch: false,
10
+ setView: false,
11
+ maxZoom: Infinity,
12
+ timeout: 10000,
13
+ maximumAge: 0,
14
+ enableHighAccuracy: false
15
+ }, options);
16
+
17
+ if (!navigator.geolocation) {
18
+ return this.fire('locationerror', {
19
+ code: 0,
20
+ message: "Geolocation not supported."
21
+ });
22
+ }
23
+
24
+ var onResponse = L.Util.bind(this._handleGeolocationResponse, this),
25
+ onError = L.Util.bind(this._handleGeolocationError, this);
26
+
27
+ if (options.watch) {
28
+ this._locationWatchId = navigator.geolocation.watchPosition(onResponse, onError, options);
29
+ } else {
30
+ navigator.geolocation.getCurrentPosition(onResponse, onError, options);
31
+ }
32
+ return this;
33
+ },
34
+
35
+ stopLocate: function () {
36
+ if (navigator.geolocation) {
37
+ navigator.geolocation.clearWatch(this._locationWatchId);
38
+ }
39
+ },
40
+
41
+ locateAndSetView: function (maxZoom, options) {
42
+ options = L.Util.extend({
43
+ maxZoom: maxZoom || Infinity,
44
+ setView: true
45
+ }, options);
46
+ return this.locate(options);
47
+ },
48
+
49
+ _handleGeolocationError: function (error) {
50
+ var c = error.code,
51
+ message = (c === 1 ? "permission denied" :
52
+ (c === 2 ? "position unavailable" : "timeout"));
53
+
54
+ if (this._locationOptions.setView && !this._loaded) {
55
+ this.fitWorld();
56
+ }
57
+
58
+ this.fire('locationerror', {
59
+ code: c,
60
+ message: "Geolocation error: " + message + "."
61
+ });
62
+ },
63
+
64
+ _handleGeolocationResponse: function (pos) {
65
+ var latAccuracy = 180 * pos.coords.accuracy / 4e7,
66
+ lngAccuracy = latAccuracy * 2,
67
+ lat = pos.coords.latitude,
68
+ lng = pos.coords.longitude,
69
+ latlng = new L.LatLng(lat, lng);
70
+
71
+ var sw = new L.LatLng(lat - latAccuracy, lng - lngAccuracy),
72
+ ne = new L.LatLng(lat + latAccuracy, lng + lngAccuracy),
73
+ bounds = new L.LatLngBounds(sw, ne);
74
+
75
+ if (this._locationOptions.setView) {
76
+ var zoom = Math.min(this.getBoundsZoom(bounds), this._locationOptions.maxZoom);
77
+ this.setView(latlng, zoom);
78
+ }
79
+
80
+ this.fire('locationfound', {
81
+ latlng: latlng,
82
+ bounds: bounds,
83
+ accuracy: pos.coords.accuracy
84
+ });
85
+ }
86
+ });
@@ -0,0 +1,20 @@
1
+
2
+ L.Map.include({
3
+ openPopup: function (popup) {
4
+ this.closePopup();
5
+ this._popup = popup;
6
+ this.addLayer(popup);
7
+ this.fire('popupopen', { popup: this._popup });
8
+
9
+ return this;
10
+ },
11
+
12
+ closePopup: function () {
13
+ if (this._popup) {
14
+ this.removeLayer(this._popup);
15
+ this.fire('popupclose', { popup: this._popup });
16
+ this._popup = null;
17
+ }
18
+ return this;
19
+ }
20
+ });
@@ -0,0 +1,73 @@
1
+ /*
2
+ * L.Handler.ShiftDragZoom is used internally by L.Map to add shift-drag zoom (zoom to a selected bounding box).
3
+ */
4
+
5
+ L.Map.BoxZoom = L.Handler.extend({
6
+ initialize: function (map) {
7
+ this._map = map;
8
+ this._container = map._container;
9
+ this._pane = map._panes.overlayPane;
10
+ },
11
+
12
+ addHooks: function () {
13
+ L.DomEvent.addListener(this._container, 'mousedown', this._onMouseDown, this);
14
+ },
15
+
16
+ removeHooks: function () {
17
+ L.DomEvent.removeListener(this._container, 'mousedown', this._onMouseDown);
18
+ },
19
+
20
+ _onMouseDown: function (e) {
21
+ if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) {
22
+ return false;
23
+ }
24
+
25
+ L.DomUtil.disableTextSelection();
26
+
27
+ this._startLayerPoint = this._map.mouseEventToLayerPoint(e);
28
+
29
+ this._box = L.DomUtil.create('div', 'leaflet-zoom-box', this._pane);
30
+ L.DomUtil.setPosition(this._box, this._startLayerPoint);
31
+
32
+ //TODO move cursor to styles
33
+ this._container.style.cursor = 'crosshair';
34
+
35
+ L.DomEvent.addListener(document, 'mousemove', this._onMouseMove, this);
36
+ L.DomEvent.addListener(document, 'mouseup', this._onMouseUp, this);
37
+
38
+ L.DomEvent.preventDefault(e);
39
+ },
40
+
41
+ _onMouseMove: function (e) {
42
+ var layerPoint = this._map.mouseEventToLayerPoint(e),
43
+ dx = layerPoint.x - this._startLayerPoint.x,
44
+ dy = layerPoint.y - this._startLayerPoint.y;
45
+
46
+ var newX = Math.min(layerPoint.x, this._startLayerPoint.x),
47
+ newY = Math.min(layerPoint.y, this._startLayerPoint.y),
48
+ newPos = new L.Point(newX, newY);
49
+
50
+ L.DomUtil.setPosition(this._box, newPos);
51
+
52
+ this._box.style.width = (Math.abs(dx) - 4) + 'px';
53
+ this._box.style.height = (Math.abs(dy) - 4) + 'px';
54
+ },
55
+
56
+ _onMouseUp: function (e) {
57
+ this._pane.removeChild(this._box);
58
+ this._container.style.cursor = '';
59
+
60
+ L.DomUtil.enableTextSelection();
61
+
62
+ L.DomEvent.removeListener(document, 'mousemove', this._onMouseMove);
63
+ L.DomEvent.removeListener(document, 'mouseup', this._onMouseUp);
64
+
65
+ var layerPoint = this._map.mouseEventToLayerPoint(e);
66
+
67
+ var bounds = new L.LatLngBounds(
68
+ this._map.layerPointToLatLng(this._startLayerPoint),
69
+ this._map.layerPointToLatLng(layerPoint));
70
+
71
+ this._map.fitBounds(bounds);
72
+ }
73
+ });
@@ -0,0 +1,18 @@
1
+ /*
2
+ * L.Handler.DoubleClickZoom is used internally by L.Map to add double-click zooming.
3
+ */
4
+
5
+ L.Map.DoubleClickZoom = L.Handler.extend({
6
+ addHooks: function () {
7
+ this._map.on('dblclick', this._onDoubleClick);
8
+ // TODO remove 3d argument?
9
+ },
10
+
11
+ removeHooks: function () {
12
+ this._map.off('dblclick', this._onDoubleClick);
13
+ },
14
+
15
+ _onDoubleClick: function (e) {
16
+ this.setView(e.latlng, this._zoom + 1);
17
+ }
18
+ });