]> git.openstreetmap.org Git - rails.git/commitdiff
Update Leaflet to 0.6.3
authorTom Hughes <tom@compton.nu>
Wed, 17 Jul 2013 18:18:13 +0000 (19:18 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 17 Jul 2013 18:18:36 +0000 (19:18 +0100)
Vendorfile
vendor/assets/leaflet/leaflet.css
vendor/assets/leaflet/leaflet.js

index 251a478d12e21916a6e2af0efa331dd37a4393d9..3eee989d3adcf45a784e25046629d9d00d807d85 100644 (file)
@@ -1,11 +1,14 @@
 folder 'vendor/assets' do
   folder 'leaflet' do
-    from 'git://github.com/Leaflet/Leaflet.git', :tag => 'v0.6.1' do
-      file 'leaflet.css', 'dist/leaflet.css'
-      file 'leaflet.ie.css', 'dist/leaflet.ie.css'
-      file 'leaflet.js', 'dist/leaflet-src.js'
-      folder 'images', 'dist/images'
-    end
+    file 'leaflet.js', 'http://cdn.leafletjs.com/leaflet-0.6.3/leaflet-src.js'
+    file 'leaflet.css', 'http://cdn.leafletjs.com/leaflet-0.6.3/leaflet.css'
+    file 'leaflet.ie.css', 'http://cdn.leafletjs.com/leaflet-0.6.3/leaflet.ie.css'
+
+    [ 'layers.png', 'layers-2x.png',
+      'marker-icon.png', 'marker-icon-2x.png',
+      'marker-shadow.png' ].each do |image|
+      file "images/#{image}", "http://cdn.leafletjs.com/leaflet-0.6.3/images/#{image}"
+    end    
 
     from 'git://github.com/kajic/leaflet-locationfilter.git' do
       file 'leaflet.locationfilter.css', 'src/locationfilter.css'
index aee2bb9f750ab8d6c55df5fc00c84b9338a95adb..7dc11b127fbb20048330207442a80a375bb21159 100644 (file)
        width: 0;\r
        height: 0;\r
        }\r
+/* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */\r
+.leaflet-overlay-pane svg {\r
+       -moz-user-select: none;\r
+       }\r
 \r
 .leaflet-tile-pane    { z-index: 2; }\r
 .leaflet-objects-pane { z-index: 3; }\r
 \r
 .leaflet-touch .leaflet-control-attribution,\r
 .leaflet-touch .leaflet-control-layers,\r
-.leaflet-touch .leaflet-control-zoom {\r
+.leaflet-touch .leaflet-bar {\r
        box-shadow: none;\r
        }\r
 .leaflet-touch .leaflet-control-layers,\r
-.leaflet-touch .leaflet-control-zoom {\r
+.leaflet-touch .leaflet-bar {\r
        border: 4px solid rgba(0,0,0,0.3);\r
        }\r
 \r
index 8a857c96c016ea9cf779b296b699082da1676a2d..794496b35130fb5121ef764b3947b33187787ff5 100644 (file)
@@ -7,7 +7,7 @@
 var oldL = window.L,
     L = {};
 
-L.version = '0.6.1';
+L.version = '0.6.3';
 
 // define Leaflet for Node module pattern loaders, including Browserify
 if (typeof module === 'object' && typeof module.exports === 'object') {
@@ -1092,46 +1092,30 @@ L.DomUtil.TRANSITION_END =
        var userSelectProperty = L.DomUtil.testProp(
                ['userSelect', 'WebkitUserSelect', 'OUserSelect', 'MozUserSelect', 'msUserSelect']);
 
-       var userDragProperty = L.DomUtil.testProp(
-               ['userDrag', 'WebkitUserDrag', 'OUserDrag', 'MozUserDrag', 'msUserDrag']);
-
        L.extend(L.DomUtil, {
                disableTextSelection: function () {
+                       L.DomEvent.on(window, 'selectstart', L.DomEvent.preventDefault);
                        if (userSelectProperty) {
                                var style = document.documentElement.style;
                                this._userSelect = style[userSelectProperty];
                                style[userSelectProperty] = 'none';
-                       } else {
-                               L.DomEvent.on(window, 'selectstart', L.DomEvent.stop);
                        }
                },
 
                enableTextSelection: function () {
+                       L.DomEvent.off(window, 'selectstart', L.DomEvent.preventDefault);
                        if (userSelectProperty) {
                                document.documentElement.style[userSelectProperty] = this._userSelect;
                                delete this._userSelect;
-                       } else {
-                               L.DomEvent.off(window, 'selectstart', L.DomEvent.stop);
                        }
                },
 
                disableImageDrag: function () {
-                       if (userDragProperty) {
-                               var style = document.documentElement.style;
-                               this._userDrag = style[userDragProperty];
-                               style[userDragProperty] = 'none';
-                       } else {
-                               L.DomEvent.on(window, 'dragstart', L.DomEvent.stop);
-                       }
+                       L.DomEvent.on(window, 'dragstart', L.DomEvent.preventDefault);
                },
 
                enableImageDrag: function () {
-                       if (userDragProperty) {
-                               document.documentElement.style[userDragProperty] = this._userDrag;
-                               delete this._userDrag;
-                       } else {
-                               L.DomEvent.off(window, 'dragstart', L.DomEvent.stop);
-                       }
+                       L.DomEvent.off(window, 'dragstart', L.DomEvent.preventDefault);
                }
        });
 })();
@@ -1629,7 +1613,7 @@ L.Map = L.Class.extend({
                return this.fire('moveend');
        },
 
-       setMaxBounds: function (bounds) {
+       setMaxBounds: function (bounds, options) {
                bounds = L.latLngBounds(bounds);
 
                this.options.maxBounds = bounds;
@@ -1646,7 +1630,7 @@ L.Map = L.Class.extend({
 
                if (this._loaded) {
                        if (this._zoom < minZoom) {
-                               this.setView(bounds.getCenter(), minZoom);
+                               this.setView(bounds.getCenter(), minZoom, options);
                        } else {
                                this.panInsideBounds(bounds);
                        }
@@ -1724,10 +1708,14 @@ L.Map = L.Class.extend({
 
                if (this._loaded) {
                        layer.onRemove(this);
-                       this.fire('layerremove', {layer: layer});
                }
 
                delete this._layers[id];
+
+               if (this._loaded) {
+                       this.fire('layerremove', {layer: layer});
+               }
+
                if (this._zoomBoundLayers[id]) {
                        delete this._zoomBoundLayers[id];
                        this._updateZoomLevels();
@@ -1856,18 +1844,15 @@ L.Map = L.Class.extend({
        },
 
        getMinZoom: function () {
-               var z1 = this.options.minZoom || 0,
-                   z2 = this._layersMinZoom || 0,
-                   z3 = this._boundsMinZoom || 0;
-
-               return Math.max(z1, z2, z3);
+               var z1 = this._layersMinZoom === undefined ? -Infinity : this._layersMinZoom,
+                   z2 = this._boundsMinZoom === undefined ? -Infinity : this._boundsMinZoom;
+               return this.options.minZoom === undefined ? Math.max(z1, z2) : this.options.minZoom;
        },
 
        getMaxZoom: function () {
-               var z1 = this.options.maxZoom === undefined ? Infinity : this.options.maxZoom,
-                   z2 = this._layersMaxZoom  === undefined ? Infinity : this._layersMaxZoom;
-
-               return Math.min(z1, z2);
+               return this.options.maxZoom === undefined ?
+                       (this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) :
+                       this.options.maxZoom;
        },
 
        getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number
@@ -2187,16 +2172,15 @@ L.Map = L.Class.extend({
        },
 
        _onMouseClick: function (e) {
-               // jshint camelcase: false
-               if (!this._loaded || (!e._simulated && this.dragging && this.dragging.moved()) || e._leaflet_stop) { return; }
+               if (!this._loaded || (!e._simulated && this.dragging && this.dragging.moved()) ||
+                       L.DomEvent._skipped(e)) { return; }
 
                this.fire('preclick');
                this._fireMouseEvent(e);
        },
 
        _fireMouseEvent: function (e) {
-               // jshint camelcase: false
-               if (!this._loaded || e._leaflet_stop) { return; }
+               if (!this._loaded || L.DomEvent._skipped(e)) { return; }
 
                var type = e.type;
 
@@ -2606,10 +2590,7 @@ L.TileLayer = L.Class.extend({
                                var className = 'leaflet-tile-container leaflet-zoom-animated';
 
                                this._bgBuffer = L.DomUtil.create('div', className, this._container);
-                               this._bgBuffer.style.zIndex = 1;
-
                                this._tileContainer = L.DomUtil.create('div', className, this._container);
-                               this._tileContainer.style.zIndex = 2;
 
                        } else {
                                this._tileContainer = this._container;
@@ -3049,6 +3030,11 @@ L.TileLayer.Canvas = L.TileLayer.extend({
        },
 
        redraw: function () {
+               if (this._map) {
+                       this._reset({hard: true});
+                       this._update();
+               }
+               
                for (var i in this._tiles) {
                        this._redrawTile(this._tiles[i]);
                }
@@ -3538,10 +3524,10 @@ L.Marker = L.Class.extend({
                if (newShadow !== this._shadow) {
                        this._removeShadow();
                        addShadow = true;
+               }
 
-                       if (newShadow) {
-                               L.DomUtil.addClass(newShadow, classToAdd);
-                       }
+               if (newShadow) {
+                       L.DomUtil.addClass(newShadow, classToAdd);
                }
                this._shadow = newShadow;
 
@@ -3679,6 +3665,8 @@ L.Marker = L.Class.extend({
                if (this._map) {
                        this._updateOpacity();
                }
+               
+               return this;
        },
 
        _updateOpacity: function () {
@@ -3904,6 +3892,7 @@ L.Popup = L.Class.extend({
 
                this._contentNode = L.DomUtil.create('div', prefix + '-content', wrapper);
                L.DomEvent.on(this._contentNode, 'mousewheel', L.DomEvent.stopPropagation);
+               L.DomEvent.on(this._contentNode, 'MozMousePixelScroll', L.DomEvent.stopPropagation);
                L.DomEvent.on(wrapper, 'contextmenu', L.DomEvent.stopPropagation);
                this._tipContainer = L.DomUtil.create('div', prefix + '-tip-container', container);
                this._tip = L.DomUtil.create('div', prefix + '-tip', this._tipContainer);
@@ -4304,6 +4293,9 @@ L.FeatureGroup = L.LayerGroup.extend({
        },
 
        removeLayer: function (layer) {
+               if (!this.hasLayer(layer)) {
+                       return this;
+               }
                if (layer in this._layers) {
                        layer = this._layers[layer];
                }
@@ -4373,9 +4365,11 @@ L.Path = L.Class.extend({
                // how much to extend the clip area around the map view
                // (relative to its size, e.g. 0.5 is half the screen in each direction)
                // set it so that SVG element doesn't exceed 1280px (vectors flicker on dragend if it is)
-               CLIP_PADDING: L.Browser.mobile ?
-                       Math.max(0, Math.min(0.5,
-                               (1280 / Math.max(window.innerWidth, window.innerHeight) - 1) / 2)) : 0.5
+               CLIP_PADDING: (function () {
+                       var max = L.Browser.mobile ? 1280 : 2000,
+                           target = (max / Math.max(window.outerWidth, window.outerHeight) - 1) / 2;
+                       return Math.max(0, Math.min(0.5, target));
+               })()
        },
 
        options: {
@@ -5635,6 +5629,16 @@ L.polygon = function (latlngs, options) {
                                }
 
                                return this;
+                       },
+
+                       getLatLngs: function () {
+                               var latlngs = [];
+
+                               this.eachLayer(function (layer) {
+                                       latlngs.push(layer.getLatLngs());
+                               });
+
+                               return latlngs;
                        }
                });
        }
@@ -5936,12 +5940,13 @@ L.GeoJSON = L.FeatureGroup.extend({
 
        addData: function (geojson) {
                var features = L.Util.isArray(geojson) ? geojson : geojson.features,
-                   i, len;
+                   i, len, feature;
 
                if (features) {
                        for (i = 0, len = features.length; i < len; i++) {
                                // Only add this if geometry or geometries are set and not null
-                               if (features[i].geometries || features[i].geometry || features[i].features) {
+                               feature = features[i];
+                               if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
                                        this.addData(features[i]);
                                }
                        }
@@ -6319,13 +6324,30 @@ L.DomEvent = {
 
        getMousePosition: function (e, container) {
 
-               var body = document.body,
+               var ie7 = L.Browser.ie7,
+                   body = document.body,
                    docEl = document.documentElement,
-                   x = e.pageX ? e.pageX : e.clientX + body.scrollLeft + docEl.scrollLeft,
-                   y = e.pageY ? e.pageY : e.clientY + body.scrollTop + docEl.scrollTop,
-                   pos = new L.Point(x, y);
+                   x = e.pageX ? e.pageX - body.scrollLeft - docEl.scrollLeft: e.clientX,
+                   y = e.pageY ? e.pageY - body.scrollTop - docEl.scrollTop: e.clientY,
+                   pos = new L.Point(x, y),
+                   rect = container.getBoundingClientRect(),
+                   left = rect.left - container.clientLeft,
+                   top = rect.top - container.clientTop;
+
+               // webkit (and ie <= 7) handles RTL scrollLeft different to everyone else
+               // https://code.google.com/p/closure-library/source/browse/trunk/closure/goog/style/bidi.js
+               if (!L.DomUtil.documentIsLtr() && (L.Browser.webkit || ie7)) {
+                       left += container.scrollWidth - container.clientWidth;
+
+                       // ie7 shows the scrollbar by default and provides clientWidth counting it, so we
+                       // need to add it back in if it is visible; scrollbar is on the left as we are RTL
+                       if (ie7 && L.DomUtil.getStyle(container, 'overflow-y') !== 'hidden' &&
+                                  L.DomUtil.getStyle(container, 'overflow') !== 'hidden') {
+                               left += 17;
+                       }
+               }
 
-               return (container ? pos._subtract(L.DomUtil.getViewportOffset(container)) : pos);
+               return pos._subtract(new L.Point(left, top));
        },
 
        getWheelDelta: function (e) {
@@ -6341,10 +6363,18 @@ L.DomEvent = {
                return delta;
        },
 
-       _fakeStop: function stop(e) {
-               // fakes stopPropagation by setting a special event flag checked in Map mouse events handler
-               // jshint camelcase: false
-               e._leaflet_stop = true;
+       _skipEvents: {},
+
+       _fakeStop: function (e) {
+               // fakes stopPropagation by setting a special event flag, checked/reset with L.DomEvent._skipped(e)
+               L.DomEvent._skipEvents[e.type] = true;
+       },
+
+       _skipped: function (e) {
+               var skipped = this._skipEvents[e.type];
+               // reset when checking, as it's only used in map container and propagates outside of the map
+               this._skipEvents[e.type] = false;
+               return skipped;
        },
 
        // check if element really left/entered the event target (for mouseenter/mouseleave)
@@ -6460,6 +6490,7 @@ L.Draggable = L.Class.extend({
                if (L.Draggable._disabled) { return; }
 
                L.DomUtil.disableImageDrag();
+               L.DomUtil.disableTextSelection();
 
                var first = e.touches ? e.touches[0] : e,
                    el = first.target;
@@ -6499,7 +6530,6 @@ L.Draggable = L.Class.extend({
                        this._startPos = L.DomUtil.getPosition(this._element).subtract(offset);
 
                        if (!L.Browser.touch) {
-                               L.DomUtil.disableTextSelection();
                                L.DomUtil.addClass(document.body, 'leaflet-dragging');
                        }
                }
@@ -6519,7 +6549,6 @@ L.Draggable = L.Class.extend({
 
        _onUp: function () {
                if (!L.Browser.touch) {
-                       L.DomUtil.enableTextSelection();
                        L.DomUtil.removeClass(document.body, 'leaflet-dragging');
                }
 
@@ -6530,6 +6559,7 @@ L.Draggable = L.Class.extend({
                }
 
                L.DomUtil.enableImageDrag();
+               L.DomUtil.enableTextSelection();
 
                if (this._moved) {
                        // ensure drag is not fired after dragend
@@ -6606,6 +6636,8 @@ L.Map.Drag = L.Handler.extend({
                        if (map.options.worldCopyJump) {
                                this._draggable.on('predrag', this._onPreDrag, this);
                                map.on('viewreset', this._onViewReset, this);
+
+                               this._onViewReset();
                        }
                }
                this._draggable.enable();
@@ -8340,9 +8372,14 @@ L.PosAnimation = L.Class.extend({
        },
 
        _onStep: function () {
+               var stepPos = this._getPos();
+               if (!stepPos) {
+                       this._onTransitionEnd();
+                       return;
+               }
                // jshint camelcase: false
                // make L.DomUtil.getPosition return intermediate position value during animation
-               this._el._leaflet_pos = this._getPos();
+               this._el._leaflet_pos = stepPos;
 
                this.fire('step');
        },
@@ -8359,8 +8396,9 @@ L.PosAnimation = L.Class.extend({
 
                if (L.Browser.any3d) {
                        matches = style[L.DomUtil.TRANSFORM].match(this._transformRe);
-                       left = matches ? parseFloat(matches[1]) : 0;
-                       top  = matches ? parseFloat(matches[2]) : 0;
+                       if (!matches) { return; }
+                       left = parseFloat(matches[1]);
+                       top  = parseFloat(matches[2]);
                } else {
                        left = parseFloat(style.left);
                        top  = parseFloat(style.top);
@@ -8590,6 +8628,10 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
                }
        },
 
+       _nothingToAnimate: function () {
+               return !this._container.getElementsByClassName('leaflet-zoom-animated').length;
+       },
+
        _tryAnimatedZoom: function (center, zoom, options) {
 
                if (this._animatingZoom) { return true; }
@@ -8597,7 +8639,7 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
                options = options || {};
 
                // don't animate if disabled, not supported or zoom difference is too large
-               if (!this._zoomAnimated || options.animate === false ||
+               if (!this._zoomAnimated || options.animate === false || this._nothingToAnimate() ||
                        Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { return false; }
 
                // offset is the pixel coords of the zoom origin relative to the current center
@@ -8664,28 +8706,13 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
 
 L.TileLayer.include({
        _animateZoom: function (e) {
-               var firstFrame = false;
-
                if (!this._animating) {
                        this._animating = true;
-                       firstFrame = true;
-               }
-
-               if (firstFrame) {
                        this._prepareBgBuffer();
                }
 
-               var bg = this._bgBuffer;
-
-               if (firstFrame) {
-                       //prevent bg buffer from clearing right after zoom
-                       clearTimeout(this._clearBgBufferTimer);
-
-                       // hack to make sure transform is updated before running animation
-                       L.Util.falseFn(bg.offsetWidth);
-               }
-
-               var transform = L.DomUtil.TRANSFORM,
+               var bg = this._bgBuffer,
+                   transform = L.DomUtil.TRANSFORM,
                    initialTransform = e.delta ? L.DomUtil.getTranslateString(e.delta) : bg.style[transform],
                    scaleStr = L.DomUtil.getScaleString(e.scale, e.origin);
 
@@ -8699,9 +8726,7 @@ L.TileLayer.include({
                    bg = this._bgBuffer;
 
                front.style.visibility = '';
-               front.style.zIndex = 2;
-
-               bg.style.zIndex = 1;
+               front.parentNode.appendChild(front); // Bring to fore
 
                // force reflow
                L.Util.falseFn(bg.offsetWidth);
@@ -8745,6 +8770,9 @@ L.TileLayer.include({
                bg = this._bgBuffer = front;
 
                this._stopLoadingImages(bg);
+
+               //prevent bg buffer from clearing right after zoom
+               clearTimeout(this._clearBgBufferTimer);
        },
 
        _getLoadedTilesPercentage: function (container) {
@@ -8864,7 +8892,7 @@ L.Map.include({
 
                var data = {
                        latlng: latlng,
-                       bounds: bounds,
+                       bounds: bounds
                };
 
                for (var i in pos.coords) {