leaflet-js 0.6.beta4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/CHANGELOG.rdoc +3 -0
- data/leaflet-js.gemspec +2 -2
- data/lib/leaflet.draw/CHANGELOG.md +45 -0
- data/lib/leaflet.draw/README.md +70 -23
- data/lib/leaflet.draw/build/deps.js +1 -0
- data/lib/leaflet.draw/dist/images/spritesheet-2x.png +0 -0
- data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
- data/lib/leaflet.draw/dist/leaflet.draw-src.js +489 -136
- data/lib/leaflet.draw/dist/leaflet.draw.css +34 -2
- data/lib/leaflet.draw/dist/leaflet.draw.ie.css +5 -0
- data/lib/leaflet.draw/dist/leaflet.draw.js +2 -2
- data/lib/leaflet.draw/examples/basic.html +14 -7
- data/lib/leaflet.draw/examples/libs/images/layers-2x.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon-2x.png +0 -0
- data/lib/leaflet.draw/examples/libs/leaflet-src.js +1129 -608
- data/lib/leaflet.draw/examples/libs/leaflet.css +85 -66
- data/lib/leaflet.draw/package.json +2 -2
- data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +1 -1
- data/lib/leaflet.draw/spec/suites/GeometryUtilSpec.js +25 -0
- data/lib/leaflet.draw/spec/suites/LatLngUtilSpec.js +9 -0
- data/lib/leaflet.draw/src/Control.Draw.js +1 -0
- data/lib/leaflet.draw/src/Leaflet.draw.js +89 -1
- data/lib/leaflet.draw/src/Toolbar.js +2 -6
- data/lib/leaflet.draw/src/Tooltip.js +20 -7
- data/lib/leaflet.draw/src/draw/DrawToolbar.js +26 -22
- data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +11 -6
- data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +6 -2
- data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +7 -2
- data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +29 -7
- data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +44 -21
- data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +3 -3
- data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +14 -1
- data/lib/leaflet.draw/src/edit/EditToolbar.js +86 -16
- data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +10 -7
- data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +1 -2
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +15 -3
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +56 -38
- data/lib/leaflet.draw/src/ext/GeometryUtil.js +68 -0
- data/lib/leaflet.draw/src/images/spritesheet.svg +41 -0
- data/lib/leaflet.label/CHANGELOG.md +32 -0
- data/lib/leaflet.label/README.md +21 -4
- data/lib/leaflet.label/build/build.js +2 -2
- data/lib/leaflet.label/build/deps.js +2 -0
- data/lib/leaflet.label/build/hintrc.js +4 -0
- data/lib/leaflet.label/dist/leaflet.label-src.js +266 -83
- data/lib/leaflet.label/dist/leaflet.label.css +23 -4
- data/lib/leaflet.label/dist/leaflet.label.js +1 -1
- data/lib/leaflet.label/example/label.html +6 -3
- data/lib/leaflet.label/libs/leaflet/images/layers-2x.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon-2x.png +0 -0
- data/lib/leaflet.label/libs/leaflet/leaflet-src.js +1129 -608
- data/lib/leaflet.label/libs/leaflet/leaflet.css +85 -66
- data/lib/leaflet.label/libs/leaflet/leaflet.js +6 -5
- data/lib/leaflet.label/package.json +19 -0
- data/lib/leaflet.label/src/BaseMarkerMethods.js +129 -0
- data/lib/leaflet.label/src/CircleMarker.Label.js +7 -0
- data/lib/leaflet.label/src/Label.js +161 -37
- data/lib/leaflet.label/src/Leaflet.label.js +1 -1
- data/lib/leaflet.label/src/Map.Label.js +0 -2
- data/lib/leaflet.label/src/Marker.Label.js +15 -120
- data/lib/leaflet.label/src/Path.Label.js +11 -11
- data/lib/leaflet/CHANGELOG.md +299 -31
- data/lib/leaflet/CONTRIBUTING.md +3 -3
- data/lib/leaflet/FAQ.md +138 -0
- data/lib/leaflet/Jakefile.js +24 -4
- data/lib/leaflet/PLUGIN-GUIDE.md +127 -0
- data/lib/leaflet/README.md +10 -6
- data/lib/leaflet/build/build.html +3 -19
- data/lib/leaflet/build/build.js +21 -51
- data/lib/leaflet/build/deps.js +10 -7
- data/lib/leaflet/build/hintrc.js +6 -4
- data/lib/leaflet/debug/hacks/jitter.html +0 -1
- data/lib/leaflet/debug/map/canvas.html +11 -12
- data/lib/leaflet/debug/map/controls.html +3 -4
- data/lib/leaflet/debug/map/geolocation.html +0 -1
- data/lib/leaflet/debug/map/iframe.html +11 -0
- data/lib/leaflet/debug/map/image-overlay.html +0 -1
- data/lib/leaflet/debug/map/map-mobile.html +0 -1
- data/lib/leaflet/debug/map/map.html +1 -2
- data/lib/leaflet/debug/map/max-bounds.html +2 -1
- data/lib/leaflet/debug/map/opacity.html +223 -0
- data/lib/leaflet/debug/map/scroll.html +6 -1
- data/lib/leaflet/debug/map/simple-proj.html +0 -1
- data/lib/leaflet/debug/map/wms-marble.html +4 -5
- data/lib/leaflet/debug/map/wms.html +0 -1
- data/lib/leaflet/debug/map/zoomlevels.html +0 -1
- data/lib/leaflet/debug/tests/add_remove_layers.html +5 -6
- data/lib/leaflet/debug/tests/bringtoback.html +0 -1
- data/lib/leaflet/debug/tests/canvasloop.html +47 -0
- data/lib/leaflet/debug/tests/click_on_canvas.html +0 -1
- data/lib/leaflet/debug/tests/dragging_and_copyworldjump.html +61 -0
- data/lib/leaflet/debug/tests/opacity.html +0 -1
- data/lib/leaflet/debug/tests/popupcontextmenuclicks.html +59 -0
- data/lib/leaflet/debug/tests/remove_while_dragging.html +4 -5
- data/lib/leaflet/debug/tests/removetilewhilepan.html +0 -1
- data/lib/leaflet/debug/tests/reuse_popups.html +0 -1
- data/lib/leaflet/debug/tests/rtl.html +42 -0
- data/lib/leaflet/debug/tests/rtl2.html +27 -0
- data/lib/leaflet/debug/tests/set_icon_reuse_dom.html +43 -0
- data/lib/leaflet/debug/tests/svg_clicks.html +3 -4
- data/lib/leaflet/debug/vector/bounds-extend.html +0 -1
- data/lib/leaflet/debug/vector/feature-group-bounds.html +0 -1
- data/lib/leaflet/debug/vector/geojson.html +0 -1
- data/lib/leaflet/debug/vector/rectangle.html +0 -1
- data/lib/leaflet/debug/vector/touchzoomemu.html +2 -3
- data/lib/leaflet/debug/vector/vector-bounds.html +0 -1
- data/lib/leaflet/debug/vector/vector-canvas.html +0 -1
- data/lib/leaflet/debug/vector/vector-mobile.html +0 -1
- data/lib/leaflet/debug/vector/vector-simple.html +0 -1
- data/lib/leaflet/debug/vector/vector.html +0 -1
- data/lib/leaflet/dist/images/layers-2x.png +0 -0
- data/lib/leaflet/dist/images/layers.png +0 -0
- data/lib/leaflet/dist/leaflet.css +85 -66
- data/lib/leaflet/package.json +25 -20
- data/lib/leaflet/spec/after.js +1 -1
- data/lib/leaflet/spec/index.html +21 -13
- data/lib/leaflet/spec/karma.conf.js +51 -50
- data/lib/leaflet/spec/spec.hintrc.js +25 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +2 -2
- data/lib/leaflet/spec/suites/SpecHelper.js +37 -21
- data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +1 -1
- data/lib/leaflet/spec/suites/core/ClassSpec.js +12 -12
- data/lib/leaflet/spec/suites/core/EventsSpec.js +74 -18
- data/lib/leaflet/spec/suites/core/UtilSpec.js +69 -25
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +16 -16
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +9 -16
- data/lib/leaflet/spec/suites/dom/PosAnimationSpec.js +27 -0
- data/lib/leaflet/spec/suites/geo/CRSSpec.js +47 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +22 -14
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +22 -8
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +21 -20
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +15 -15
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +12 -12
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +4 -4
- data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +59 -9
- data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +213 -17
- data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +6 -6
- data/lib/leaflet/spec/suites/layer/PopupSpec.js +65 -5
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +16 -15
- data/lib/leaflet/spec/suites/layer/marker/MarkerSpec.js +94 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +7 -7
- data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +38 -2
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +4 -4
- data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +2 -2
- data/lib/leaflet/spec/suites/map/MapSpec.js +318 -26
- data/lib/leaflet/spec/suites/map/handler/Map.DragSpec.js +38 -0
- data/lib/leaflet/src/Leaflet.js +2 -2
- data/lib/leaflet/src/control/Control.Attribution.js +6 -0
- data/lib/leaflet/src/control/Control.Layers.js +33 -24
- data/lib/leaflet/src/control/Control.Zoom.js +12 -4
- data/lib/leaflet/src/control/Control.js +10 -0
- data/lib/leaflet/src/copyright.js +2 -1
- data/lib/leaflet/src/core/Browser.js +11 -10
- data/lib/leaflet/src/core/Events.js +15 -11
- data/lib/leaflet/src/core/Util.js +19 -14
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +13 -12
- data/lib/leaflet/src/dom/DomEvent.Pointer.js +155 -0
- data/lib/leaflet/src/dom/DomEvent.js +57 -19
- data/lib/leaflet/src/dom/DomUtil.js +89 -34
- data/lib/leaflet/src/dom/Draggable.js +26 -89
- data/lib/leaflet/src/dom/PosAnimation.js +13 -2
- data/lib/leaflet/src/geo/LatLng.js +16 -5
- data/lib/leaflet/src/geo/LatLngBounds.js +5 -2
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +2 -2
- data/lib/leaflet/src/geo/crs/CRS.js +5 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +3 -3
- data/lib/leaflet/src/geometry/LineUtil.js +2 -2
- data/lib/leaflet/src/images/layers.svg +8 -0
- data/lib/leaflet/src/images/marker.svg +61 -1
- data/lib/leaflet/src/layer/FeatureGroup.js +24 -7
- data/lib/leaflet/src/layer/GeoJSON.js +97 -56
- data/lib/leaflet/src/layer/ImageOverlay.js +9 -0
- data/lib/leaflet/src/layer/LayerGroup.js +8 -3
- data/lib/leaflet/src/layer/Popup.js +56 -34
- data/lib/leaflet/src/layer/marker/DivIcon.js +4 -2
- data/lib/leaflet/src/layer/marker/Icon.Default.js +1 -1
- data/lib/leaflet/src/layer/marker/Icon.js +15 -18
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +7 -5
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +22 -5
- data/lib/leaflet/src/layer/marker/Marker.js +75 -32
- data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +14 -26
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +7 -6
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +14 -10
- data/lib/leaflet/src/layer/tile/TileLayer.js +53 -32
- data/lib/leaflet/src/layer/vector/CircleMarker.js +11 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +10 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +14 -3
- data/lib/leaflet/src/layer/vector/Path.VML.js +12 -2
- data/lib/leaflet/src/layer/vector/Path.js +7 -3
- data/lib/leaflet/src/layer/vector/Polygon.js +14 -3
- data/lib/leaflet/src/layer/vector/canvas/CircleMarker.Canvas.js +9 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +1 -0
- data/lib/leaflet/src/map/Map.js +192 -125
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +29 -19
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +21 -9
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +11 -4
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +26 -12
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +10 -3
- data/lib/leaflet/src/map/handler/Map.Drag.js +12 -6
- data/lib/leaflet/src/map/handler/Map.Keyboard.js +5 -2
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +7 -1
- data/lib/leaflet/src/map/handler/Map.Tap.js +107 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +9 -3
- data/vendor/assets/images/layers-2x.png +0 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/spritesheet-2x.png +0 -0
- data/vendor/assets/images/spritesheet.png +0 -0
- data/vendor/assets/javascripts/leaflet.draw.js +2 -4
- data/vendor/assets/javascripts/leaflet.js +3 -1
- data/vendor/assets/javascripts/leaflet.label.js +2 -0
- data/vendor/assets/stylesheets/leaflet.css.erb +337 -318
- data/vendor/assets/stylesheets/leaflet.draw.css.erb +35 -3
- data/vendor/assets/stylesheets/leaflet.draw.ie.css +5 -0
- data/vendor/assets/stylesheets/leaflet.label.css +23 -4
- metadata +40 -14
- data/lib/leaflet.draw/examples/libs/leaflet.ie.css +0 -51
- data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +0 -51
- data/lib/leaflet/dist/leaflet-src.js +0 -8579
- data/lib/leaflet/dist/leaflet.ie.css +0 -51
- data/lib/leaflet/dist/leaflet.js +0 -8
- data/lib/leaflet/spec/happen.js +0 -93
- data/lib/leaflet/src/dom/DomEvent.MsTouch.js +0 -146
- data/vendor/assets/stylesheets/leaflet.ie.css +0 -51
data/lib/leaflet/src/map/Map.js
CHANGED
@@ -23,9 +23,13 @@ L.Map = L.Class.extend({
|
|
23
23
|
initialize: function (id, options) { // (HTMLElement or String, Object)
|
24
24
|
options = L.setOptions(this, options);
|
25
25
|
|
26
|
+
|
26
27
|
this._initContainer(id);
|
27
28
|
this._initLayout();
|
28
|
-
|
29
|
+
|
30
|
+
// hack for https://github.com/Leaflet/Leaflet/issues/1980
|
31
|
+
this._onResize = L.bind(this._onResize, this);
|
32
|
+
|
29
33
|
this._initEvents();
|
30
34
|
|
31
35
|
if (options.maxBounds) {
|
@@ -33,10 +37,18 @@ L.Map = L.Class.extend({
|
|
33
37
|
}
|
34
38
|
|
35
39
|
if (options.center && options.zoom !== undefined) {
|
36
|
-
this.setView(L.latLng(options.center), options.zoom, true);
|
40
|
+
this.setView(L.latLng(options.center), options.zoom, {reset: true});
|
37
41
|
}
|
38
42
|
|
39
|
-
this.
|
43
|
+
this._handlers = [];
|
44
|
+
|
45
|
+
this._layers = {};
|
46
|
+
this._zoomBoundLayers = {};
|
47
|
+
this._tileLayersNum = 0;
|
48
|
+
|
49
|
+
this.callInitHooks();
|
50
|
+
|
51
|
+
this._addLayers(options.layers);
|
40
52
|
},
|
41
53
|
|
42
54
|
|
@@ -44,23 +56,28 @@ L.Map = L.Class.extend({
|
|
44
56
|
|
45
57
|
// replaced by animation-powered implementation in Map.PanAnimation.js
|
46
58
|
setView: function (center, zoom) {
|
59
|
+
zoom = zoom === undefined ? this.getZoom() : zoom;
|
47
60
|
this._resetView(L.latLng(center), this._limitZoom(zoom));
|
48
61
|
return this;
|
49
62
|
},
|
50
63
|
|
51
|
-
setZoom: function (zoom) {
|
52
|
-
|
64
|
+
setZoom: function (zoom, options) {
|
65
|
+
if (!this._loaded) {
|
66
|
+
this._zoom = this._limitZoom(zoom);
|
67
|
+
return this;
|
68
|
+
}
|
69
|
+
return this.setView(this.getCenter(), zoom, {zoom: options});
|
53
70
|
},
|
54
71
|
|
55
|
-
zoomIn: function (delta) {
|
56
|
-
return this.setZoom(this._zoom + (delta || 1));
|
72
|
+
zoomIn: function (delta, options) {
|
73
|
+
return this.setZoom(this._zoom + (delta || 1), options);
|
57
74
|
},
|
58
75
|
|
59
|
-
zoomOut: function (delta) {
|
60
|
-
return this.setZoom(this._zoom - (delta || 1));
|
76
|
+
zoomOut: function (delta, options) {
|
77
|
+
return this.setZoom(this._zoom - (delta || 1), options);
|
61
78
|
},
|
62
79
|
|
63
|
-
setZoomAround: function (latlng, zoom) {
|
80
|
+
setZoomAround: function (latlng, zoom, options) {
|
64
81
|
var scale = this.getZoomScale(zoom),
|
65
82
|
viewHalf = this.getSize().divideBy(2),
|
66
83
|
containerPoint = latlng instanceof L.Point ? latlng : this.latLngToContainerPoint(latlng),
|
@@ -68,35 +85,39 @@ L.Map = L.Class.extend({
|
|
68
85
|
centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale),
|
69
86
|
newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
|
70
87
|
|
71
|
-
return this.setView(newCenter, zoom);
|
88
|
+
return this.setView(newCenter, zoom, {zoom: options});
|
72
89
|
},
|
73
90
|
|
74
|
-
fitBounds: function (bounds,
|
91
|
+
fitBounds: function (bounds, options) {
|
75
92
|
|
93
|
+
options = options || {};
|
76
94
|
bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds);
|
77
95
|
|
78
|
-
|
79
|
-
|
96
|
+
var paddingTL = L.point(options.paddingTopLeft || options.padding || [0, 0]),
|
97
|
+
paddingBR = L.point(options.paddingBottomRight || options.padding || [0, 0]),
|
98
|
+
|
99
|
+
zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR)),
|
100
|
+
paddingOffset = paddingBR.subtract(paddingTL).divideBy(2),
|
80
101
|
|
81
|
-
var zoom = this.getBoundsZoom(bounds, false, paddingTopLeft.add(paddingBottomRight)),
|
82
|
-
paddingOffset = paddingBottomRight.subtract(paddingTopLeft).divideBy(2),
|
83
102
|
swPoint = this.project(bounds.getSouthWest(), zoom),
|
84
103
|
nePoint = this.project(bounds.getNorthEast(), zoom),
|
85
104
|
center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom);
|
86
105
|
|
87
|
-
|
106
|
+
zoom = options && options.maxZoom ? Math.min(options.maxZoom, zoom) : zoom;
|
107
|
+
|
108
|
+
return this.setView(center, zoom, options);
|
88
109
|
},
|
89
110
|
|
90
|
-
fitWorld: function () {
|
91
|
-
return this.fitBounds([[-90, -180], [90, 180]]);
|
111
|
+
fitWorld: function (options) {
|
112
|
+
return this.fitBounds([[-90, -180], [90, 180]], options);
|
92
113
|
},
|
93
114
|
|
94
|
-
panTo: function (center) { // (LatLng)
|
95
|
-
return this.setView(center, this._zoom);
|
115
|
+
panTo: function (center, options) { // (LatLng)
|
116
|
+
return this.setView(center, this._zoom, {pan: options});
|
96
117
|
},
|
97
118
|
|
98
119
|
panBy: function (offset) { // (Point)
|
99
|
-
// replaced with animated panBy in Map.
|
120
|
+
// replaced with animated panBy in Map.PanAnimation.js
|
100
121
|
this.fire('movestart');
|
101
122
|
|
102
123
|
this._rawPanBy(L.point(offset));
|
@@ -111,56 +132,23 @@ L.Map = L.Class.extend({
|
|
111
132
|
this.options.maxBounds = bounds;
|
112
133
|
|
113
134
|
if (!bounds) {
|
114
|
-
this.
|
115
|
-
return this;
|
135
|
+
return this.off('moveend', this._panInsideMaxBounds, this);
|
116
136
|
}
|
117
137
|
|
118
|
-
var minZoom = this.getBoundsZoom(bounds, true);
|
119
|
-
|
120
|
-
this._boundsMinZoom = minZoom;
|
121
|
-
|
122
138
|
if (this._loaded) {
|
123
|
-
|
124
|
-
this.setView(bounds.getCenter(), minZoom);
|
125
|
-
} else {
|
126
|
-
this.panInsideBounds(bounds);
|
127
|
-
}
|
139
|
+
this._panInsideMaxBounds();
|
128
140
|
}
|
129
141
|
|
130
|
-
this.on('moveend', this._panInsideMaxBounds, this);
|
131
|
-
|
132
|
-
return this;
|
142
|
+
return this.on('moveend', this._panInsideMaxBounds, this);
|
133
143
|
},
|
134
144
|
|
135
|
-
panInsideBounds: function (bounds) {
|
136
|
-
|
145
|
+
panInsideBounds: function (bounds, options) {
|
146
|
+
var center = this.getCenter(),
|
147
|
+
newCenter = this._limitCenter(center, this._zoom, bounds);
|
137
148
|
|
138
|
-
|
139
|
-
viewSw = viewBounds.getBottomLeft(),
|
140
|
-
viewNe = viewBounds.getTopRight(),
|
141
|
-
sw = this.project(bounds.getSouthWest()),
|
142
|
-
ne = this.project(bounds.getNorthEast()),
|
143
|
-
dx = 0,
|
144
|
-
dy = 0;
|
149
|
+
if (center.equals(newCenter)) { return this; }
|
145
150
|
|
146
|
-
|
147
|
-
dy = Math.ceil(ne.y - viewNe.y);
|
148
|
-
}
|
149
|
-
if (viewNe.x > ne.x) { // east
|
150
|
-
dx = Math.floor(ne.x - viewNe.x);
|
151
|
-
}
|
152
|
-
if (viewSw.y > sw.y) { // south
|
153
|
-
dy = Math.floor(sw.y - viewSw.y);
|
154
|
-
}
|
155
|
-
if (viewSw.x < sw.x) { // west
|
156
|
-
dx = Math.ceil(sw.x - viewSw.x);
|
157
|
-
}
|
158
|
-
|
159
|
-
if (dx || dy) {
|
160
|
-
return this.panBy([dx, dy]);
|
161
|
-
}
|
162
|
-
|
163
|
-
return this;
|
151
|
+
return this.panTo(newCenter, options);
|
164
152
|
},
|
165
153
|
|
166
154
|
addLayer: function (layer) {
|
@@ -181,14 +169,13 @@ L.Map = L.Class.extend({
|
|
181
169
|
// TODO looks ugly, refactor!!!
|
182
170
|
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
|
183
171
|
this._tileLayersNum++;
|
184
|
-
|
185
|
-
|
172
|
+
this._tileLayersToLoad++;
|
173
|
+
layer.on('load', this._onTileLayerLoad, this);
|
186
174
|
}
|
187
175
|
|
188
|
-
this.
|
189
|
-
|
190
|
-
|
191
|
-
}, this);
|
176
|
+
if (this._loaded) {
|
177
|
+
this._layerAdd(layer);
|
178
|
+
}
|
192
179
|
|
193
180
|
return this;
|
194
181
|
},
|
@@ -196,11 +183,18 @@ L.Map = L.Class.extend({
|
|
196
183
|
removeLayer: function (layer) {
|
197
184
|
var id = L.stamp(layer);
|
198
185
|
|
199
|
-
if (!this._layers[id]) { return; }
|
186
|
+
if (!this._layers[id]) { return this; }
|
200
187
|
|
201
|
-
|
188
|
+
if (this._loaded) {
|
189
|
+
layer.onRemove(this);
|
190
|
+
}
|
202
191
|
|
203
192
|
delete this._layers[id];
|
193
|
+
|
194
|
+
if (this._loaded) {
|
195
|
+
this.fire('layerremove', {layer: layer});
|
196
|
+
}
|
197
|
+
|
204
198
|
if (this._zoomBoundLayers[id]) {
|
205
199
|
delete this._zoomBoundLayers[id];
|
206
200
|
this._updateZoomLevels();
|
@@ -209,11 +203,11 @@ L.Map = L.Class.extend({
|
|
209
203
|
// TODO looks ugly, refactor
|
210
204
|
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
|
211
205
|
this._tileLayersNum--;
|
212
|
-
|
213
|
-
|
206
|
+
this._tileLayersToLoad--;
|
207
|
+
layer.off('load', this._onTileLayerLoad, this);
|
214
208
|
}
|
215
209
|
|
216
|
-
return this
|
210
|
+
return this;
|
217
211
|
},
|
218
212
|
|
219
213
|
hasLayer: function (layer) {
|
@@ -229,47 +223,59 @@ L.Map = L.Class.extend({
|
|
229
223
|
return this;
|
230
224
|
},
|
231
225
|
|
232
|
-
invalidateSize: function (
|
233
|
-
|
226
|
+
invalidateSize: function (options) {
|
227
|
+
options = L.extend({
|
228
|
+
animate: false,
|
229
|
+
pan: true
|
230
|
+
}, options === true ? {animate: true} : options);
|
234
231
|
|
232
|
+
var oldSize = this.getSize();
|
235
233
|
this._sizeChanged = true;
|
236
|
-
|
237
|
-
if (this.options.maxBounds) {
|
238
|
-
this.setMaxBounds(this.options.maxBounds);
|
239
|
-
}
|
234
|
+
this._initialCenter = null;
|
240
235
|
|
241
236
|
if (!this._loaded) { return this; }
|
242
237
|
|
243
238
|
var newSize = this.getSize(),
|
244
|
-
|
239
|
+
oldCenter = oldSize.divideBy(2).round(),
|
240
|
+
newCenter = newSize.divideBy(2).round(),
|
241
|
+
offset = oldCenter.subtract(newCenter);
|
245
242
|
|
246
|
-
if (
|
247
|
-
|
248
|
-
|
249
|
-
|
243
|
+
if (!offset.x && !offset.y) { return this; }
|
244
|
+
|
245
|
+
if (options.animate && options.pan) {
|
246
|
+
this.panBy(offset);
|
247
|
+
|
248
|
+
} else {
|
249
|
+
if (options.pan) {
|
250
250
|
this._rawPanBy(offset);
|
251
|
+
}
|
251
252
|
|
252
|
-
|
253
|
+
this.fire('move');
|
253
254
|
|
255
|
+
if (options.debounceMoveend) {
|
254
256
|
clearTimeout(this._sizeTimer);
|
255
257
|
this._sizeTimer = setTimeout(L.bind(this.fire, this, 'moveend'), 200);
|
258
|
+
} else {
|
259
|
+
this.fire('moveend');
|
256
260
|
}
|
257
|
-
this.fire('resize', {
|
258
|
-
oldSize: oldSize,
|
259
|
-
newSize: newSize
|
260
|
-
});
|
261
261
|
}
|
262
|
-
|
262
|
+
|
263
|
+
return this.fire('resize', {
|
264
|
+
oldSize: oldSize,
|
265
|
+
newSize: newSize
|
266
|
+
});
|
263
267
|
},
|
264
268
|
|
265
269
|
// TODO handler.addTo
|
266
270
|
addHandler: function (name, HandlerClass) {
|
267
|
-
if (!HandlerClass) { return; }
|
271
|
+
if (!HandlerClass) { return this; }
|
272
|
+
|
273
|
+
var handler = this[name] = new HandlerClass(this);
|
268
274
|
|
269
|
-
this
|
275
|
+
this._handlers.push(handler);
|
270
276
|
|
271
277
|
if (this.options[name]) {
|
272
|
-
|
278
|
+
handler.enable();
|
273
279
|
}
|
274
280
|
|
275
281
|
return this;
|
@@ -279,8 +285,23 @@ L.Map = L.Class.extend({
|
|
279
285
|
if (this._loaded) {
|
280
286
|
this.fire('unload');
|
281
287
|
}
|
288
|
+
|
282
289
|
this._initEvents('off');
|
283
|
-
|
290
|
+
|
291
|
+
try {
|
292
|
+
// throws error in IE6-8
|
293
|
+
delete this._container._leaflet;
|
294
|
+
} catch (e) {
|
295
|
+
this._container._leaflet = undefined;
|
296
|
+
}
|
297
|
+
|
298
|
+
this._clearPanes();
|
299
|
+
if (this._clearControlPos) {
|
300
|
+
this._clearControlPos();
|
301
|
+
}
|
302
|
+
|
303
|
+
this._clearHandlers();
|
304
|
+
|
284
305
|
return this;
|
285
306
|
},
|
286
307
|
|
@@ -290,7 +311,7 @@ L.Map = L.Class.extend({
|
|
290
311
|
getCenter: function () { // (Boolean) -> LatLng
|
291
312
|
this._checkIfLoaded();
|
292
313
|
|
293
|
-
if (!this._moved()) {
|
314
|
+
if (this._initialCenter && !this._moved()) {
|
294
315
|
return this._initialCenter;
|
295
316
|
}
|
296
317
|
return this.layerPointToLatLng(this._getCenterLayerPoint());
|
@@ -309,18 +330,15 @@ L.Map = L.Class.extend({
|
|
309
330
|
},
|
310
331
|
|
311
332
|
getMinZoom: function () {
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
return Math.max(z1, z2, z3);
|
333
|
+
return this.options.minZoom === undefined ?
|
334
|
+
(this._layersMinZoom === undefined ? 0 : this._layersMinZoom) :
|
335
|
+
this.options.minZoom;
|
317
336
|
},
|
318
337
|
|
319
338
|
getMaxZoom: function () {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
return Math.min(z1, z2);
|
339
|
+
return this.options.maxZoom === undefined ?
|
340
|
+
(this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) :
|
341
|
+
this.options.maxZoom;
|
324
342
|
},
|
325
343
|
|
326
344
|
getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number
|
@@ -463,15 +481,11 @@ L.Map = L.Class.extend({
|
|
463
481
|
_initLayout: function () {
|
464
482
|
var container = this._container;
|
465
483
|
|
466
|
-
L.DomUtil.addClass(container, 'leaflet-container'
|
467
|
-
|
468
|
-
|
469
|
-
L.
|
470
|
-
|
471
|
-
|
472
|
-
if (this.options.fadeAnimation) {
|
473
|
-
L.DomUtil.addClass(container, 'leaflet-fade-anim');
|
474
|
-
}
|
484
|
+
L.DomUtil.addClass(container, 'leaflet-container' +
|
485
|
+
(L.Browser.touch ? ' leaflet-touch' : '') +
|
486
|
+
(L.Browser.retina ? ' leaflet-retina' : '') +
|
487
|
+
(L.Browser.ielt9 ? ' leaflet-oldie' : '') +
|
488
|
+
(this.options.fadeAnimation ? ' leaflet-fade-anim' : ''));
|
475
489
|
|
476
490
|
var position = L.DomUtil.getStyle(container, 'position');
|
477
491
|
|
@@ -511,16 +525,14 @@ L.Map = L.Class.extend({
|
|
511
525
|
return L.DomUtil.create('div', className, container || this._panes.objectsPane);
|
512
526
|
},
|
513
527
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
this._layers = {};
|
518
|
-
this._zoomBoundLayers = {};
|
519
|
-
this._tileLayersNum = 0;
|
528
|
+
_clearPanes: function () {
|
529
|
+
this._container.removeChild(this._mapPane);
|
530
|
+
},
|
520
531
|
|
521
|
-
|
532
|
+
_addLayers: function (layers) {
|
533
|
+
layers = layers ? (L.Util.isArray(layers) ? layers : [layers]) : [];
|
522
534
|
|
523
|
-
for (i = 0, len = layers.length; i < len; i++) {
|
535
|
+
for (var i = 0, len = layers.length; i < len; i++) {
|
524
536
|
this.addLayer(layers[i]);
|
525
537
|
}
|
526
538
|
},
|
@@ -558,6 +570,7 @@ L.Map = L.Class.extend({
|
|
558
570
|
|
559
571
|
if (loading) {
|
560
572
|
this.fire('load');
|
573
|
+
this.eachLayer(this._layerAdd, this);
|
561
574
|
}
|
562
575
|
|
563
576
|
this.fire('viewreset', {hard: !preserveMapOffset});
|
@@ -642,18 +655,21 @@ L.Map = L.Class.extend({
|
|
642
655
|
_onResize: function () {
|
643
656
|
L.Util.cancelAnimFrame(this._resizeRequest);
|
644
657
|
this._resizeRequest = L.Util.requestAnimFrame(
|
645
|
-
this.invalidateSize, this, false, this._container);
|
658
|
+
function () { this.invalidateSize({debounceMoveend: true}); }, this, false, this._container);
|
646
659
|
},
|
647
660
|
|
648
661
|
_onMouseClick: function (e) {
|
649
|
-
if (!this._loaded || (
|
662
|
+
if (!this._loaded || (!e._simulated &&
|
663
|
+
((this.dragging && this.dragging.moved()) ||
|
664
|
+
(this.boxZoom && this.boxZoom.moved()))) ||
|
665
|
+
L.DomEvent._skipped(e)) { return; }
|
650
666
|
|
651
667
|
this.fire('preclick');
|
652
668
|
this._fireMouseEvent(e);
|
653
669
|
},
|
654
670
|
|
655
671
|
_fireMouseEvent: function (e) {
|
656
|
-
if (!this._loaded) { return; }
|
672
|
+
if (!this._loaded || L.DomEvent._skipped(e)) { return; }
|
657
673
|
|
658
674
|
var type = e.type;
|
659
675
|
|
@@ -684,6 +700,12 @@ L.Map = L.Class.extend({
|
|
684
700
|
}
|
685
701
|
},
|
686
702
|
|
703
|
+
_clearHandlers: function () {
|
704
|
+
for (var i = 0, len = this._handlers.length; i < len; i++) {
|
705
|
+
this._handlers[i].disable();
|
706
|
+
}
|
707
|
+
},
|
708
|
+
|
687
709
|
whenReady: function (callback, context) {
|
688
710
|
if (this._loaded) {
|
689
711
|
callback.call(context || this, this);
|
@@ -693,6 +715,11 @@ L.Map = L.Class.extend({
|
|
693
715
|
return this;
|
694
716
|
},
|
695
717
|
|
718
|
+
_layerAdd: function (layer) {
|
719
|
+
layer.onAdd(this);
|
720
|
+
this.fire('layeradd', {layer: layer});
|
721
|
+
},
|
722
|
+
|
696
723
|
|
697
724
|
// private methods for getting map state
|
698
725
|
|
@@ -730,6 +757,46 @@ L.Map = L.Class.extend({
|
|
730
757
|
return this.latLngToLayerPoint(latlng).subtract(this._getCenterLayerPoint());
|
731
758
|
},
|
732
759
|
|
760
|
+
// adjust center for view to get inside bounds
|
761
|
+
_limitCenter: function (center, zoom, bounds) {
|
762
|
+
|
763
|
+
if (!bounds) { return center; }
|
764
|
+
|
765
|
+
var centerPoint = this.project(center, zoom),
|
766
|
+
viewHalf = this.getSize().divideBy(2),
|
767
|
+
viewBounds = new L.Bounds(centerPoint.subtract(viewHalf), centerPoint.add(viewHalf)),
|
768
|
+
offset = this._getBoundsOffset(viewBounds, bounds, zoom);
|
769
|
+
|
770
|
+
return this.unproject(centerPoint.add(offset), zoom);
|
771
|
+
},
|
772
|
+
|
773
|
+
// adjust offset for view to get inside bounds
|
774
|
+
_limitOffset: function (offset, bounds) {
|
775
|
+
if (!bounds) { return offset; }
|
776
|
+
|
777
|
+
var viewBounds = this.getPixelBounds(),
|
778
|
+
newBounds = new L.Bounds(viewBounds.min.add(offset), viewBounds.max.add(offset));
|
779
|
+
|
780
|
+
return offset.add(this._getBoundsOffset(newBounds, bounds));
|
781
|
+
},
|
782
|
+
|
783
|
+
// returns offset needed for pxBounds to get inside maxBounds at a specified zoom
|
784
|
+
_getBoundsOffset: function (pxBounds, maxBounds, zoom) {
|
785
|
+
var nwOffset = this.project(maxBounds.getNorthWest(), zoom).subtract(pxBounds.min),
|
786
|
+
seOffset = this.project(maxBounds.getSouthEast(), zoom).subtract(pxBounds.max),
|
787
|
+
|
788
|
+
dx = this._rebound(nwOffset.x, -seOffset.x),
|
789
|
+
dy = this._rebound(nwOffset.y, -seOffset.y);
|
790
|
+
|
791
|
+
return new L.Point(dx, dy);
|
792
|
+
},
|
793
|
+
|
794
|
+
_rebound: function (left, right) {
|
795
|
+
return left + right > 0 ?
|
796
|
+
Math.round(left - right) / 2 :
|
797
|
+
Math.max(0, Math.ceil(left)) - Math.max(0, Math.floor(right));
|
798
|
+
},
|
799
|
+
|
733
800
|
_limitZoom: function (zoom) {
|
734
801
|
var min = this.getMinZoom(),
|
735
802
|
max = this.getMaxZoom();
|