From 1f08c6579484268ae499ad9c9340cf1370aa8f60 Mon Sep 17 00:00:00 2001 From: danzel Date: Wed, 2 Apr 2014 10:40:33 +1300 Subject: [PATCH 01/57] Round point so that circles work again :) --- src/layer/vector/SVG.VML.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/vector/SVG.VML.js b/src/layer/vector/SVG.VML.js index 2cc1d244..95b3735b 100644 --- a/src/layer/vector/SVG.VML.js +++ b/src/layer/vector/SVG.VML.js @@ -106,7 +106,7 @@ L.SVG.include(!L.Browser.vml ? {} : { }, _updateCircle: function (layer) { - var p = layer._point, + var p = layer._point.round(), r = Math.round(layer._radius), r2 = Math.round(layer._radiusY || r); From c5e781b6a0c9ab3a0b49a535de91547673e22ae0 Mon Sep 17 00:00:00 2001 From: Robin van Baalen Date: Wed, 2 Apr 2014 12:23:15 -0700 Subject: [PATCH 02/57] Fix for #2606: Cannot read property x of undefined Only setPosition if _getPos actually returns a valid position to this._newPos --- src/dom/PosAnimation.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dom/PosAnimation.js b/src/dom/PosAnimation.js index f5b00da5..a3ee932c 100644 --- a/src/dom/PosAnimation.js +++ b/src/dom/PosAnimation.js @@ -32,8 +32,11 @@ L.PosAnimation = L.Evented.extend({ // if we just removed the transition property, the element would jump to its final position, // so we need to make it stay at the current position + // Only setPosition if _getPos actually returns a valid position. this._newPos = this._getPos(); - L.DomUtil.setPosition(this._el, this._newPos); + if (this._newPos) { + L.DomUtil.setPosition(this._el, this._newPos); + } this._onTransitionEnd(); L.Util.falseFn(this._el.offsetWidth); // force reflow in case we are about to start a new animation From 7e40b07d7dd1920cb9a15cfee91c13accd49c386 Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 7 Apr 2014 13:51:03 +1200 Subject: [PATCH 03/57] Try not set a huge translate when a pan happens. Fixes #2602 --- src/layer/Layer.js | 8 ++++---- src/map/anim/Map.PanAnimation.js | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/layer/Layer.js b/src/layer/Layer.js index 32b2c44b..a0f3cb30 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -34,15 +34,15 @@ L.Layer = L.Evented.extend({ this._map = map; this._zoomAnimated = map._zoomAnimated; - this.onAdd(map); + if (this.getEvents) { + map.on(this.getEvents(), this); + } if (this.getAttribution && this._map.attributionControl) { this._map.attributionControl.addAttribution(this.getAttribution()); } - if (this.getEvents) { - map.on(this.getEvents(), this); - } + this.onAdd(map); this.fire('add'); map.fire('layeradd', {layer: this}); diff --git a/src/map/anim/Map.PanAnimation.js b/src/map/anim/Map.PanAnimation.js index 777ea7b9..160de06b 100644 --- a/src/map/anim/Map.PanAnimation.js +++ b/src/map/anim/Map.PanAnimation.js @@ -46,6 +46,10 @@ L.Map.include({ if (!offset.x && !offset.y) { return this; } + //If we pan too far then chrome gets issues with tiles and makes them disappear or appear in the wrong place (slightly offset) #2602 + if (Math.abs(offset.x) > 10000 || Math.abs(offset.y) > 10000) { + return this._resetView(map.unproject(map.project(map.getCenter()).add(offset)), this.getZoom()); + } if (!this._panAnim) { this._panAnim = new L.PosAnimation(); From 7d98b2e6d97af5f3bde768f4e8068d3797312f8e Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 7 Apr 2014 16:11:33 +1200 Subject: [PATCH 04/57] Fix the warnings --- src/map/anim/Map.PanAnimation.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/map/anim/Map.PanAnimation.js b/src/map/anim/Map.PanAnimation.js index 160de06b..c7577acc 100644 --- a/src/map/anim/Map.PanAnimation.js +++ b/src/map/anim/Map.PanAnimation.js @@ -46,9 +46,10 @@ L.Map.include({ if (!offset.x && !offset.y) { return this; } - //If we pan too far then chrome gets issues with tiles and makes them disappear or appear in the wrong place (slightly offset) #2602 + //If we pan too far then chrome gets issues with tiles + // and makes them disappear or appear in the wrong place (slightly offset) #2602 if (Math.abs(offset.x) > 10000 || Math.abs(offset.y) > 10000) { - return this._resetView(map.unproject(map.project(map.getCenter()).add(offset)), this.getZoom()); + return this._resetView(this.unproject(this.project(this.getCenter()).add(offset)), this.getZoom()); } if (!this._panAnim) { From 3257038d70ba0753e07dde7eaa035e53ad7027ba Mon Sep 17 00:00:00 2001 From: danzel Date: Tue, 8 Apr 2014 09:30:25 +1200 Subject: [PATCH 05/57] Change how we work out if a pan is ok. --- src/map/anim/Map.PanAnimation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/anim/Map.PanAnimation.js b/src/map/anim/Map.PanAnimation.js index c7577acc..8de67e3c 100644 --- a/src/map/anim/Map.PanAnimation.js +++ b/src/map/anim/Map.PanAnimation.js @@ -48,7 +48,7 @@ L.Map.include({ } //If we pan too far then chrome gets issues with tiles // and makes them disappear or appear in the wrong place (slightly offset) #2602 - if (Math.abs(offset.x) > 10000 || Math.abs(offset.y) > 10000) { + if (options.animate !== true && !this.getSize().contains(offset)) { return this._resetView(this.unproject(this.project(this.getCenter()).add(offset)), this.getZoom()); } From a61fcd4226cd488ffba0014873a3a87443e91be9 Mon Sep 17 00:00:00 2001 From: Eric Theise Date: Wed, 9 Apr 2014 17:23:28 -0400 Subject: [PATCH 06/57] Update GridLayer.js --- src/layer/tile/GridLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index dec97f1c..7a2f9913 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -340,7 +340,7 @@ L.GridLayer = L.Layer.extend({ return coords.x + ':' + coords.y; }, - // converts tile cache key to coordiantes + // converts tile cache key to coordinates _keyToTileCoords: function (key) { var kArr = key.split(':'), x = parseInt(kArr[0], 10), From 21b14fd91dcaf6f1c2e418348781a34ed1844286 Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Wed, 9 Apr 2014 15:54:02 -0700 Subject: [PATCH 07/57] Allow access to L.TileLayer imagedata See https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image. Seemed like such a small change it could maybe go in core instead of writing an entire plugin for it, but I also doubt it's a common use case. I use this to pull in data that's stored in tiles (e.g. elevation data, soil composition). --- src/layer/tile/TileLayer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index 276f50f2..b7128825 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -55,7 +55,8 @@ L.TileLayer = L.GridLayer.extend({ tile.onload = L.bind(this._tileOnLoad, this, done, tile); tile.onerror = L.bind(this._tileOnError, this, done, tile); - + tile.crossOrigin = ''; + /* Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons http://www.w3.org/TR/WCAG20-TECHS/H67 From 3c86f6cca47e87301fb379a6359c43d03a1b1864 Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Thu, 10 Apr 2014 11:16:30 -0700 Subject: [PATCH 08/57] tile CORS headers now a layer option --- src/layer/tile/TileLayer.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index b7128825..f5bfc2eb 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -17,6 +17,7 @@ L.TileLayer = L.GridLayer.extend({ tms: , zoomReverse: , detectRetina: , + crossOrigin: , */ }, @@ -55,7 +56,10 @@ L.TileLayer = L.GridLayer.extend({ tile.onload = L.bind(this._tileOnLoad, this, done, tile); tile.onerror = L.bind(this._tileOnError, this, done, tile); - tile.crossOrigin = ''; + + if (this.options.crossOrigin) { + tile.crossOrigin = ''; + } /* Alt tag is set to empty string to keep screen readers from reading URL and for compliance reasons From aa073a260f5ba1efdac1b0b295e780b559c97122 Mon Sep 17 00:00:00 2001 From: Benny Lichtner Date: Fri, 11 Apr 2014 12:26:21 -0700 Subject: [PATCH 09/57] removed trailing whitespace --- src/layer/tile/TileLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index f5bfc2eb..5e6d996e 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -58,7 +58,7 @@ L.TileLayer = L.GridLayer.extend({ tile.onerror = L.bind(this._tileOnError, this, done, tile); if (this.options.crossOrigin) { - tile.crossOrigin = ''; + tile.crossOrigin = ''; } /* From 2808d0f0162d218ec5a0e2e536f6ea12f733372a Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 28 Apr 2014 15:59:30 +0300 Subject: [PATCH 10/57] fix error dragging outside of window in FF, close #2610 --- src/dom/Draggable.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index a6650ec6..466dded2 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -90,7 +90,9 @@ L.Draggable = L.Evented.extend({ this._startPos = L.DomUtil.getPosition(this._element).subtract(offset); L.DomUtil.addClass(document.body, 'leaflet-dragging'); - L.DomUtil.addClass(e.target || e.srcElement, 'leaflet-drag-target'); + + this._lastTarget = e.target || e.srcElement; + L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target'); } this._newPos = this._startPos.add(offset); @@ -108,7 +110,11 @@ L.Draggable = L.Evented.extend({ _onUp: function (e) { L.DomUtil.removeClass(document.body, 'leaflet-dragging'); - L.DomUtil.removeClass(e.target || e.srcElement, 'leaflet-drag-target'); + + if (this._lastTarget) { + L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target'); + this._lastTarget = null; + } for (var i in L.Draggable.MOVE) { L.DomEvent From ddce7b39774c79e3cdb9b8b6390640ee6bb5f22b Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 28 Apr 2014 15:59:30 +0300 Subject: [PATCH 11/57] fix error dragging outside of window in FF, close #2610 --- src/dom/Draggable.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dom/Draggable.js b/src/dom/Draggable.js index a6650ec6..c743c11c 100644 --- a/src/dom/Draggable.js +++ b/src/dom/Draggable.js @@ -90,7 +90,9 @@ L.Draggable = L.Evented.extend({ this._startPos = L.DomUtil.getPosition(this._element).subtract(offset); L.DomUtil.addClass(document.body, 'leaflet-dragging'); - L.DomUtil.addClass(e.target || e.srcElement, 'leaflet-drag-target'); + + this._lastTarget = e.target || e.srcElement; + L.DomUtil.addClass(this._lastTarget, 'leaflet-drag-target'); } this._newPos = this._startPos.add(offset); @@ -106,9 +108,13 @@ L.Draggable = L.Evented.extend({ this.fire('drag'); }, - _onUp: function (e) { + _onUp: function () { L.DomUtil.removeClass(document.body, 'leaflet-dragging'); - L.DomUtil.removeClass(e.target || e.srcElement, 'leaflet-drag-target'); + + if (this._lastTarget) { + L.DomUtil.removeClass(this._lastTarget, 'leaflet-drag-target'); + this._lastTarget = null; + } for (var i in L.Draggable.MOVE) { L.DomEvent From 3696926bef430a5f27e1a45ece1281e45e00b833 Mon Sep 17 00:00:00 2001 From: Hans Kristian Flaatten Date: Wed, 30 Apr 2014 19:58:30 +0200 Subject: [PATCH 12/57] Fix #2658 ZoomBox not disappearing on right click --- src/map/handler/Map.BoxZoom.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/map/handler/Map.BoxZoom.js b/src/map/handler/Map.BoxZoom.js index cad8a236..c3eaefaf 100644 --- a/src/map/handler/Map.BoxZoom.js +++ b/src/map/handler/Map.BoxZoom.js @@ -27,22 +27,28 @@ L.Map.BoxZoom = L.Handler.extend({ }, _onMouseDown: function (e) { - this._moved = false; - if (!e.shiftKey || ((e.which !== 1) && (e.button !== 1))) { return false; } + this._moved = false; + L.DomUtil.disableTextSelection(); L.DomUtil.disableImageDrag(); this._startPoint = this._map.mouseEventToContainerPoint(e); L.DomEvent.on(document, { + contextmenu: this._onPreventDefault, mousemove: this._onMouseMove, - mouseup: this._onMouseUp, - keydown: this._onKeyDown + mouseup: this._onMouseUp, + keydown: this._onKeyDown }, this); }, + _onPreventDefault: function (e) { + L.DomEvent.preventDefault(e); + L.DomEvent.stopPropagation(e); + }, + _onMouseMove: function (e) { if (!this._moved) { this._moved = true; @@ -74,13 +80,15 @@ L.Map.BoxZoom = L.Handler.extend({ L.DomUtil.enableImageDrag(); L.DomEvent.off(document, { + contextmenu: this._onPreventDefault, mousemove: this._onMouseMove, - mouseup: this._onMouseUp, - keydown: this._onKeyDown + mouseup: this._onMouseUp, + keydown: this._onKeyDown }, this); }, - _onMouseUp: function () { + _onMouseUp: function (e) { + if ((e.which !== 1) && (e.button !== 1)) { return false; } this._finish(); From 5dc4c1ade1220369105306b4818d5fd6bc896928 Mon Sep 17 00:00:00 2001 From: Hans Kristian Flaatten Date: Wed, 30 Apr 2014 20:55:57 +0200 Subject: [PATCH 13/57] Replace custom _onPreventDefault function --- src/map/handler/Map.BoxZoom.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/map/handler/Map.BoxZoom.js b/src/map/handler/Map.BoxZoom.js index c3eaefaf..fcca466c 100644 --- a/src/map/handler/Map.BoxZoom.js +++ b/src/map/handler/Map.BoxZoom.js @@ -37,18 +37,13 @@ L.Map.BoxZoom = L.Handler.extend({ this._startPoint = this._map.mouseEventToContainerPoint(e); L.DomEvent.on(document, { - contextmenu: this._onPreventDefault, + contextmenu: L.DomEvent.stop, mousemove: this._onMouseMove, mouseup: this._onMouseUp, keydown: this._onKeyDown }, this); }, - _onPreventDefault: function (e) { - L.DomEvent.preventDefault(e); - L.DomEvent.stopPropagation(e); - }, - _onMouseMove: function (e) { if (!this._moved) { this._moved = true; @@ -80,7 +75,7 @@ L.Map.BoxZoom = L.Handler.extend({ L.DomUtil.enableImageDrag(); L.DomEvent.off(document, { - contextmenu: this._onPreventDefault, + contextmenu: L.DomEvent.stop, mousemove: this._onMouseMove, mouseup: this._onMouseUp, keydown: this._onKeyDown From 9f48f357ae62427f34de9ce7b9367cbbc7615c6d Mon Sep 17 00:00:00 2001 From: cebence Date: Wed, 21 May 2014 13:43:29 +0200 Subject: [PATCH 14/57] Fixing URL template issue #2695 --- src/layer/tile/TileLayer.WMS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/TileLayer.WMS.js b/src/layer/tile/TileLayer.WMS.js index 48da0ab1..b7386373 100644 --- a/src/layer/tile/TileLayer.WMS.js +++ b/src/layer/tile/TileLayer.WMS.js @@ -57,7 +57,7 @@ L.TileLayer.WMS = L.TileLayer.extend({ [se.y, nw.x, nw.y, se.x] : [nw.x, se.y, se.x, nw.y]).join(','), - url = L.Util.template(this._url, {s: this._getSubdomain(coords)}); + url = L.TileLayer.prototype.getTileUrl.call(this, coords); return url + L.Util.getParamString(this.wmsParams, url, true) + '&BBOX=' + bbox; }, From 433ff94110aa4b150f4b283cb381ca55c169ce14 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 23 May 2014 12:23:46 +0300 Subject: [PATCH 15/57] add 0.7.3 changelog --- CHANGELOG.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56fb04e..5cd50f42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -133,7 +133,6 @@ These changes were targeted at removing any hardcoded projection-specific logic * Fixed `ImageOverlay` mercator distortion on lower zoom levels. * Fixed a bug where layers didn't fire `popupopen` and `popupclose` events when manually creating a popup object and passing it to `bindPopup`. [#2354](https://github.com/Leaflet/Leaflet/issues/2354) * Fixed box-zoom overlay appearing under markers. [#1813](https://github.com/Leaflet/Leaflet/issues/1813) -* Fixed an issue where clicks on Android were skipped when happened too fast. [#2303](https://github.com/Leaflet/Leaflet/issues/2303) ### Misc improvements @@ -143,6 +142,19 @@ These changes were targeted at removing any hardcoded projection-specific logic * Added reference to Leaflet CSS in `package.json` (by [@bclinkinbeard](https://github.com/bclinkinbeard)). [#2432](https://github.com/Leaflet/Leaflet/pull/2432) +## 0.7.3 (May 23, 2014) + +* Added proper **bower** and **component** support (by [@calvinmetcalf](https://github.com/calvinmetcalf)). [#2561](https://github.com/Leaflet/Leaflet/pull/2561) [#1903](https://github.com/Leaflet/Leaflet/issues/1903) +* Fixed a bug where dragging the map outside the window caused an error on FF. [#2610](https://github.com/Leaflet/Leaflet/issues/2610) +* Fixed a bug where some taps on Android where not working, often falsely perceived as drags (by [@axefrog](https://github.com/axefrog)). [#2503](https://github.com/Leaflet/Leaflet/pull/2503) +* Fixed a bug where clicks on Android were skipped when happened too fast. [#2303](https://github.com/Leaflet/Leaflet/issues/2303) +* Fixed a bug where calling `setView` (or similar methods) several times in succession could freeze the map. [#2521](https://github.com/Leaflet/Leaflet/issues/2521) [#2236](https://github.com/Leaflet/Leaflet/issues/2236) [#2485](https://github.com/Leaflet/Leaflet/issues/2485) +* Fixed a bug where `Control.Layers` wasn't properly removed (by [@jack-kerouac](https://github.com/jack-kerouac)). [#2569](https://github.com/Leaflet/Leaflet/pull/2569) +* Fixed a bug that caused `TileLayer` `load` event not to fire properly. [#2510](https://github.com/Leaflet/Leaflet/issues/2510) +* Fixed Canvas-based paths not triggering `remove` event when removed (by @adimitrov). [#2486](https://github.com/Leaflet/Leaflet/pull/2486) +* Fixed a bug where you could end up with fractional zoom after pinch-zooming in some cases (by [@danzel](https://github.com/danzel). [#2400](https://github.com/Leaflet/Leaflet/pull/2400) [#1943](https://github.com/Leaflet/Leaflet/issues/1934) + + ## 0.7.2 (January 17, 2014) * Fixed a bug that appeared with **Chrome 32 update** that made all **mouse events shifted on scrolled pages**. [#2352](https://github.com/Leaflet/Leaflet/issues/2352) From 2885f2bf45867ca406206aa1c4101ee6723a6200 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 23 May 2014 23:52:38 +0300 Subject: [PATCH 16/57] upgrade deps --- package.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 802f5d23..33bf5f43 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,18 @@ "version": "0.7.0", "description": "JavaScript library for mobile-friendly interactive maps", "devDependencies": { - "jake": "~0.7.9", - "jshint": "~2.4.4", + "jake": "~0.7.14", + "jshint": "~2.5.1", "uglify-js": "~2.4.13", - "mocha": "~1.17.1", + "mocha": "~1.19.0", "happen": "~0.1.3", - "karma": "~0.12.0", - "karma-mocha": "~0.1.1", - "karma-coverage": "~0.2.0", - "karma-phantomjs-launcher": "^0.1.2", - "karma-chrome-launcher": "^0.1.2", - "tin": "^0.4.0", - "copyfiles": "0.0.1" + "karma": "~0.12.16", + "karma-mocha": "~0.1.3", + "karma-coverage": "~0.2.3", + "karma-phantomjs-launcher": "^0.1.4", + "karma-chrome-launcher": "^0.1.4", + "tin": "^0.5.0", + "copyfiles": "0.1.0" }, "main": "dist/leaflet-src.js", "style": "dist/leaflet.css", From 53048500b1a41d049f3a6583ba261fbc80c4f2ca Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 26 May 2014 17:10:09 +0300 Subject: [PATCH 17/57] fix vector rendering regression --- src/layer/Layer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layer/Layer.js b/src/layer/Layer.js index a0f3cb30..32b2c44b 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -34,15 +34,15 @@ L.Layer = L.Evented.extend({ this._map = map; this._zoomAnimated = map._zoomAnimated; - if (this.getEvents) { - map.on(this.getEvents(), this); - } + this.onAdd(map); if (this.getAttribution && this._map.attributionControl) { this._map.attributionControl.addAttribution(this.getAttribution()); } - this.onAdd(map); + if (this.getEvents) { + map.on(this.getEvents(), this); + } this.fire('add'); map.fire('layeradd', {layer: this}); From 1d0dc6dcad00321acde0fd41b57922343b6b415e Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 26 May 2014 18:47:11 +0300 Subject: [PATCH 18/57] add and use L.DomUtil.empty, close #2600 --- src/control/Control.Layers.js | 4 ++-- src/dom/DomUtil.js | 6 ++++++ src/layer/tile/GridLayer.js | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/control/Control.Layers.js b/src/control/Control.Layers.js index 3e8417ff..f5234a00 100644 --- a/src/control/Control.Layers.js +++ b/src/control/Control.Layers.js @@ -124,8 +124,8 @@ L.Control.Layers = L.Control.extend({ _update: function () { if (!this._container) { return; } - this._baseLayersList.innerHTML = ''; - this._overlaysList.innerHTML = ''; + L.DomUtil.empty(this._baseLayersList); + L.DomUtil.empty(this._overlaysList); var baseLayersPresent, overlaysPresent, i, obj; diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index ba77e735..c13c41e7 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -38,6 +38,12 @@ L.DomUtil = { } }, + empty: function (el) { + while (el.firstChild) { + el.removeChild(el.firstChild); + } + }, + toFront: function (el) { el.parentNode.appendChild(el); }, diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 7a2f9913..513bb01b 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -195,7 +195,7 @@ L.GridLayer = L.Layer.extend({ this._tilesToLoad = 0; this._tilesTotal = 0; - this._tileContainer.innerHTML = ''; + L.DomUtil.empty(this._tileContainer); if (this._zoomAnimated && e && e.hard) { this._clearBgBuffer(); @@ -494,7 +494,7 @@ L.GridLayer = L.Layer.extend({ bg = this._bgBuffer; if (map && !map._animatingZoom && !map.touchZoom._zooming && bg) { - bg.innerHTML = ''; + L.DomUtil.empty(bg); L.DomUtil.setTransform(bg); } }, From b16daa39b941f9ce5158564955976a8b8c0babb9 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 26 May 2014 18:52:24 +0300 Subject: [PATCH 19/57] fix rare error when dragging vectors, close #2706 --- src/layer/vector/SVG.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index 196a269d..d807d22d 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -152,7 +152,10 @@ L.SVG = L.Renderer.extend({ }, _fireMouseEvent: function (e) { - this._paths[L.stamp(e.target || e.srcElement)]._fireMouseEvent(e); + var path = this._paths[L.stamp(e.target || e.srcElement)]; + if (path) { + path._fireMouseEvent(e); + } } }); From 0aeca1a4e780712dba4763f3372d41cee12dfacc Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 26 May 2014 23:21:33 +0300 Subject: [PATCH 20/57] remove element argument in requestAnimFrame --- src/core/Util.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Util.js b/src/core/Util.js index bd9ccafc..5573343e 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -174,11 +174,11 @@ L.Util = { getPrefixed('CancelRequestAnimationFrame') || function (id) { window.clearTimeout(id); }; - L.Util.requestAnimFrame = function (fn, context, immediate, element) { + L.Util.requestAnimFrame = function (fn, context, immediate) { if (immediate && requestFn === timeoutDefer) { fn.call(context); } else { - return requestFn.call(window, L.bind(fn, context), element); + return requestFn.call(window, L.bind(fn, context)); } }; From cea1eff73280cd4fb808df4cf85dcec79130d9a6 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 27 May 2014 15:30:47 -0400 Subject: [PATCH 21/57] Set detectRetina's expected type as Boolean at code level to match documentation and usage --- src/layer/tile/TileLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index 5e6d996e..5c259f59 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -16,7 +16,7 @@ L.TileLayer = L.GridLayer.extend({ maxNativeZoom: , tms: , zoomReverse: , - detectRetina: , + detectRetina: , crossOrigin: , */ }, From 760c730f92508d6b0cc9d5dee3bdf7fd2a1c3929 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Wed, 28 May 2014 17:26:37 +0300 Subject: [PATCH 22/57] fix LatLng.distanceTo race condition, close #2705 --- spec/suites/geo/LatLngSpec.js | 6 ++++++ src/geo/crs/CRS.Earth.js | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spec/suites/geo/LatLngSpec.js b/spec/suites/geo/LatLngSpec.js index 5552aff9..1c050df0 100644 --- a/spec/suites/geo/LatLngSpec.js +++ b/spec/suites/geo/LatLngSpec.js @@ -64,6 +64,12 @@ describe('LatLng', function () { expect(Math.abs(Math.round(a.distanceTo(b) / 1000) - 2084) < 5).to.eql(true); }); + it('does not return NaN if input points are equal', function () { + var a = new L.LatLng(50.5, 30.5); + var b = new L.LatLng(50.5, 30.5); + + expect(a.distanceTo(b)).to.eql(0); + }); }); describe('L.latLng factory', function () { diff --git a/src/geo/crs/CRS.Earth.js b/src/geo/crs/CRS.Earth.js index 3eb09873..b1fb4458 100644 --- a/src/geo/crs/CRS.Earth.js +++ b/src/geo/crs/CRS.Earth.js @@ -11,9 +11,10 @@ L.CRS.Earth = L.extend({}, L.CRS, { distance: function (latlng1, latlng2) { var rad = Math.PI / 180, lat1 = latlng1.lat * rad, - lat2 = latlng2.lat * rad; + lat2 = latlng2.lat * rad, + a = Math.sin(lat1) * Math.sin(lat2) + + Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad); - return this.R * Math.acos(Math.sin(lat1) * Math.sin(lat2) + - Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad)); + return this.R * Math.acos(Math.min(a, 1)); } }); From 5c7bf0268a70c7c0f17844f2de7a406256acdb59 Mon Sep 17 00:00:00 2001 From: Malte Legenhausen Date: Wed, 4 Jun 2014 09:24:50 +0200 Subject: [PATCH 23/57] Bugfix for #2704 --- src/layer/tile/GridLayer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index 513bb01b..cc39f293 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -324,7 +324,7 @@ L.GridLayer = L.Layer.extend({ _tileCoordsToBounds: function (coords) { var map = this._map, - tileSize = this.options.tileSize, + tileSize = this._getTileSize(), nwPoint = coords.multiplyBy(tileSize), sePoint = nwPoint.add([tileSize, tileSize]), From 6ebd9f1ac78d22038116e4fa1d3c45c303fb77f8 Mon Sep 17 00:00:00 2001 From: Sonny Gupta Date: Wed, 4 Jun 2014 09:06:54 -0700 Subject: [PATCH 24/57] Issue #2722 Removed minified source from bower distribution, as is the convention now. --- build/bower.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/bower.json b/build/bower.json index 7dde3788..ca85bde2 100644 --- a/build/bower.json +++ b/build/bower.json @@ -2,7 +2,6 @@ "name": "leaflet", "description": "JavaScript library for mobile-friendly interactive maps", "main": [ - "dist/leaflet.js", "dist/leaflet.css", "dist/leaflet-src.js", "dist/images/layers-2x.png", @@ -20,4 +19,4 @@ "src", "build" ] -} \ No newline at end of file +} From b08e2f7a3de74d8d7c046a1faad002c3b7d5fd64 Mon Sep 17 00:00:00 2001 From: Fabian Zeindl Date: Tue, 17 Jun 2014 14:34:16 +0200 Subject: [PATCH 25/57] removed 1 unnecessary array-creation --- src/core/Util.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/Util.js b/src/core/Util.js index 5573343e..fc66a76e 100644 --- a/src/core/Util.js +++ b/src/core/Util.js @@ -5,11 +5,10 @@ L.Util = { // extend an object with properties of one or more other objects extend: function (dest) { - var sources = Array.prototype.slice.call(arguments, 1), - i, j, len, src; + var i, j, len, src; - for (j = 0, len = sources.length; j < len; j++) { - src = sources[j]; + for (j = 1, len = arguments.length; j < len; j++) { + src = arguments[j]; for (i in src) { dest[i] = src[i]; } From 132e5b6f7cc1a3b31feb21b6a53cd16d971eb455 Mon Sep 17 00:00:00 2001 From: Fabian Zeindl Date: Tue, 17 Jun 2014 15:01:42 +0200 Subject: [PATCH 26/57] =?UTF-8?q?Performance:=20don=E2=80=99t=20set=20widt?= =?UTF-8?q?h/height=20on=20SVG=20if=20unchanged.=20Saves=20a=20costly=20la?= =?UTF-8?q?yout/repaint=20in=20some=20situations.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layer/vector/SVG.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index d807d22d..1bc01eb2 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -31,11 +31,17 @@ L.SVG = L.Renderer.extend({ L.DomUtil.setPosition(container, b.min); - // update container viewBox so that we don't have to change coordinates of individual layers - container.setAttribute('width', size.x); - container.setAttribute('height', size.y); - container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' ')); + // set size of svg-container if changed + if (!this._svgSize || !this._svgSize.equals(size)) { + this._svgSize = size; + container.setAttribute('width', size.x); + container.setAttribute('height', size.y); + } + // movement: update container viewBox so that we don't have to change coordinates of individual layers + L.DomUtil.setPosition(container, b.min); + container.setAttribute('viewBox', [b.min.x, b.min.y, size.x, size.y].join(' ')); + if (L.Browser.mobileWebkit) { pane.appendChild(container); } From 0416bd473feefd73ea93b2a0c49e69503e582ae5 Mon Sep 17 00:00:00 2001 From: Fabian Zeindl Date: Tue, 17 Jun 2014 15:02:56 +0200 Subject: [PATCH 27/57] =?UTF-8?q?Performance:=20this=20triggers=20a=20refl?= =?UTF-8?q?ow,=20but=20newest=20Chrome=20doesn=E2=80=99t=20flicker=20anymo?= =?UTF-8?q?re.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dom/PosAnimation.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/dom/PosAnimation.js b/src/dom/PosAnimation.js index a3ee932c..ff67853a 100644 --- a/src/dom/PosAnimation.js +++ b/src/dom/PosAnimation.js @@ -19,9 +19,6 @@ L.PosAnimation = L.Evented.extend({ L.DomEvent.on(el, L.DomUtil.TRANSITION_END, this._onTransitionEnd, this); L.DomUtil.setPosition(el, newPos); - // toggle reflow, Chrome flickers for some reason if you don't do this - L.Util.falseFn(el.offsetWidth); - // there's no native way to track value updates of transitioned properties, so we imitate this this._stepTimer = setInterval(L.bind(this._onStep, this), 50); }, From 04ed2571fb0a18a7af57037bcdfeb8dd2dd1f5f8 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 24 Jun 2014 22:58:54 +0200 Subject: [PATCH 28/57] Fixed jake build if leaflet copy is not a git repository --- Jakefile.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index bb965e41..1e3599c9 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -23,7 +23,7 @@ function hint(msg, paths) { console.log('\tCheck passed.\n'); complete(); }); - } + }; } desc('Check Leaflet source for errors with JSHint'); @@ -36,12 +36,14 @@ desc('Combine and compress Leaflet source files'); task('build', {async: true}, function (compsBase32, buildName) { var v; - jake.exec('git log -1 --pretty=format:"%h"', {}, function () { + jake.exec('git log -1 --pretty=format:"%h"', {breakOnError: false}, function () { build.build(complete, v, compsBase32, buildName); }).on('stdout', function (data) { v = version + ' (' + data.toString() + ')'; - }) + }).on('error', function () { + v = version; + }); }); desc('Run PhantomJS tests'); From f50806e1cab6ef26db7503c8382a5283fc1676ce Mon Sep 17 00:00:00 2001 From: "francis.chan" Date: Sun, 29 Jun 2014 20:22:44 +0800 Subject: [PATCH 29/57] invoke _clearBgBuffer function to reset layer div container when zoom out of max or minZoom. --- src/layer/tile/GridLayer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index cc39f293..65a2c74b 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -241,7 +241,10 @@ L.GridLayer = L.Layer.extend({ tileSize = this._getTileSize(); if (zoom > this.options.maxZoom || - zoom < this.options.minZoom) { return; } + zoom < this.options.minZoom) { + this._clearBgBuffer(); + return; + } // tile coordinates range for the current view var tileBounds = L.bounds( From ac615cb89e50cbc9762107dbf9ae03d25fa1bd3e Mon Sep 17 00:00:00 2001 From: "francis.chan" Date: Mon, 30 Jun 2014 10:28:48 +0800 Subject: [PATCH 30/57] can customize alt attribute of the image in imageOverlay. --- src/layer/ImageOverlay.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/layer/ImageOverlay.js b/src/layer/ImageOverlay.js index 42deb3b8..b2ac282b 100644 --- a/src/layer/ImageOverlay.js +++ b/src/layer/ImageOverlay.js @@ -5,7 +5,8 @@ L.ImageOverlay = L.Layer.extend({ options: { - opacity: 1 + opacity: 1, + alt: '' }, initialize: function (url, bounds, options) { // (String, LatLngBounds, Object) @@ -90,6 +91,7 @@ L.ImageOverlay = L.Layer.extend({ img.onload = L.bind(this.fire, this, 'load'); img.src = this._url; + img.alt = this.options.alt; }, _animateZoom: function (e) { From d68cab7322ccb45eae1f98a25ebc3154efbb651b Mon Sep 17 00:00:00 2001 From: ericdahl Date: Mon, 30 Jun 2014 18:35:13 -0500 Subject: [PATCH 31/57] fix FAQ links --- FAQ.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FAQ.md b/FAQ.md index 669662ae..e44e363d 100644 --- a/FAQ.md +++ b/FAQ.md @@ -29,7 +29,7 @@ Check out [this example](http://leaflet-extras.github.io/leaflet-providers/previ with half a hundred different layers to choose from. Popular commercial options, free up to a particular number of requests, include [MapBox](http://mapbox.com), -[Bing Maps](http://www.microsoft.com/maps/choose-your-binge's-maps-API.aspx) (using a [plugin](https://github.com/shramov/leaflet-plugins)), +[Bing Maps](http://www.microsoft.com/maps/choose-your-bing-maps-API.aspx) (using a [plugin](https://github.com/shramov/leaflet-plugins)), [Esri ArcGIS](http://www.arcgis.com/features/maps/imagery.html) ([official plugin](https://github.com/Esri/esri-leaflet)) and [Nokia Here](http://developer.here.com/web-experiences). A notable exception is [MapQuest Open](http://developer.mapquest.com/web/products/open/map), which is free for any number of requests. @@ -45,7 +45,7 @@ and [MapQuest Open](http://developer.mapquest.com/web/products/open/map) provide #### I want to use Google Maps API tiles with Leaflet, can I do that? -The problem with Google is that its [Terms of Use](https://developers.google.com/maps/terms?hl=ru) forbid any means of tile access other than through the Google Maps API. +The problem with Google is that its [Terms of Use](https://developers.google.com/maps/terms) forbid any means of tile access other than through the Google Maps API. You can add the Google Maps API as a Leaflet layer with a [plugin](https://github.com/shramov/leaflet-plugins). But note that the map experience will not be perfect, because Leaflet will just act as a proxy to the Google Maps JS engine, so you won't get all the performance and usability benefits of using Leaflet when the Google layer is on. From 9177b7080591d6f67db1880188c8e4ceed67e9dc Mon Sep 17 00:00:00 2001 From: ericdahl Date: Mon, 30 Jun 2014 18:46:20 -0500 Subject: [PATCH 32/57] Fix typos in CONTRIBUTING --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 052240d1..1e4ec7f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,7 +44,7 @@ try asking [on the Leaflet forum](https://groups.google.com/forum/#!forum/leafle ### Considerations for Accepting Patches -While we happily accept patches, we're also commited to keeping Leaflet simple, lightweight and blazingly fast. +While we happily accept patches, we're also committed to keeping Leaflet simple, lightweight and blazingly fast. So bugfixes, performance optimizations and small improvements that don't add a lot of code are much more likely to get accepted quickly. @@ -53,7 +53,7 @@ Before sending a pull request with a new feature, first check if it's been discu or [Leaflet UserVoice](http://leaflet.uservoice.com/)), and then ask yourself two questions: - 1. Are you sure that this new feature is important enough to justify its presense in the Leaflet core? + 1. Are you sure that this new feature is important enough to justify its presence in the Leaflet core? Or will it look better as a plugin in a separate repository? 2. Is it written in a simple, concise way that doesn't add bulk to the codebase? @@ -85,7 +85,7 @@ Please do not commit to the `master` branch, or your unrelated changes will go i You should also follow the code style and whitespace conventions of the original codebase. In particular, use tabs for indentation and spaces for alignment. -Before commiting your changes, run `jake lint` to catch any JS errors in the code and fix them. +Before committing your changes, run `jake lint` to catch any JS errors in the code and fix them. If you add any new files to the Leaflet source, make sure to also add them to `build/deps.js` so that the build system knows about them. @@ -142,7 +142,7 @@ If you need to make edits in a local repository to see how it looks in the proce 4. Open `localhost:4000` in your browser. Now any file changes will be updated when you reload pages automatically. -After commiting the changes, just send a pull request. +After committing the changes, just send a pull request. If you need to update documentation according to a new feature that only appeared in the master version (not stable one), you need to make changes to `gh-pages-master` branch instead of `gh-pages`. From 2124c173df6b667f0cb118f01e9415bdff95a983 Mon Sep 17 00:00:00 2001 From: Austen Talbot Date: Sat, 5 Jul 2014 14:40:23 -0700 Subject: [PATCH 33/57] Make indentation consistent Update indentation on line 27 to be consistent with rest of file --- dist/leaflet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/leaflet.css b/dist/leaflet.css index 1edf2b14..06dd0512 100644 --- a/dist/leaflet.css +++ b/dist/leaflet.css @@ -24,7 +24,7 @@ -webkit-user-select: none; -moz-user-select: none; user-select: none; - -webkit-user-drag: none; + -webkit-user-drag: none; } /* Safari renders non-retina tile on retina better with this, but Chrome is worse */ .leaflet-safari .leaflet-tile { From 7af5adaf0a2028225f6f70229f9cb41a5740344b Mon Sep 17 00:00:00 2001 From: Austen Talbot Date: Sat, 5 Jul 2014 20:17:57 -0700 Subject: [PATCH 34/57] Changed language referring to layers Adjusted language to sound more normal. Changed "half a hundred" to "over seventy." --- FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index e44e363d..47f24966 100644 --- a/FAQ.md +++ b/FAQ.md @@ -26,7 +26,7 @@ You can roll your own tiles as well. but there are providers that use other sources. Check out [this example](http://leaflet-extras.github.io/leaflet-providers/preview/) -with half a hundred different layers to choose from. +with over seventy different layers to choose from. Popular commercial options, free up to a particular number of requests, include [MapBox](http://mapbox.com), [Bing Maps](http://www.microsoft.com/maps/choose-your-bing-maps-API.aspx) (using a [plugin](https://github.com/shramov/leaflet-plugins)), From 410068c08fc1651474533c79ade81884dce90fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniele=20Orru=CC=80?= Date: Sun, 13 Jul 2014 11:41:52 +0200 Subject: [PATCH 35/57] Fixed 'bounceAtZoomLimits' when you don't start pinching from max\min level --- src/map/handler/Map.TouchZoom.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/map/handler/Map.TouchZoom.js b/src/map/handler/Map.TouchZoom.js index 741f83ea..ab90795e 100644 --- a/src/map/handler/Map.TouchZoom.js +++ b/src/map/handler/Map.TouchZoom.js @@ -54,9 +54,11 @@ L.Map.TouchZoom = L.Handler.extend({ this._scale = p1.distanceTo(p2) / this._startDist; this._delta = p1._add(p2)._divideBy(2)._subtract(this._startCenter); - if (!map.options.bounceAtZoomLimits && - ((map.getZoom() === map.getMinZoom() && this._scale < 1) || - (map.getZoom() === map.getMaxZoom() && this._scale > 1))) { return; } + if (!map.options.bounceAtZoomLimits) { + var currentZoom = map.getScaleZoom(this._scale); + if ((currentZoom <= map.getMinZoom() && this._scale < 1) || + (currentZoom >= map.getMaxZoom() && this._scale > 1)) { return; } + } if (!this._moved) { map From c4d99f33b2bec4a63d6c24e2725552417dbb7009 Mon Sep 17 00:00:00 2001 From: bullgare Date: Fri, 18 Jul 2014 16:21:31 +0400 Subject: [PATCH 36/57] mousemove event for marker --- src/layer/marker/Marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 434b4e43..d8a3d8e6 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -205,7 +205,7 @@ L.Marker = L.Layer.extend({ L.DomUtil.addClass(this._icon, 'leaflet-clickable'); - L.DomEvent.on(this._icon, 'click dblclick mousedown mouseup mouseover mouseout contextmenu keypress', + L.DomEvent.on(this._icon, 'click dblclick mousedown mouseup mouseover mousemove mouseout contextmenu keypress', this._fireMouseEvent, this); if (L.Handler.MarkerDrag) { From d5931ad35a55cc00a020f7268b6fab80e1a0e373 Mon Sep 17 00:00:00 2001 From: bennlich Date: Sun, 20 Jul 2014 22:14:30 -0700 Subject: [PATCH 37/57] added _abortLoading() to _reset() --- src/layer/tile/GridLayer.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layer/tile/GridLayer.js b/src/layer/tile/GridLayer.js index cc39f293..0bb181b1 100644 --- a/src/layer/tile/GridLayer.js +++ b/src/layer/tile/GridLayer.js @@ -191,6 +191,10 @@ L.GridLayer = L.Layer.extend({ }); } + if (this._abortLoading) { + this._abortLoading(); + } + this._tiles = {}; this._tilesToLoad = 0; this._tilesTotal = 0; From 412bbd7cdb1ede7af8797fd1a2c4d07b237be8a4 Mon Sep 17 00:00:00 2001 From: bennlich Date: Sun, 20 Jul 2014 22:16:11 -0700 Subject: [PATCH 38/57] always clear tile onload and onerror funs in _abortLoading() --- src/layer/tile/TileLayer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index 5c259f59..2e5aa9d5 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -143,11 +143,11 @@ L.TileLayer = L.GridLayer.extend({ for (i in this._tiles) { tile = this._tiles[i]; - if (!tile.complete) { - tile.onload = L.Util.falseFn; - tile.onerror = L.Util.falseFn; - tile.src = L.Util.emptyImageUrl; + tile.onload = L.Util.falseFn; + tile.onerror = L.Util.falseFn; + if (!tile.complete) { + tile.src = L.Util.emptyImageUrl; L.DomUtil.remove(tile); } } From aeea88b9fcb785b9ae4894a96f265c8b39bdf392 Mon Sep 17 00:00:00 2001 From: jfgodoy Date: Thu, 24 Jul 2014 00:44:42 -0400 Subject: [PATCH 39/57] fix memory leak generated by setIcon when setIcon is called this.dragging is replaced without be disabled before, so hooks remains active. --- src/layer/marker/Marker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index d8a3d8e6..7a73b187 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -209,6 +209,10 @@ L.Marker = L.Layer.extend({ this._fireMouseEvent, this); if (L.Handler.MarkerDrag) { + if (this.dragging) { + this.dragging.disable(); + } + this.dragging = new L.Handler.MarkerDrag(this); if (this.options.draggable) { From abfcd9ea59d03d05f266a3ce1909c6bce1d0c80e Mon Sep 17 00:00:00 2001 From: bennlich Date: Thu, 31 Jul 2014 15:38:21 -0600 Subject: [PATCH 40/57] Added TileLayerSpec.js tests for loading events --- spec/suites/layer/tile/TileLayerSpec.js | 102 ++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 34c9b498..0b79ed68 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -105,4 +105,106 @@ describe('TileLayer', function () { }); }); }); + + describe("'loading' event", function() { + var tileUrl1 = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', + tileUrl2 = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png'; + + // Inject Leaflet css + var head = document.getElementsByTagName("head")[0], + link = document.createElement("link"); + link.href = "../dist/leaflet.css"; + link.type = "text/css"; + link.rel = "stylesheet"; + head.appendChild(link); + + // Add map div to DOM. The map panning tests do not work reliably unless + // the Leaflet map is properly styled and part of the DOM + var mapDiv = document.createElement('div'); + mapDiv.style.height = '256px'; + mapDiv.style.width = '256px'; + document.body.appendChild(mapDiv); + + this.afterAll(function() { + document.body.removeChild(mapDiv); + }); + + // Set the map zoom high enough that panning by 256 pixels necessarily loads more tiles + var myMap = L.map(mapDiv).setView([0, 0], 13); + + describe("after a tilelayer has been initialized with an empty string", function() { + var layer = L.tileLayer(''); + var updateInterval = layer.options.updateInterval + 500; + + var loadingSpy; + beforeEach(function() { + loadingSpy = sinon.spy(); + layer.on('loading', function() { loadingSpy(); }); + }); + afterEach(function() { + layer.off('loading'); + }); + + it("is fired when the tilelayer is added to the map", function() { + layer.addTo(myMap); + expect(loadingSpy.calledOnce).to.be.ok(); + }); + + it("is fired again when the tilelayer has its url set to a real tile url", function(done) { + layer.setUrl(tileUrl2); + + setTimeout(function() { + expect(loadingSpy.calledOnce).to.be.ok(); + done(); + }, updateInterval); + }); + + it("is fired again when the map is panned enough to load more tiles", function(done) { + myMap.panBy([256,256]); + + setTimeout(function() { + expect(loadingSpy.calledOnce).to.be.ok(); + done(); + }, updateInterval); + }); + }); + + describe("after a tilelayer has been initialized with a real tile url", function() { + var layer = L.tileLayer(tileUrl1); + var updateInterval = layer.options.updateInterval + 500; + + var loadingSpy; + beforeEach(function() { + loadingSpy = sinon.spy(); + layer.on('loading', function() { loadingSpy(); }); + }); + afterEach(function() { + layer.off('loading'); + }); + + it("is fired when the tilelayer is added to the map", function() { + layer.addTo(myMap); + expect(loadingSpy.calledOnce).to.be.ok(); + }); + + it("is fired again when the tilelayer has its url set to a real tile url", function(done) { + layer.setUrl(tileUrl2); + + setTimeout(function() { + expect(loadingSpy.calledOnce).to.be.ok(); + done(); + }, updateInterval); + }); + + it("is fired again when the map is panned enough to load more tiles", function(done) { + myMap.panBy([256,256]); + + setTimeout(function() { + expect(loadingSpy.calledOnce).to.be.ok(); + done(); + }, updateInterval); + }); + }); + }); + }); From 4eb033c7196a8b490e449efb238c84efd24262b0 Mon Sep 17 00:00:00 2001 From: bennlich Date: Thu, 31 Jul 2014 23:43:14 -0600 Subject: [PATCH 41/57] Included leaflet.css in html instead of TileLayerSpec.js --- spec/index.html | 1 + spec/suites/layer/tile/TileLayerSpec.js | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/spec/index.html b/spec/index.html index 2be65391..fe8a8c1b 100644 --- a/spec/index.html +++ b/spec/index.html @@ -4,6 +4,7 @@ Leaflet Spec Runner +
diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 0b79ed68..f4439b9b 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -110,14 +110,6 @@ describe('TileLayer', function () { var tileUrl1 = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png', tileUrl2 = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png'; - // Inject Leaflet css - var head = document.getElementsByTagName("head")[0], - link = document.createElement("link"); - link.href = "../dist/leaflet.css"; - link.type = "text/css"; - link.rel = "stylesheet"; - head.appendChild(link); - // Add map div to DOM. The map panning tests do not work reliably unless // the Leaflet map is properly styled and part of the DOM var mapDiv = document.createElement('div'); From fd7ebcb5aaa14f32471bf554cf77c6b46841bd5e Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Tue, 5 Aug 2014 00:09:01 +0300 Subject: [PATCH 42/57] Issue #2619 fixed. Now Map.js/_fireMouseEvent checks dragging.moved() on moved object instead on map --- debug/map/markers.html | 57 ++++++++++++++++++++++++++++++++++++++ src/layer/marker/Marker.js | 2 -- src/map/Map.js | 3 +- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 debug/map/markers.html diff --git a/debug/map/markers.html b/debug/map/markers.html new file mode 100644 index 00000000..e5607185 --- /dev/null +++ b/debug/map/markers.html @@ -0,0 +1,57 @@ + + + + Leaflet debug page + + + + + + + + + + + + +
+ + + + diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 7a73b187..8636f35d 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -227,8 +227,6 @@ L.Marker = L.Layer.extend({ L.DomEvent.preventDefault(e); } - if (e.type === 'click' && this.dragging && this.dragging.moved()) { return; } - if (e.type === 'keypress' && e.keyCode === 13) { type = 'click'; } diff --git a/src/map/Map.js b/src/map/Map.js index 31c7d072..b3c6db95 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -566,9 +566,8 @@ L.Map = L.Evented.extend({ type = type || e.type; if (L.DomEvent._skipped(e)) { return; } - if (type === 'click') { - if (!e._simulated && ((this.dragging && this.dragging.moved()) || + if (!e._simulated && ((obj.dragging && obj.dragging.moved()) || (this.boxZoom && this.boxZoom.moved()))) { return; } obj.fire('preclick'); } From a2825920fa1b377a4d3dea0737732db7642cf0cd Mon Sep 17 00:00:00 2001 From: Kevin DeLoach Date: Mon, 4 Aug 2014 10:59:25 -0400 Subject: [PATCH 43/57] Add uppercase option for WMS TileLayer. In response to issue #1751, WMS TileLayer request parameter keys were cast to uppercase. This is a breaking change for services that are case sensitive and expect lowercase keys. This change adds a new option to uppercase keys, which is false by default, to preserve backwards compatibility. --- src/layer/tile/TileLayer.WMS.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/layer/tile/TileLayer.WMS.js b/src/layer/tile/TileLayer.WMS.js index b7386373..c76dcee2 100644 --- a/src/layer/tile/TileLayer.WMS.js +++ b/src/layer/tile/TileLayer.WMS.js @@ -22,7 +22,9 @@ L.TileLayer.WMS = L.TileLayer.extend({ // all keys that are not TileLayer options go to WMS params for (var i in options) { - if (!this.options.hasOwnProperty(i) && i !== 'crs') { + if (!this.options.hasOwnProperty(i) && + i !== 'crs' && + i !== 'uppercase') { wmsParams[i] = options[i]; } } @@ -38,6 +40,7 @@ L.TileLayer.WMS = L.TileLayer.extend({ onAdd: function (map) { this._crs = this.options.crs || map.options.crs; + this._uppercase = this.options.uppercase || false; this._wmsVersion = parseFloat(this.wmsParams.version); @@ -59,7 +62,9 @@ L.TileLayer.WMS = L.TileLayer.extend({ url = L.TileLayer.prototype.getTileUrl.call(this, coords); - return url + L.Util.getParamString(this.wmsParams, url, true) + '&BBOX=' + bbox; + return url + + L.Util.getParamString(this.wmsParams, url, this._uppercase) + + (this._uppercase ? '&BBOX=' : '&bbox=') + bbox; }, setParams: function (params, noRedraw) { From f5cfddb60d174f1f8d098ca4257f84695e31e0c2 Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Tue, 5 Aug 2014 16:49:33 +0300 Subject: [PATCH 44/57] #2501, wheelDebounceTime option added --- src/map/handler/Map.ScrollWheelZoom.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/map/handler/Map.ScrollWheelZoom.js b/src/map/handler/Map.ScrollWheelZoom.js index df2e614b..b9242318 100644 --- a/src/map/handler/Map.ScrollWheelZoom.js +++ b/src/map/handler/Map.ScrollWheelZoom.js @@ -3,7 +3,8 @@ */ L.Map.mergeOptions({ - scrollWheelZoom: true + scrollWheelZoom: true, + wheelDebounceTime: 40 }); L.Map.ScrollWheelZoom = L.Handler.extend({ @@ -24,7 +25,8 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ }, _onWheelScroll: function (e) { - var delta = L.DomEvent.getWheelDelta(e); + var delta = L.DomEvent.getWheelDelta(e), + debounce = this._map.options.wheelDebounceTime; this._delta += delta; this._lastMousePos = this._map.mouseEventToContainerPoint(e); @@ -33,7 +35,7 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ this._startTime = +new Date(); } - var left = Math.max(40 - (+new Date() - this._startTime), 0); + var left = Math.max(debounce - (+new Date() - this._startTime), 0); clearTimeout(this._timer); this._timer = setTimeout(L.bind(this._performZoom, this), left); From a321406cf8a12ce15b453fa0df20da979e759bb4 Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Tue, 5 Aug 2014 17:13:10 +0300 Subject: [PATCH 45/57] #2501, tab fixed --- src/map/handler/Map.ScrollWheelZoom.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/map/handler/Map.ScrollWheelZoom.js b/src/map/handler/Map.ScrollWheelZoom.js index b9242318..77ada016 100644 --- a/src/map/handler/Map.ScrollWheelZoom.js +++ b/src/map/handler/Map.ScrollWheelZoom.js @@ -25,8 +25,8 @@ L.Map.ScrollWheelZoom = L.Handler.extend({ }, _onWheelScroll: function (e) { - var delta = L.DomEvent.getWheelDelta(e), - debounce = this._map.options.wheelDebounceTime; + var delta = L.DomEvent.getWheelDelta(e); + var debounce = this._map.options.wheelDebounceTime; this._delta += delta; this._lastMousePos = this._map.mouseEventToContainerPoint(e); From 9445c2f9f277f74ae7176bdabacf3a9bfcd07aae Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Tue, 5 Aug 2014 18:14:02 +0300 Subject: [PATCH 46/57] this commit fixes #2499 --- debug/tests/click_on_canvas.html | 2 +- debug/tests/svg_clicks.html | 2 +- dist/leaflet.css | 6 +++--- src/layer/marker/Marker.js | 6 +++--- src/layer/vector/Canvas.js | 6 +++--- src/layer/vector/Path.js | 2 +- src/layer/vector/SVG.js | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/debug/tests/click_on_canvas.html b/debug/tests/click_on_canvas.html index f4a6b9c0..ac9b21f4 100644 --- a/debug/tests/click_on_canvas.html +++ b/debug/tests/click_on_canvas.html @@ -35,7 +35,7 @@ opacity: 1, smoothFactor: 1, color: 'red', - clickable:true + interactive:true })); polygons.on('click', function(m) { diff --git a/debug/tests/svg_clicks.html b/debug/tests/svg_clicks.html index 11be258e..706f3456 100644 --- a/debug/tests/svg_clicks.html +++ b/debug/tests/svg_clicks.html @@ -43,7 +43,7 @@ [51, 7.000], [51.002, 7.004] ], - { clickable:false,color:'#f00' } + { interactive:false,color:'#f00' } ).addTo(map); // when the mouse hovers over the red route2, you cannot click through the blue route1 beneath diff --git a/dist/leaflet.css b/dist/leaflet.css index 06dd0512..4f746154 100644 --- a/dist/leaflet.css +++ b/dist/leaflet.css @@ -171,7 +171,7 @@ /* cursors */ -.leaflet-clickable { +.leaflet-interactive { cursor: pointer; } .leaflet-container { @@ -179,7 +179,7 @@ cursor: -moz-grab; } .leaflet-crosshair, -.leaflet-crosshair .leaflet-clickable { +.leaflet-crosshair .leaflet-interactive { cursor: crosshair; } .leaflet-popup-pane, @@ -187,7 +187,7 @@ cursor: auto; } .leaflet-dragging .leaflet-container, -.leaflet-dragging .leaflet-clickable { +.leaflet-dragging .leaflet-interactive { cursor: move; cursor: -webkit-grabbing; cursor: -moz-grabbing; diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 8636f35d..2bc92a19 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -10,7 +10,7 @@ L.Marker = L.Layer.extend({ icon: new L.Icon.Default(), // title: '', // alt: '', - clickable: true, + interactive: true, // draggable: false, keyboard: true, zIndexOffset: 0, @@ -201,9 +201,9 @@ L.Marker = L.Layer.extend({ _initInteraction: function () { - if (!this.options.clickable) { return; } + if (!this.options.interactive) { return; } - L.DomUtil.addClass(this._icon, 'leaflet-clickable'); + L.DomUtil.addClass(this._icon, 'leaflet-interactive'); L.DomEvent.on(this._icon, 'click dblclick mousedown mouseup mouseover mousemove mouseout contextmenu keypress', this._fireMouseEvent, this); diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index 59580090..e05f2d3e 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -207,12 +207,12 @@ L.Canvas = L.Renderer.extend({ }, _handleHover: function (layer, e, point) { - if (!layer.options.clickable) { return; } + if (!layer.options.interactive) { return; } if (layer._containsPoint(point)) { // if we just got inside the layer, fire mouseover if (!layer._mouseInside) { - L.DomUtil.addClass(this._container, 'leaflet-clickable'); // change cursor + L.DomUtil.addClass(this._container, 'leaflet-interactive'); // change cursor layer._fireMouseEvent(e, 'mouseover'); layer._mouseInside = true; } @@ -221,7 +221,7 @@ L.Canvas = L.Renderer.extend({ } else if (layer._mouseInside) { // if we're leaving the layer, fire mouseout - L.DomUtil.removeClass(this._container, 'leaflet-clickable'); + L.DomUtil.removeClass(this._container, 'leaflet-interactive'); layer._fireMouseEvent(e, 'mouseout'); layer._mouseInside = false; } diff --git a/src/layer/vector/Path.js b/src/layer/vector/Path.js index d4dea2a2..70e575ad 100644 --- a/src/layer/vector/Path.js +++ b/src/layer/vector/Path.js @@ -19,7 +19,7 @@ L.Path = L.Layer.extend({ fillOpacity: 0.2, // className: '' - clickable: true + interactive: true }, onAdd: function () { diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index 1bc01eb2..553bb7e4 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -56,8 +56,8 @@ L.SVG = L.Renderer.extend({ L.DomUtil.addClass(path, layer.options.className); } - if (layer.options.clickable) { - L.DomUtil.addClass(path, 'leaflet-clickable'); + if (layer.options.interactive) { + L.DomUtil.addClass(path, 'leaflet-interactive'); } this._updateStyle(layer); @@ -116,7 +116,7 @@ L.SVG = L.Renderer.extend({ path.setAttribute('fill', 'none'); } - path.setAttribute('pointer-events', options.pointerEvents || (options.clickable ? 'visiblePainted' : 'none')); + path.setAttribute('pointer-events', options.pointerEvents || (options.interactive ? 'visiblePainted' : 'none')); }, _updatePoly: function (layer, closed) { From 1bdd7cf41a59b8810fbdf55a40ce6a16a6a9a360 Mon Sep 17 00:00:00 2001 From: b_b Date: Sun, 10 Aug 2014 18:44:14 +0200 Subject: [PATCH 47/57] Add getBounds() method to ImageOverlay Bugfix : ImageOverlay can be added to FeatueGroup, but calling getBounds on FeatureGroup throw an error cause ImageOverlay misses this method. --- src/layer/ImageOverlay.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/layer/ImageOverlay.js b/src/layer/ImageOverlay.js index b2ac282b..0c9bca02 100644 --- a/src/layer/ImageOverlay.js +++ b/src/layer/ImageOverlay.js @@ -81,6 +81,10 @@ L.ImageOverlay = L.Layer.extend({ return events; }, + + getBounds: function() { + return this._bounds; + }, _initImage: function () { var img = this._image = L.DomUtil.create('img', From f7ac72d073587c3f1c33076038f06a7d9f0eec9b Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Mon, 11 Aug 2014 15:14:37 +0300 Subject: [PATCH 48/57] issue #1871 fixed, set this._zoom on map init whenever options.zoom is provided --- src/map/Map.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/map/Map.js b/src/map/Map.js index b3c6db95..c84ae890 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -33,6 +33,10 @@ L.Map = L.Evented.extend({ this.setMaxBounds(options.maxBounds); } + if (options.zoom !== undefined) { + this._zoom = options.zoom; + } + if (options.center && options.zoom !== undefined) { this.setView(L.latLng(options.center), options.zoom, {reset: true}); } From 31a09930b407bfae097959bbd3075b2631e0d8fe Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Mon, 11 Aug 2014 17:53:59 +0300 Subject: [PATCH 49/57] #1871, zoom limited --- src/map/Map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/map/Map.js b/src/map/Map.js index c84ae890..9f986e21 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -34,7 +34,7 @@ L.Map = L.Evented.extend({ } if (options.zoom !== undefined) { - this._zoom = options.zoom; + this._zoom = this._limitZoom(options.zoom); } if (options.center && options.zoom !== undefined) { From 18938b0319b298055b2c45fe6393cf4213799b36 Mon Sep 17 00:00:00 2001 From: AndreyGeonya Date: Sat, 23 Aug 2014 01:00:42 +0300 Subject: [PATCH 50/57] #2865, fixed bug with geometry/staticMarker click event after map dragging --- debug/map/markers.html | 11 +++++++++++ src/map/Map.js | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/debug/map/markers.html b/debug/map/markers.html index e5607185..1bf803cf 100644 --- a/debug/map/markers.html +++ b/debug/map/markers.html @@ -38,13 +38,24 @@ map.addLayer(markerDraggable); markerDraggable.bindPopup("Draggable"); + + var poly = new L.Polygon([[0, 10], [0, 15.5], [0, 50], [20, 20.5]]); + map.addLayer(poly); + + markerDraggable.on('click', function(e) { console.log('markerDraggable click'); }); + markerStatic.on('click', function(e) { + console.log('markerStatic click'); + }) map.on('click', function(e) { console.log('map click'); }); + poly.on('click', function(e) { + console.log('poly click'); + }); L.tileLayer('http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', { attribution: "Map: Tiles Courtesy of MapQuest (OpenStreetMap, CC-BY-SA)", diff --git a/src/map/Map.js b/src/map/Map.js index 9f986e21..7fda5050 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -571,7 +571,8 @@ L.Map = L.Evented.extend({ if (L.DomEvent._skipped(e)) { return; } if (type === 'click') { - if (!e._simulated && ((obj.dragging && obj.dragging.moved()) || + var draggableObj = obj.options.draggable === true ? obj : this; + if (!e._simulated && ((draggableObj.dragging && draggableObj.dragging.moved()) || (this.boxZoom && this.boxZoom.moved()))) { return; } obj.fire('preclick'); } From 8a33e94c0e56634a749f378256905e9e23243483 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Mon, 25 Aug 2014 16:38:46 +0300 Subject: [PATCH 51/57] Fix scale control widths, close #2869 --- src/control/Control.Scale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/control/Control.Scale.js b/src/control/Control.Scale.js index 80b1a146..2dab3100 100644 --- a/src/control/Control.Scale.js +++ b/src/control/Control.Scale.js @@ -80,7 +80,7 @@ L.Control.Scale = L.Control.extend({ }, _updateScale: function (scale, text, ratio) { - scale.style.width = (Math.round(this.options.maxWidth * ratio) - 10) + 'px'; + scale.style.width = Math.round(this.options.maxWidth * ratio) + 'px'; scale.innerHTML = text; }, From b43da41575b64b21be97c349501658af9cd9d453 Mon Sep 17 00:00:00 2001 From: bullgare Date: Tue, 26 Aug 2014 15:35:58 +0400 Subject: [PATCH 52/57] it fixes marker's setIcon method, that flushes popup's options, which leads to breaking popup's custom offset --- src/layer/marker/Marker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layer/marker/Marker.js b/src/layer/marker/Marker.js index 2bc92a19..6256cd84 100644 --- a/src/layer/marker/Marker.js +++ b/src/layer/marker/Marker.js @@ -76,7 +76,7 @@ L.Marker = L.Layer.extend({ } if (this._popup) { - this.bindPopup(this._popup); + this.bindPopup(this._popup, this._popup.options); } return this; From ecb4af5e76db589d8022459308e4ec63c3ea3a1b Mon Sep 17 00:00:00 2001 From: David Jardin Date: Wed, 3 Sep 2014 17:46:35 +0200 Subject: [PATCH 53/57] CSS reset for svg max-width declarations Fix for https://github.com/Leaflet/Leaflet/issues/2881 --- dist/leaflet.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dist/leaflet.css b/dist/leaflet.css index 4f746154..20d8162c 100644 --- a/dist/leaflet.css +++ b/dist/leaflet.css @@ -44,6 +44,10 @@ .leaflet-container img { max-width: none !important; } +/* reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */ +.leaflet-container svg { + max-width: none !important; + } /* stupid Android 2 doesn't understand "max-width: none" properly */ .leaflet-container img.leaflet-image-layer { max-width: 15000px !important; From 1712b74363b2b7d599f27c3cb7af07faf3031c3c Mon Sep 17 00:00:00 2001 From: David Jardin Date: Wed, 3 Sep 2014 21:07:30 +0200 Subject: [PATCH 54/57] Merged css declarations --- dist/leaflet.css | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/dist/leaflet.css b/dist/leaflet.css index 20d8162c..5f3d8abc 100644 --- a/dist/leaflet.css +++ b/dist/leaflet.css @@ -40,14 +40,12 @@ .leaflet-marker-shadow { display: block; } -/* map is broken in FF if you have max-width: 100% on tiles */ +/* .leaflet-container svg: reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */ +/* .leaflet-container img: map is broken in FF if you have max-width: 100% on tiles */ +.leaflet-container svg, .leaflet-container img { max-width: none !important; } -/* reset svg max-width decleration shipped in Joomla! (joomla.org) 3.x */ -.leaflet-container svg { - max-width: none !important; - } /* stupid Android 2 doesn't understand "max-width: none" properly */ .leaflet-container img.leaflet-image-layer { max-width: 15000px !important; From f2490d3d4a2afa06d10257c2c9dfd36662199bf9 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Mon, 13 Oct 2014 11:18:45 -0700 Subject: [PATCH 55/57] expose a global if window is present --- src/Leaflet.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Leaflet.js b/src/Leaflet.js index 507c781d..ed534f48 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -21,8 +21,9 @@ if (typeof module === 'object' && typeof module.exports === 'object') { // define Leaflet as an AMD module } else if (typeof define === 'function' && define.amd) { define(L); +} // define Leaflet as a global L variable, saving the original L to restore later if needed -} else { +if (typeof window !== 'undefined') { expose(); -} +} \ No newline at end of file From 8cc2d4b42d9338b78f873a6cedf889bdfd392b39 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 14 Oct 2014 15:15:06 -0700 Subject: [PATCH 56/57] add newline --- src/Leaflet.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Leaflet.js b/src/Leaflet.js index ed534f48..14604f42 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -26,4 +26,4 @@ if (typeof module === 'object' && typeof module.exports === 'object') { // define Leaflet as a global L variable, saving the original L to restore later if needed if (typeof window !== 'undefined') { expose(); -} \ No newline at end of file +} From 82abc2bef422d02d7b5e3f5ef756ffdaceb7df30 Mon Sep 17 00:00:00 2001 From: Patrick Arlt Date: Tue, 14 Oct 2014 16:20:39 -0700 Subject: [PATCH 57/57] Revert "update plugin guide with module loader info" --- PLUGIN-GUIDE.md | 119 ------------------------------------------------ 1 file changed, 119 deletions(-) diff --git a/PLUGIN-GUIDE.md b/PLUGIN-GUIDE.md index 92e226ea..e9325e57 100644 --- a/PLUGIN-GUIDE.md +++ b/PLUGIN-GUIDE.md @@ -15,13 +15,6 @@ This guide lists a number of best practices for publishing a Leaflet plugin that - [File Structure](#file-structure) - [Code Conventions](#code-conventions) - [Plugin API](#plugin-api) -3. [Module Loaders](#module-loaders) - - [Wrapping with UMD](#wrapping-with-umd) - - [Using with RequireJS](#using-with-requirejs) - - [Using with Browserify](#using-with-browserify) - - [Best practices for RequireJS](#best-practices-for-requirejs) - - [Best practices for Browserify](#best-practices-for-browserify) - - [Module Loader Resources](#module-loader-resources) ## Presentation @@ -132,115 +125,3 @@ marker.myPlugin('bla', { ``` And most importantly, keep it simple. Leaflet is all about *simplicity*. - -## Module Loaders - -Module loaders such as [RequireJS](http://requirejs.org/) and [Browserify](http://browserify.org/) impliment module systems like AMD (Asyncronous Module Definition) and CommonJS to allow developers to modularize and load their code. - -Leaflet supports being loaded as either an AMD module or a CommonJS module. It does this by implimenting UMD (Universal Module Definition) which checks for the existance of an AMD/CommonJS and impliments the appropriate wrappers. - -### Wrapping with UMD - -You can add support for AMD/CommonJS loaders to your Leaflet plugin by follwoing this pattern. - -```js -(function (factory, window) { - - // define an AMD module that relies on 'leaflet' - if (typeof define === 'function' && define.amd) { - define(['leaflet'], function (L) { - return (exports = factory(L)); - }); - - // define a Common JS module that relies on 'leaflet' - } else if (typeof exports === 'object') { - module.exports = factory(require('leaflet')); - - } - - // attach your plugin to the global 'L' variable - window.L.YourPlugin = factory(L); - -}(function (L) { - // impliment your plguin - var MyLeafletPlugin = {}; - - MyLeafeltPlugin.CustomLayer = L.Layer.extend({ - onAdd: function(map){ - - }, - onRemove: function(){ - - } - }); - - // return your plugin when you are done - return MyLeafletPlugin; -}, window)); -``` - -### Using with RequireJS - -Now users using RequireJS (which impliments the AMD module system) can use your plugin like this. - -```js -// define where the 'leaflet' and 'your-plugin' modules are located -require.config({ - paths: { - 'leaflet': 'the/path/to/leaflet', //path to leaflet.js without the .js - 'your-plugin': 'the/path/to/your-plugin', //path to your-plguin.js without the .js - } -}); - -require([ - 'leaflet', - 'your-plugin' -], function(L, YourPlugin) { - var map = new L.map('map').setView([45.5, -122.75], 9); - var layer = new YourPlugin.CustomLayer().addTo(map); -}); -``` - -### Using with Browserify - -Users who are using Browserify (which impliments the CommonJS module system) can use your plugins following this example. - -```js -var L = require('leaflet'); -var YourPlugin = require('your-plugin'); - -var map = new L.map('map').setView([45.5, -122.75], 9); -var layer = new YourPlugin.CustomLayer().addTo(map); -``` - -### Best practices for RequireJS - -Most AMD based module systesm (RequireJS, Dojo, ect...) have a mechanisum to name modules so they can be easily included with short strings rather then paths. In order to avoid confusion with many short names like `Leaflet` vs `leaflet` always use a lowercase `leaflet` for your module identifier. - -### Best practices for Browserify - -CommonJS module systems like Browserify rely on the [NPM (Node Package Modules)](https://www.npmjs.org/) registry to manage their dependencies. The means that when you `require('leaflet')` the proper module from the registry is returned to you. - -This means that you must publish your plugin to the NPM repository. NPM has an excellent [developers guide](https://www.npmjs.org/doc/misc/npm-developers.html) to help you through the process. - -When you publish your plugin you should add a depenency on `leaflet` to your `package.json` file. This will automatically install Leaflet when your package is installed. - -```json -{ - "name": "my-leaflet-plugin", - "version": "1.0.0", - "description": "A simple leaflet plugin.", - "main": "my-plugin.js", - "author": "You", - "license": "IST", - "dependencies": { - "leaflet": "^1.0.0" - } -} -``` - -### Resources - -* [Get started with RequireJS](http://requirejs.org/docs/start.html#add) -* [Get started Browserify](https://github.com/substack/browserify-handbook) -* [Publishing on NPM](https://www.npmjs.org/doc/misc/npm-developers.html) \ No newline at end of file