]> git.openstreetmap.org Git - rails.git/blobdiff - vendor/assets/leaflet/leaflet.js
Update Leaflet
[rails.git] / vendor / assets / leaflet / leaflet.js
index 22503755c3470f3bcfdf5b4b4a3dbeca70978240..6efe5be5ca1c6aebd9f6464bd2fe138e5903996f 100644 (file)
@@ -822,11 +822,10 @@ L.DomUtil = {
 \r
        getScaleString: function (scale, origin) {\r
 \r
-               var preTranslateStr = L.DomUtil.getTranslateString(origin),\r
-                       scaleStr = ' scale(' + scale + ') ',\r
-                       postTranslateStr = L.DomUtil.getTranslateString(origin.multiplyBy(-1));\r
+               var preTranslateStr = L.DomUtil.getTranslateString(origin.add(origin.multiplyBy(-1 * scale))),\r
+                   scaleStr = ' scale(' + scale + ') ';\r
 \r
-               return preTranslateStr + scaleStr + postTranslateStr;\r
+               return preTranslateStr + scaleStr;\r
        },\r
 \r
        setPosition: function (el, point, disable3D) { // (HTMLElement, Point[, Boolean])\r
@@ -1347,16 +1346,10 @@ L.Map = L.Class.extend({
             layer.on('load', this._onTileLayerLoad, this);\r
                }\r
 \r
-               var onMapLoad = function () {\r
+               this.whenReady(function () {\r
                        layer.onAdd(this);\r
                        this.fire('layeradd', {layer: layer});\r
-               };\r
-\r
-               if (this._loaded) {\r
-                       onMapLoad.call(this);\r
-               } else {\r
-                       this.on('load', onMapLoad, this);\r
-               }\r
+               }, this);\r
 \r
                return this;\r
        },\r
@@ -1791,6 +1784,15 @@ L.Map = L.Class.extend({
                }\r
        },\r
 \r
+       whenReady: function (callback, context) {\r
+               if (this._loaded) {\r
+                       callback.call(context || this, this);\r
+               } else {\r
+                       this.on('load', callback, context);\r
+               }\r
+               return this;\r
+       },\r
+\r
 \r
        // private methods for getting map state\r
 \r
@@ -2898,10 +2900,7 @@ L.Marker = L.Class.extend({
        onRemove: function (map) {\r
                this._removeIcon();\r
 \r
-               // TODO move to Marker.Popup.js\r
-               if (this.closePopup) {\r
-                       this.closePopup();\r
-               }\r
+               this.fire('remove');\r
 \r
                map.off({\r
                        'viewreset': this.update,\r
@@ -2920,9 +2919,7 @@ L.Marker = L.Class.extend({
 \r
                this.update();\r
 \r
-               if (this._popup) {\r
-                       this._popup.setLatLng(latlng);\r
-               }\r
+               this.fire('move', { latlng: this._latlng });\r
        },\r
 \r
        setZIndexOffset: function (offset) {\r
@@ -3416,7 +3413,10 @@ L.Marker.include({
                options = L.Util.extend({offset: anchor}, options);\r
 \r
                if (!this._popup) {\r
-                       this.on('click', this.openPopup, this);\r
+                       this\r
+                               .on('click', this.openPopup, this)\r
+                               .on('remove', this.closePopup, this)\r
+                               .on('move', this._movePopup, this);\r
                }\r
 \r
                this._popup = new L.Popup(options, this)\r
@@ -3428,9 +3428,16 @@ L.Marker.include({
        unbindPopup: function () {\r
                if (this._popup) {\r
                        this._popup = null;\r
-                       this.off('click', this.openPopup);\r
+                       this\r
+                               .off('click', this.openPopup)\r
+                               .off('remove', this.closePopup)\r
+                               .off('move', this._movePopup);\r
                }\r
                return this;\r
+       },\r
+\r
+       _movePopup: function (e) {\r
+               this._popup.setLatLng(e.latlng);\r
        }\r
 });\r
 
@@ -3692,6 +3699,8 @@ L.Path = L.Class.extend({
                        this._fill = null;\r
                }\r
 \r
+               this.fire('remove');\r
+\r
                map.off({\r
                        'viewreset': this.projectLatlngs,\r
                        'moveend': this._updatePath\r
@@ -3848,10 +3857,6 @@ L.Path = L.Path.extend({
                }\r
 \r
                this._fireMouseEvent(e);\r
-\r
-               if (this.hasEventListeners(e.type)) {\r
-                       L.DomEvent.stopPropagation(e);\r
-               }\r
        },\r
 \r
        _fireMouseEvent: function (e) {\r
@@ -3859,10 +3864,6 @@ L.Path = L.Path.extend({
                        return;\r
                }\r
 \r
-               if (e.type === 'contextmenu') {\r
-                       L.DomEvent.preventDefault(e);\r
-               }\r
-\r
                var map = this._map,\r
                        containerPoint = map.mouseEventToContainerPoint(e),\r
                        layerPoint = map.containerPointToLayerPoint(containerPoint),\r
@@ -3874,6 +3875,11 @@ L.Path = L.Path.extend({
                        containerPoint: containerPoint,\r
                        originalEvent: e\r
                });\r
+\r
+               if (e.type === 'contextmenu') {\r
+                       L.DomEvent.preventDefault(e);\r
+               }\r
+               L.DomEvent.stopPropagation(e);\r
        }\r
 });\r
 \r
@@ -3963,14 +3969,26 @@ L.Path.include({
 \r
                this._popup.setContent(content);\r
 \r
-               if (!this._openPopupAdded) {\r
-                       this.on('click', this._openPopup, this);\r
-                       this._openPopupAdded = true;\r
+               if (!this._popupHandlersAdded) {\r
+                       this\r
+                               .on('click', this._openPopup, this)\r
+                               .on('remove', this._closePopup, this);\r
+                       this._popupHandlersAdded = true;\r
                }\r
 \r
                return this;\r
        },\r
 \r
+       unbindPopup: function () {\r
+               if (this._popup) {\r
+                       this._popup = null;\r
+                       this\r
+                               .off('click', this.openPopup)\r
+                               .off('remove', this.closePopup);\r
+               }\r
+               return this;\r
+       },\r
+\r
        openPopup: function (latlng) {\r
 \r
                if (this._popup) {\r
@@ -3986,6 +4004,10 @@ L.Path.include({
        _openPopup: function (e) {\r
                this._popup.setLatLng(e.latlng);\r
                this._map.openPopup(this._popup);\r
+       },\r
+\r
+       _closePopup: function () {\r
+               this._popup._close();\r
        }\r
 });\r
 
@@ -6302,16 +6324,20 @@ L.Handler.MarkerDrag = L.Handler.extend({
        },
 
        _onDrag: function (e) {
+               var marker = this._marker,
+                       shadow = marker._shadow,
+                       iconPos = L.DomUtil.getPosition(marker._icon),
+                       latlng = marker._map.layerPointToLatLng(iconPos);
+
                // update shadow position
-               var iconPos = L.DomUtil.getPosition(this._marker._icon);
-               if (this._marker._shadow) {
-                       L.DomUtil.setPosition(this._marker._shadow, iconPos);
+               if (shadow) {
+                       L.DomUtil.setPosition(shadow, iconPos);
                }
 
-               this._marker._latlng = this._marker._map.layerPointToLatLng(iconPos);
+               marker._latlng = latlng;
 
-               this._marker
-                       .fire('move')
+               marker
+                       .fire('move', { latlng: latlng })
                        .fire('drag');
        },
 
@@ -6831,7 +6857,7 @@ L.Control.Scale = L.Control.extend({
                this._addScales(options, className, container);
 
                map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
-               this._update();
+               map.whenReady(this._update, this);
 
                return container;
        },
@@ -7101,18 +7127,26 @@ L.Control.Layers = L.Control.extend({
        _onInputClick: function () {\r
                var i, input, obj,\r
                        inputs = this._form.getElementsByTagName('input'),\r
-                       inputsLen = inputs.length;\r
+                       inputsLen = inputs.length,\r
+                       baseLayer;\r
 \r
                for (i = 0; i < inputsLen; i++) {\r
                        input = inputs[i];\r
                        obj = this._layers[input.layerId];\r
 \r
-                       if (input.checked) {\r
-                               this._map.addLayer(obj.layer, !obj.overlay);\r
-                       } else {\r
+                       if (input.checked && !this._map.hasLayer(obj.layer)) {\r
+                               this._map.addLayer(obj.layer);\r
+                               if (!obj.overlay) {\r
+                                       baseLayer = obj.layer;\r
+                               }\r
+                       } else if (!input.checked && this._map.hasLayer(obj.layer)) {\r
                                this._map.removeLayer(obj.layer);\r
                        }\r
                }\r
+\r
+               if (baseLayer) {\r
+                       this._map.fire('baselayerchange', {layer: baseLayer});\r
+               }\r
        },\r
 \r
        _expand: function () {\r
@@ -7426,11 +7460,6 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
 
                clearTimeout(this._clearTileBgTimer);
 
-               //dumb FireFox hack, I have no idea why this magic zero translate fixes the scale transition problem
-               if (L.Browser.gecko || window.opera || L.Browser.ie3d) {
-                       tileBg.style[transform] += ' translate(0,0)';
-               }
-
                L.Util.falseFn(tileBg.offsetWidth); //hack to make sure transform is updated before running animation
 
                var scaleStr = L.DomUtil.getScaleString(scale, origin),