update leaflet to the latest master - wondering if it improves the troublesome mobile experience

This commit is contained in:
Jon Atkins 2013-06-05 01:00:15 +01:00
parent efa077cb44
commit 935d78fc5f
2 changed files with 122 additions and 71 deletions

View File

@ -55,8 +55,9 @@ L.Util = {
}, },
stamp: (function () { stamp: (function () {
var lastId = 0, key = '_leaflet_id'; var lastId = 0,
return function (/*Object*/ obj) { key = '_leaflet_id';
return function (obj) {
obj[key] = obj[key] || ++lastId; obj[key] = obj[key] || ++lastId;
return obj[key]; return obj[key];
}; };
@ -352,8 +353,8 @@ L.Mixin.Events = {
// store listeners of a particular context in a separate hash (if it has an id) // store listeners of a particular context in a separate hash (if it has an id)
// gives a major performance boost when removing thousands of map layers // gives a major performance boost when removing thousands of map layers
indexKey = type + '_idx', indexKey = type + '_idx';
indexLenKey = indexKey + '_len', indexLenKey = indexKey + '_len';
typeIndex = events[indexKey] = events[indexKey] || {}; typeIndex = events[indexKey] = events[indexKey] || {};
@ -419,7 +420,7 @@ L.Mixin.Events = {
for (j = listeners.length - 1; j >= 0; j--) { for (j = listeners.length - 1; j >= 0; j--) {
if ((listeners[j].action === fn) && (!context || (listeners[j].context === context))) { if ((listeners[j].action === fn) && (!context || (listeners[j].context === context))) {
removed = listeners.splice(j, 1); removed = listeners.splice(j, 1);
// set the old action to a no-op, because it is possible // set the old action to a no-op, because it is possible
// that the listener is being iterated over as part of a dispatch // that the listener is being iterated over as part of a dispatch
removed[0].action = L.Util.falseFn; removed[0].action = L.Util.falseFn;
} }
@ -464,7 +465,7 @@ L.Mixin.Events = {
typeIndex = events[type + '_idx']; typeIndex = events[type + '_idx'];
for (contextId in typeIndex) { for (contextId in typeIndex) {
listeners = typeIndex[contextId]; listeners = typeIndex[contextId].slice();
if (listeners) { if (listeners) {
for (i = 0, len = listeners.length; i < len; i++) { for (i = 0, len = listeners.length; i < len; i++) {
@ -899,6 +900,19 @@ L.DomUtil = {
left += docBody.scrollLeft || docEl.scrollLeft || 0; left += docBody.scrollLeft || docEl.scrollLeft || 0;
break; break;
} }
if (pos === 'relative' && !el.offsetLeft) {
var width = L.DomUtil.getStyle(el, 'width'),
maxWidth = L.DomUtil.getStyle(el, 'max-width');
if (width !== 'none' || maxWidth !== 'none') {
var r = el.getBoundingClientRect();
left += r.left + el.clientLeft;
}
break;
}
el = el.offsetParent; el = el.offsetParent;
} while (el); } while (el);
@ -1195,6 +1209,8 @@ L.LatLngBounds = function (southWest, northEast) { // (LatLng, LatLng) or (LatLn
L.LatLngBounds.prototype = { L.LatLngBounds.prototype = {
// extend the bounds to contain the given point or bounds // extend the bounds to contain the given point or bounds
extend: function (obj) { // (LatLng) or (LatLngBounds) extend: function (obj) { // (LatLng) or (LatLngBounds)
if (!obj) { return this; }
if (typeof obj[0] === 'number' || typeof obj[0] === 'string' || obj instanceof L.LatLng) { if (typeof obj[0] === 'number' || typeof obj[0] === 'string' || obj instanceof L.LatLng) {
obj = L.latLng(obj); obj = L.latLng(obj);
} else { } else {
@ -1650,14 +1666,13 @@ L.Map = L.Class.extend({
// TODO looks ugly, refactor!!! // TODO looks ugly, refactor!!!
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) { if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
this._tileLayersNum++; this._tileLayersNum++;
this._tileLayersToLoad++; this._tileLayersToLoad++;
layer.on('load', this._onTileLayerLoad, this); layer.on('load', this._onTileLayerLoad, this);
} }
this.whenReady(function () { if (this._loaded) {
layer.onAdd(this); this._layerAdd(layer);
this.fire('layeradd', {layer: layer}); }
}, this);
return this; return this;
}, },
@ -1667,7 +1682,10 @@ L.Map = L.Class.extend({
if (!this._layers[id]) { return; } if (!this._layers[id]) { return; }
layer.onRemove(this); if (this._loaded) {
layer.onRemove(this);
this.fire('layerremove', {layer: layer});
}
delete this._layers[id]; delete this._layers[id];
if (this._zoomBoundLayers[id]) { if (this._zoomBoundLayers[id]) {
@ -1678,11 +1696,11 @@ L.Map = L.Class.extend({
// TODO looks ugly, refactor // TODO looks ugly, refactor
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) { if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
this._tileLayersNum--; this._tileLayersNum--;
this._tileLayersToLoad--; this._tileLayersToLoad--;
layer.off('load', this._onTileLayerLoad, this); layer.off('load', this._onTileLayerLoad, this);
} }
return this.fire('layerremove', {layer: layer}); return this;
}, },
hasLayer: function (layer) { hasLayer: function (layer) {
@ -2043,6 +2061,7 @@ L.Map = L.Class.extend({
if (loading) { if (loading) {
this.fire('load'); this.fire('load');
this.eachLayer(this._layerAdd, this);
} }
this.fire('viewreset', {hard: !preserveMapOffset}); this.fire('viewreset', {hard: !preserveMapOffset});
@ -2184,6 +2203,11 @@ L.Map = L.Class.extend({
return this; return this;
}, },
_layerAdd: function (layer) {
layer.onAdd(this);
this.fire('layeradd', {layer: layer});
},
// private methods for getting map state // private methods for getting map state
@ -2550,7 +2574,11 @@ L.TileLayer = L.Class.extend({
var className = 'leaflet-tile-container leaflet-zoom-animated'; var className = 'leaflet-tile-container leaflet-zoom-animated';
this._bgBuffer = L.DomUtil.create('div', className, this._container); 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 = L.DomUtil.create('div', className, this._container);
this._tileContainer.style.zIndex = 2;
} else { } else {
this._tileContainer = this._container; this._tileContainer = this._container;
} }
@ -2655,11 +2683,11 @@ L.TileLayer = L.Class.extend({
var options = this.options; var options = this.options;
if (!options.continuousWorld && options.noWrap) { if (!options.continuousWorld) {
var limit = this._getWrapTileNum(); var limit = this._getWrapTileNum();
// don't load if exceeds world bounds // don't load if exceeds world bounds
if (tilePoint.x < 0 || tilePoint.x >= limit || if ((options.noWrap && (tilePoint.x < 0 || tilePoint.x >= limit)) ||
tilePoint.y < 0 || tilePoint.y >= limit) { return false; } tilePoint.y < 0 || tilePoint.y >= limit) { return false; }
} }
@ -3193,15 +3221,15 @@ L.Icon = L.Class.extend({
L.setOptions(this, options); L.setOptions(this, options);
}, },
createIcon: function () { createIcon: function (oldIcon) {
return this._createIcon('icon'); return this._createIcon('icon', oldIcon);
}, },
createShadow: function () { createShadow: function (oldIcon) {
return this._createIcon('shadow'); return this._createIcon('shadow', oldIcon);
}, },
_createIcon: function (name) { _createIcon: function (name, oldIcon) {
var src = this._getIconUrl(name); var src = this._getIconUrl(name);
if (!src) { if (!src) {
@ -3211,7 +3239,12 @@ L.Icon = L.Class.extend({
return null; return null;
} }
var img = this._createImg(src); var img;
if (!oldIcon) {
img = this._createImg(src);
} else {
img = this._createImg(src, oldIcon);
}
this._setIconStyles(img, name); this._setIconStyles(img, name);
return img; return img;
@ -3245,14 +3278,17 @@ L.Icon = L.Class.extend({
} }
}, },
_createImg: function (src) { _createImg: function (src, el) {
var el;
if (!L.Browser.ie6) { if (!L.Browser.ie6) {
el = document.createElement('img'); if (!el) {
el = document.createElement('img');
}
el.src = src; el.src = src;
} else { } else {
el = document.createElement('div'); if (!el) {
el = document.createElement('div');
}
el.style.filter = el.style.filter =
'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")'; 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
} }
@ -3404,9 +3440,6 @@ L.Marker = L.Class.extend({
}, },
setIcon: function (icon) { setIcon: function (icon) {
if (this._map) {
this._removeIcon();
}
this.options.icon = icon; this.options.icon = icon;
@ -3434,32 +3467,38 @@ L.Marker = L.Class.extend({
classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide', classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide',
needOpacityUpdate = false; needOpacityUpdate = false;
if (!this._icon) { var reuseIcon = this._icon;
if (!reuseIcon) {
this._icon = options.icon.createIcon(); this._icon = options.icon.createIcon();
} else {
if (options.title) { this._icon = this.options.icon.createIcon(this._icon);
this._icon.title = options.title;
}
this._initInteraction();
needOpacityUpdate = (this.options.opacity < 1);
L.DomUtil.addClass(this._icon, classToAdd);
if (options.riseOnHover) {
L.DomEvent
.on(this._icon, 'mouseover', this._bringToFront, this)
.on(this._icon, 'mouseout', this._resetZIndex, this);
}
} }
if (!this._shadow) { if (options.title) {
this._icon.title = options.title;
}
this._initInteraction();
needOpacityUpdate = (this.options.opacity < 1);
L.DomUtil.addClass(this._icon, classToAdd);
if (options.riseOnHover) {
L.DomEvent
.on(this._icon, 'mouseover', this._bringToFront, this)
.on(this._icon, 'mouseout', this._resetZIndex, this);
}
var reuseShadow = this._shadow;
if (!reuseShadow) {
this._shadow = options.icon.createShadow(); this._shadow = options.icon.createShadow();
if (this._shadow) { if (this._shadow) {
L.DomUtil.addClass(this._shadow, classToAdd); L.DomUtil.addClass(this._shadow, classToAdd);
needOpacityUpdate = (this.options.opacity < 1); needOpacityUpdate = (this.options.opacity < 1);
} }
} else {
this._shadow = this.options.icon.createShadow(this._shadow);
} }
if (needOpacityUpdate) { if (needOpacityUpdate) {
@ -3468,9 +3507,11 @@ L.Marker = L.Class.extend({
var panes = this._map._panes; var panes = this._map._panes;
panes.markerPane.appendChild(this._icon); if (!reuseIcon) {
panes.markerPane.appendChild(this._icon);
}
if (this._shadow) { if (this._shadow && !reuseShadow) {
panes.shadowPane.appendChild(this._shadow); panes.shadowPane.appendChild(this._shadow);
} }
}, },
@ -3762,7 +3803,7 @@ L.Popup = L.Class.extend({
if (this._animated) { if (this._animated) {
events.zoomanim = this._zoomAnimation; events.zoomanim = this._zoomAnimation;
} }
if (this._map.options.closePopupOnClick) { if ('closeOnClick' in this.options ? this.options.closeOnClick : this._map.options.closePopupOnClick) {
events.preclick = this._close; events.preclick = this._close;
} }
if (this.options.keepInView) { if (this.options.keepInView) {
@ -4818,6 +4859,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
if (this.options.clickable) { if (this.options.clickable) {
this._map.off('click', this._onClick, this); this._map.off('click', this._onClick, this);
this._map.off('mousemove', this._onMouseMove, this);
} }
this._requestUpdate(); this._requestUpdate();
@ -5095,8 +5137,8 @@ L.LineUtil = {
return false; return false;
// other cases // other cases
} else { } else {
codeOut = codeA || codeB, codeOut = codeA || codeB;
p = this._getEdgeIntersection(a, b, codeOut, bounds), p = this._getEdgeIntersection(a, b, codeOut, bounds);
newCode = this._getBitCode(p, bounds); newCode = this._getBitCode(p, bounds);
if (codeOut === codeA) { if (codeOut === codeA) {
@ -5790,6 +5832,17 @@ L.Circle.include(!L.Path.CANVAS ? {} : {
}); });
/*
* CircleMarker canvas specific drawing parts.
*/
L.CircleMarker.include(!L.Path.CANVAS ? {} : {
_updateStyle: function () {
L.Path.prototype._updateStyle.call(this);
}
});
/* /*
* L.GeoJSON turns any GeoJSON data into a Leaflet layer. * L.GeoJSON turns any GeoJSON data into a Leaflet layer.
*/ */
@ -7049,7 +7102,7 @@ L.Map.TouchZoom = L.Handler.extend({
center = map.layerPointToLatLng(origin), center = map.layerPointToLatLng(origin),
zoom = map.getScaleZoom(this._scale); zoom = map.getScaleZoom(this._scale);
map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta, true); map._animateZoom(center, zoom, this._startCenter, this._scale, this._delta);
}, },
_onTouchEnd: function () { _onTouchEnd: function () {
@ -7079,7 +7132,7 @@ L.Map.TouchZoom = L.Handler.extend({
zoom = map._limitZoom(oldZoom + roundZoomDelta), zoom = map._limitZoom(oldZoom + roundZoomDelta),
scale = map.getZoomScale(zoom) / this._scale; scale = map.getZoomScale(zoom) / this._scale;
map._animateZoom(center, zoom, origin, scale, null, true); map._animateZoom(center, zoom, origin, scale);
}, },
_getScaleOrigin: function () { _getScaleOrigin: function () {
@ -8408,7 +8461,7 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
return true; return true;
}, },
_animateZoom: function (center, zoom, origin, scale, delta, backwards) { _animateZoom: function (center, zoom, origin, scale, delta) {
this._animatingZoom = true; this._animatingZoom = true;
@ -8429,8 +8482,7 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
zoom: zoom, zoom: zoom,
origin: origin, origin: origin,
scale: scale, scale: scale,
delta: delta, delta: delta
backwards: backwards
}); });
}, },
@ -8466,8 +8518,7 @@ L.TileLayer.include({
this._prepareBgBuffer(); this._prepareBgBuffer();
} }
var transform = L.DomUtil.TRANSFORM, var bg = this._bgBuffer;
bg = this._bgBuffer;
if (firstFrame) { if (firstFrame) {
//prevent bg buffer from clearing right after zoom //prevent bg buffer from clearing right after zoom
@ -8477,12 +8528,10 @@ L.TileLayer.include({
L.Util.falseFn(bg.offsetWidth); L.Util.falseFn(bg.offsetWidth);
} }
var scaleStr = L.DomUtil.getScaleString(e.scale, e.origin), var transform = L.DomUtil.TRANSFORM,
oldTransform = bg.style[transform]; initialTransform = e.delta ? L.DomUtil.getTranslateString(e.delta) : bg.style[transform];
bg.style[transform] = e.backwards ? bg.style[transform] = initialTransform + ' ' + L.DomUtil.getScaleString(e.scale, e.origin);
(e.delta ? L.DomUtil.getTranslateString(e.delta) : oldTransform) + ' ' + scaleStr :
scaleStr + ' ' + oldTransform;
}, },
_endZoomAnim: function () { _endZoomAnim: function () {
@ -8517,8 +8566,10 @@ L.TileLayer.include({
// if foreground layer doesn't have many tiles but bg layer does, // if foreground layer doesn't have many tiles but bg layer does,
// keep the existing bg layer and just zoom it some more // keep the existing bg layer and just zoom it some more
if (bg && this._getLoadedTilesPercentage(bg) > 0.5 && var bgLoaded = this._getLoadedTilesPercentage(bg),
this._getLoadedTilesPercentage(front) < 0.5) { frontLoaded = this._getLoadedTilesPercentage(front);
if (bg && bgLoaded > 0.5 && frontLoaded < 0.5) {
front.style.visibility = 'hidden'; front.style.visibility = 'hidden';
this._stopLoadingImages(front); this._stopLoadingImages(front);

8
external/leaflet.js vendored

File diff suppressed because one or more lines are too long