diff --git a/src/map/Map.js b/src/map/Map.js index 39789595..90ac372b 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -288,7 +288,10 @@ L.Map = L.Class.extend({ zoom++; nePoint = this.project(ne, zoom); swPoint = this.project(sw, zoom); - boundsSize = new L.Point(Math.abs(nePoint.x - swPoint.x), Math.abs(swPoint.y - nePoint.y)); + + boundsSize = new L.Point( + Math.abs(nePoint.x - swPoint.x), + Math.abs(swPoint.y - nePoint.y)); if (!inside) { zoomNotFound = boundsSize.x <= size.x && boundsSize.y <= size.y; @@ -442,8 +445,7 @@ L.Map = L.Class.extend({ this._mapPane = panes.mapPane = this._createPane('leaflet-map-pane', this._container); this._tilePane = panes.tilePane = this._createPane('leaflet-tile-pane', this._mapPane); - this._objectsPane = panes.objectsPane = this._createPane('leaflet-objects-pane', this._mapPane); - + panes.objectsPane = this._createPane('leaflet-objects-pane', this._mapPane); panes.shadowPane = this._createPane('leaflet-shadow-pane'); panes.overlayPane = this._createPane('leaflet-overlay-pane'); panes.markerPane = this._createPane('leaflet-marker-pane'); @@ -459,7 +461,7 @@ L.Map = L.Class.extend({ }, _createPane: function (className, container) { - return L.DomUtil.create('div', className, container || this._objectsPane); + return L.DomUtil.create('div', className, container || this._panes.objectsPane); }, _initializers: [], @@ -541,8 +543,9 @@ L.Map = L.Class.extend({ L.DomEvent.on(this._container, 'click', this._onMouseClick, this); - var events = ['dblclick', 'mousedown', 'mouseup', 'mouseenter', 'mouseleave', 'mousemove', 'contextmenu'], - i, len; + var events = ['dblclick', 'mousedown', 'mouseup', 'mouseenter', + 'mouseleave', 'mousemove', 'contextmenu'], + i, len; for (i = 0, len = events.length; i < len; i++) { L.DomEvent.on(this._container, events[i], this._fireMouseEvent, this); @@ -555,7 +558,8 @@ L.Map = L.Class.extend({ _onResize: function () { L.Util.cancelAnimFrame(this._resizeRequest); - this._resizeRequest = L.Util.requestAnimFrame(this.invalidateSize, this, false, this._container); + this._resizeRequest = L.Util.requestAnimFrame( + this.invalidateSize, this, false, this._container); }, _onMouseClick: function (e) { @@ -579,8 +583,8 @@ L.Map = L.Class.extend({ } var containerPoint = this.mouseEventToContainerPoint(e), - layerPoint = this.containerPointToLayerPoint(containerPoint), - latlng = this.layerPointToLatLng(layerPoint); + layerPoint = this.containerPointToLayerPoint(containerPoint), + latlng = this.layerPointToLatLng(layerPoint); this.fire(type, { latlng: latlng, @@ -645,7 +649,7 @@ L.Map = L.Class.extend({ _limitZoom: function (zoom) { var min = this.getMinZoom(), - max = this.getMaxZoom(); + max = this.getMaxZoom(); return Math.max(min, Math.min(max, zoom)); } diff --git a/src/map/anim/Map.PanAnimation.js b/src/map/anim/Map.PanAnimation.js index 4fa10e0c..2c911fde 100644 --- a/src/map/anim/Map.PanAnimation.js +++ b/src/map/anim/Map.PanAnimation.js @@ -13,8 +13,8 @@ L.Map.include({ } var done = (zoomChanged ? - this._zoomToIfClose && this._zoomToIfClose(center, zoom) : - this._panByIfClose(center)); + this._zoomToIfClose && this._zoomToIfClose(center, zoom) : + this._panByIfClose(center)); // exit if animated pan or zoom started if (done) { @@ -77,9 +77,9 @@ L.Map.include({ _offsetIsWithinView: function (offset, multiplyFactor) { var m = multiplyFactor || 1, - size = this.getSize(); + size = this.getSize(); return (Math.abs(offset.x) <= size.x * m) && - (Math.abs(offset.y) <= size.y * m); + (Math.abs(offset.y) <= size.y * m); } }); diff --git a/src/map/ext/Map.Control.js b/src/map/ext/Map.Control.js index c0d6f178..b1bf085a 100644 --- a/src/map/ext/Map.Control.js +++ b/src/map/ext/Map.Control.js @@ -13,13 +13,12 @@ L.Map.include({ var corners = this._controlCorners = {}, l = 'leaflet-', container = this._controlContainer = - L.DomUtil.create('div', l + 'control-container', this._container); + L.DomUtil.create('div', l + 'control-container', this._container); function createCorner(vSide, hSide) { var className = l + vSide + ' ' + l + hSide; - corners[vSide + hSide] = - L.DomUtil.create('div', className, container); + corners[vSide + hSide] = L.DomUtil.create('div', className, container); } createCorner('top', 'left'); diff --git a/src/map/ext/Map.Geolocation.js b/src/map/ext/Map.Geolocation.js index bf33f7fa..32501e89 100644 --- a/src/map/ext/Map.Geolocation.js +++ b/src/map/ext/Map.Geolocation.js @@ -28,7 +28,8 @@ L.Map.include({ onError = L.Util.bind(this._handleGeolocationError, this); if (options.watch) { - this._locationWatchId = navigator.geolocation.watchPosition(onResponse, onError, options); + this._locationWatchId = + navigator.geolocation.watchPosition(onResponse, onError, options); } else { navigator.geolocation.getCurrentPosition(onResponse, onError, options); } @@ -44,9 +45,9 @@ L.Map.include({ _handleGeolocationError: function (error) { var c = error.code, - message = error.message || - (c === 1 ? "permission denied" : - (c === 2 ? "position unavailable" : "timeout")); + message = error.message || + (c === 1 ? "permission denied" : + (c === 2 ? "position unavailable" : "timeout")); if (this._locationOptions.setView && !this._loaded) { this.fitWorld(); @@ -60,17 +61,17 @@ L.Map.include({ _handleGeolocationResponse: function (pos) { var latAccuracy = 180 * pos.coords.accuracy / 4e7, - lngAccuracy = latAccuracy * 2, + lngAccuracy = latAccuracy * 2, - lat = pos.coords.latitude, - lng = pos.coords.longitude, - latlng = new L.LatLng(lat, lng), + lat = pos.coords.latitude, + lng = pos.coords.longitude, + latlng = new L.LatLng(lat, lng), - sw = new L.LatLng(lat - latAccuracy, lng - lngAccuracy), - ne = new L.LatLng(lat + latAccuracy, lng + lngAccuracy), - bounds = new L.LatLngBounds(sw, ne), + sw = new L.LatLng(lat - latAccuracy, lng - lngAccuracy), + ne = new L.LatLng(lat + latAccuracy, lng + lngAccuracy), + bounds = new L.LatLngBounds(sw, ne), - options = this._locationOptions; + options = this._locationOptions; if (options.setView) { var zoom = Math.min(this.getBoundsZoom(bounds), options.maxZoom); diff --git a/src/map/ext/Map.Popup.js b/src/map/ext/Map.Popup.js index c9e1752e..e077c529 100644 --- a/src/map/ext/Map.Popup.js +++ b/src/map/ext/Map.Popup.js @@ -6,8 +6,8 @@ L.Map.include({ this._popup = popup; return this - .addLayer(popup) - .fire('popupopen', {popup: this._popup}); + .addLayer(popup) + .fire('popupopen', {popup: this._popup}); }, closePopup: function () { @@ -16,4 +16,4 @@ L.Map.include({ } return this; } -}); \ No newline at end of file +}); diff --git a/src/map/handler/Map.BoxZoom.js b/src/map/handler/Map.BoxZoom.js index 7d8b5851..204c8299 100644 --- a/src/map/handler/Map.BoxZoom.js +++ b/src/map/handler/Map.BoxZoom.js @@ -35,23 +35,23 @@ L.Map.BoxZoom = L.Handler.extend({ this._container.style.cursor = 'crosshair'; L.DomEvent - .on(document, 'mousemove', this._onMouseMove, this) - .on(document, 'mouseup', this._onMouseUp, this) - .preventDefault(e); - + .on(document, 'mousemove', this._onMouseMove, this) + .on(document, 'mouseup', this._onMouseUp, this) + .preventDefault(e); + this._map.fire("boxzoomstart"); }, _onMouseMove: function (e) { var startPoint = this._startLayerPoint, - box = this._box, + box = this._box, - layerPoint = this._map.mouseEventToLayerPoint(e), - offset = layerPoint.subtract(startPoint), + layerPoint = this._map.mouseEventToLayerPoint(e), + offset = layerPoint.subtract(startPoint), - newPos = new L.Point( - Math.min(layerPoint.x, startPoint.x), - Math.min(layerPoint.y, startPoint.y)); + newPos = new L.Point( + Math.min(layerPoint.x, startPoint.x), + Math.min(layerPoint.y, startPoint.y)); L.DomUtil.setPosition(box, newPos); @@ -67,18 +67,18 @@ L.Map.BoxZoom = L.Handler.extend({ L.DomUtil.enableTextSelection(); L.DomEvent - .off(document, 'mousemove', this._onMouseMove) - .off(document, 'mouseup', this._onMouseUp); + .off(document, 'mousemove', this._onMouseMove) + .off(document, 'mouseup', this._onMouseUp); var map = this._map, - layerPoint = map.mouseEventToLayerPoint(e); + layerPoint = map.mouseEventToLayerPoint(e), - var bounds = new L.LatLngBounds( - map.layerPointToLatLng(this._startLayerPoint), - map.layerPointToLatLng(layerPoint)); + bounds = new L.LatLngBounds( + map.layerPointToLatLng(this._startLayerPoint), + map.layerPointToLatLng(layerPoint)); map.fitBounds(bounds); - + map.fire("boxzoomend", { boxZoomBounds: bounds }); diff --git a/src/map/handler/Map.Drag.js b/src/map/handler/Map.Drag.js index a97c20a8..c96187d7 100644 --- a/src/map/handler/Map.Drag.js +++ b/src/map/handler/Map.Drag.js @@ -19,9 +19,9 @@ L.Map.mergeOptions({ L.Map.Drag = L.Handler.extend({ addHooks: function () { if (!this._draggable) { - var options = this._map.options; + var map = this._map; - this._draggable = new L.Draggable(this._map._mapPane, this._map._container, options.longPress); + this._draggable = new L.Draggable(map._mapPane, map._container, map.options.longPress); this._draggable.on({ 'dragstart': this._onDragStart, @@ -29,9 +29,9 @@ L.Map.Drag = L.Handler.extend({ 'dragend': this._onDragEnd }, this); - if (options.worldCopyJump) { + if (map.options.worldCopyJump) { this._draggable.on('predrag', this._onPreDrag, this); - this._map.on('viewreset', this._onViewReset, this); + map.on('viewreset', this._onViewReset, this); } } this._draggable.enable(); @@ -53,8 +53,8 @@ L.Map.Drag = L.Handler.extend({ } map - .fire('movestart') - .fire('dragstart'); + .fire('movestart') + .fire('dragstart'); if (map.options.inertia) { this._positions = []; @@ -77,13 +77,13 @@ L.Map.Drag = L.Handler.extend({ } this._map - .fire('move') - .fire('drag'); + .fire('move') + .fire('drag'); }, _onViewReset: function () { var pxCenter = this._map.getSize()._divideBy(2), - pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0, 0)); + pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0, 0)); this._initialWorldOffset = pxWorldCenter.subtract(pxCenter).x; this._worldWidth = this._map.project(new L.LatLng(0, 180)).x; @@ -92,25 +92,25 @@ L.Map.Drag = L.Handler.extend({ _onPreDrag: function () { // TODO refactor to be able to adjust map pane position after zoom var map = this._map, - worldWidth = this._worldWidth, - halfWidth = Math.round(worldWidth / 2), - dx = this._initialWorldOffset, - x = this._draggable._newPos.x, - newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx, - newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx, - newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2; + worldWidth = this._worldWidth, + halfWidth = Math.round(worldWidth / 2), + dx = this._initialWorldOffset, + x = this._draggable._newPos.x, + newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx, + newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx, + newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2; this._draggable._newPos.x = newX; }, _onDragEnd: function () { var map = this._map, - options = map.options, - delay = +new Date() - this._lastTime, + options = map.options, + delay = +new Date() - this._lastTime, - noInertia = !options.inertia || - delay > options.inertiaThreshold || - this._positions[0] === undefined; + noInertia = !options.inertia || + delay > options.inertiaThreshold || + !this._positions[0]; if (noInertia) { map.fire('moveend'); @@ -118,20 +118,20 @@ L.Map.Drag = L.Handler.extend({ } else { var direction = this._lastPos.subtract(this._positions[0]), - duration = (this._lastTime + delay - this._times[0]) / 1000, + duration = (this._lastTime + delay - this._times[0]) / 1000, - speedVector = direction.multiplyBy(0.58 / duration), - speed = speedVector.distanceTo(new L.Point(0, 0)), + speedVector = direction.multiplyBy(0.58 / duration), + speed = speedVector.distanceTo(new L.Point(0, 0)), - limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), - limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), + limitedSpeed = Math.min(options.inertiaMaxSpeed, speed), + limitedSpeedVector = speedVector.multiplyBy(limitedSpeed / speed), - decelerationDuration = limitedSpeed / options.inertiaDeceleration, - offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round(); + decelerationDuration = limitedSpeed / options.inertiaDeceleration, + offset = limitedSpeedVector.multiplyBy(-decelerationDuration / 2).round(); - L.Util.requestAnimFrame(L.Util.bind(function () { - this._map.panBy(offset, decelerationDuration); - }, this)); + L.Util.requestAnimFrame(function () { + map.panBy(offset, decelerationDuration); + }); } map.fire('dragend'); diff --git a/src/map/handler/Map.Keyboard.js b/src/map/handler/Map.Keyboard.js index 352b0a12..be7ad73e 100644 --- a/src/map/handler/Map.Keyboard.js +++ b/src/map/handler/Map.Keyboard.js @@ -32,27 +32,28 @@ L.Map.Keyboard = L.Handler.extend({ } L.DomEvent - .addListener(container, 'focus', this._onFocus, this) - .addListener(container, 'blur', this._onBlur, this) - .addListener(container, 'mousedown', this._onMouseDown, this); + .addListener(container, 'focus', this._onFocus, this) + .addListener(container, 'blur', this._onBlur, this) + .addListener(container, 'mousedown', this._onMouseDown, this); this._map - .on('focus', this._addHooks, this) - .on('blur', this._removeHooks, this); + .on('focus', this._addHooks, this) + .on('blur', this._removeHooks, this); }, removeHooks: function () { this._removeHooks(); var container = this._map._container; + L.DomEvent - .removeListener(container, 'focus', this._onFocus, this) - .removeListener(container, 'blur', this._onBlur, this) - .removeListener(container, 'mousedown', this._onMouseDown, this); + .removeListener(container, 'focus', this._onFocus, this) + .removeListener(container, 'blur', this._onBlur, this) + .removeListener(container, 'mousedown', this._onMouseDown, this); this._map - .off('focus', this._addHooks, this) - .off('blur', this._removeHooks, this); + .off('focus', this._addHooks, this) + .off('blur', this._removeHooks, this); }, _onMouseDown: function () { @@ -92,7 +93,7 @@ L.Map.Keyboard = L.Handler.extend({ _setZoomOffset: function (zoom) { var keys = this._zoomKeys = {}, - codes = this.keyCodes, + codes = this.keyCodes, i, len; for (i = 0, len = codes.zoomIn.length; i < len; i++) { diff --git a/src/map/handler/Map.ScrollWheelZoom.js b/src/map/handler/Map.ScrollWheelZoom.js index f3d2033f..7e2a215a 100644 --- a/src/map/handler/Map.ScrollWheelZoom.js +++ b/src/map/handler/Map.ScrollWheelZoom.js @@ -1,5 +1,5 @@ /* - * L.Handler.ScrollWheelZoom is used internally by L.Map to enable mouse scroll wheel zooming on the map. + * L.Handler.ScrollWheelZoom is used by L.Map to enable mouse scroll wheel zoom on the map. */ L.Map.mergeOptions({ @@ -37,8 +37,8 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ _performZoom: function () { var map = this._map, - delta = Math.round(this._delta), - zoom = map.getZoom(); + delta = Math.round(this._delta), + zoom = map.getZoom(); delta = Math.max(Math.min(delta, 4), -4); delta = map._limitZoom(zoom + delta) - zoom; @@ -50,17 +50,17 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ if (!delta) { return; } var newZoom = zoom + delta, - newCenter = this._getCenterForScrollWheelZoom(newZoom); + newCenter = this._getCenterForScrollWheelZoom(newZoom); map.setView(newCenter, newZoom); }, _getCenterForScrollWheelZoom: function (newZoom) { var map = this._map, - scale = map.getZoomScale(newZoom), - viewHalf = map.getSize()._divideBy(2), - centerOffset = this._lastMousePos._subtract(viewHalf)._multiplyBy(1 - 1 / scale), - newCenterPoint = map._getTopLeftPoint()._add(viewHalf)._add(centerOffset); + scale = map.getZoomScale(newZoom), + viewHalf = map.getSize()._divideBy(2), + centerOffset = this._lastMousePos._subtract(viewHalf)._multiplyBy(1 - 1 / scale), + newCenterPoint = map._getTopLeftPoint()._add(viewHalf)._add(centerOffset); return map.unproject(newCenterPoint); } diff --git a/src/map/handler/Map.TouchZoom.js b/src/map/handler/Map.TouchZoom.js index 09f064f3..02c6b390 100644 --- a/src/map/handler/Map.TouchZoom.js +++ b/src/map/handler/Map.TouchZoom.js @@ -1,5 +1,5 @@ /* - * L.Handler.TouchZoom is used internally by L.Map to add touch-zooming on Webkit-powered mobile browsers. + * L.Handler.TouchZoom is used by L.Map to add pinch zoom on supported mobile browsers. */ L.Map.mergeOptions({ @@ -21,8 +21,8 @@ L.Map.TouchZoom = L.Handler.extend({ if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; } var p1 = map.mouseEventToLayerPoint(e.touches[0]), - p2 = map.mouseEventToLayerPoint(e.touches[1]), - viewCenter = map._getCenterLayerPoint(); + p2 = map.mouseEventToLayerPoint(e.touches[1]), + viewCenter = map._getCenterLayerPoint(); this._startCenter = p1.add(p2)._divideBy(2); this._startDist = p1.distanceTo(p2); @@ -37,8 +37,8 @@ L.Map.TouchZoom = L.Handler.extend({ } L.DomEvent - .on(document, 'touchmove', this._onTouchMove, this) - .on(document, 'touchend', this._onTouchEnd, this); + .on(document, 'touchmove', this._onTouchMove, this) + .on(document, 'touchend', this._onTouchEnd, this); L.DomEvent.preventDefault(e); }, @@ -49,7 +49,7 @@ L.Map.TouchZoom = L.Handler.extend({ var map = this._map; var p1 = map.mouseEventToLayerPoint(e.touches[0]), - p2 = map.mouseEventToLayerPoint(e.touches[1]); + p2 = map.mouseEventToLayerPoint(e.touches[1]); this._scale = p1.distanceTo(p2) / this._startDist; this._delta = p1._add(p2)._divideBy(2)._subtract(this._startCenter); @@ -60,23 +60,24 @@ L.Map.TouchZoom = L.Handler.extend({ L.DomUtil.addClass(map._mapPane, 'leaflet-zoom-anim leaflet-touching'); map - .fire('movestart') - .fire('zoomstart') - ._prepareTileBg(); + .fire('movestart') + .fire('zoomstart') + ._prepareTileBg(); this._moved = true; } L.Util.cancelAnimFrame(this._animRequest); - this._animRequest = L.Util.requestAnimFrame(this._updateOnMove, this, true, this._map._container); + this._animRequest = L.Util.requestAnimFrame( + this._updateOnMove, this, true, this._map._container); L.DomEvent.preventDefault(e); }, _updateOnMove: function () { var map = this._map, - origin = this._getScaleOrigin(), - center = map.layerPointToLatLng(origin); + origin = this._getScaleOrigin(), + center = map.layerPointToLatLng(origin); map.fire('zoomanim', { center: center, @@ -87,8 +88,8 @@ L.Map.TouchZoom = L.Handler.extend({ // it didn't count the origin on the first touch-zoom but worked correctly afterwards map._tileBg.style[L.DomUtil.TRANSFORM] = - L.DomUtil.getTranslateString(this._delta) + ' ' + - L.DomUtil.getScaleString(this._scale, this._startCenter); + L.DomUtil.getTranslateString(this._delta) + ' ' + + L.DomUtil.getScaleString(this._scale, this._startCenter); }, _onTouchEnd: function (e) { @@ -100,16 +101,18 @@ L.Map.TouchZoom = L.Handler.extend({ L.DomUtil.removeClass(map._mapPane, 'leaflet-touching'); L.DomEvent - .off(document, 'touchmove', this._onTouchMove) - .off(document, 'touchend', this._onTouchEnd); + .off(document, 'touchmove', this._onTouchMove) + .off(document, 'touchend', this._onTouchEnd); var origin = this._getScaleOrigin(), - center = map.layerPointToLatLng(origin), + center = map.layerPointToLatLng(origin), - oldZoom = map.getZoom(), - floatZoomDelta = map.getScaleZoom(this._scale) - oldZoom, - roundZoomDelta = (floatZoomDelta > 0 ? Math.ceil(floatZoomDelta) : Math.floor(floatZoomDelta)), - zoom = map._limitZoom(oldZoom + roundZoomDelta); + oldZoom = map.getZoom(), + floatZoomDelta = map.getScaleZoom(this._scale) - oldZoom, + roundZoomDelta = (floatZoomDelta > 0 ? + Math.ceil(floatZoomDelta) : Math.floor(floatZoomDelta)), + + zoom = map._limitZoom(oldZoom + roundZoomDelta); map.fire('zoomanim', { center: center,