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 () {
var lastId = 0, key = '_leaflet_id';
return function (/*Object*/ obj) {
var lastId = 0,
key = '_leaflet_id';
return function (obj) {
obj[key] = obj[key] || ++lastId;
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)
// gives a major performance boost when removing thousands of map layers
indexKey = type + '_idx',
indexLenKey = indexKey + '_len',
indexKey = type + '_idx';
indexLenKey = indexKey + '_len';
typeIndex = events[indexKey] = events[indexKey] || {};
@ -419,7 +420,7 @@ L.Mixin.Events = {
for (j = listeners.length - 1; j >= 0; j--) {
if ((listeners[j].action === fn) && (!context || (listeners[j].context === context))) {
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
removed[0].action = L.Util.falseFn;
}
@ -464,7 +465,7 @@ L.Mixin.Events = {
typeIndex = events[type + '_idx'];
for (contextId in typeIndex) {
listeners = typeIndex[contextId];
listeners = typeIndex[contextId].slice();
if (listeners) {
for (i = 0, len = listeners.length; i < len; i++) {
@ -899,6 +900,19 @@ L.DomUtil = {
left += docBody.scrollLeft || docEl.scrollLeft || 0;
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;
} while (el);
@ -1195,6 +1209,8 @@ L.LatLngBounds = function (southWest, northEast) { // (LatLng, LatLng) or (LatLn
L.LatLngBounds.prototype = {
// extend the bounds to contain the given point or bounds
extend: function (obj) { // (LatLng) or (LatLngBounds)
if (!obj) { return this; }
if (typeof obj[0] === 'number' || typeof obj[0] === 'string' || obj instanceof L.LatLng) {
obj = L.latLng(obj);
} else {
@ -1650,14 +1666,13 @@ L.Map = L.Class.extend({
// TODO looks ugly, refactor!!!
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
this._tileLayersNum++;
this._tileLayersToLoad++;
layer.on('load', this._onTileLayerLoad, this);
this._tileLayersToLoad++;
layer.on('load', this._onTileLayerLoad, this);
}
this.whenReady(function () {
layer.onAdd(this);
this.fire('layeradd', {layer: layer});
}, this);
if (this._loaded) {
this._layerAdd(layer);
}
return this;
},
@ -1667,7 +1682,10 @@ L.Map = L.Class.extend({
if (!this._layers[id]) { return; }
layer.onRemove(this);
if (this._loaded) {
layer.onRemove(this);
this.fire('layerremove', {layer: layer});
}
delete this._layers[id];
if (this._zoomBoundLayers[id]) {
@ -1678,11 +1696,11 @@ L.Map = L.Class.extend({
// TODO looks ugly, refactor
if (this.options.zoomAnimation && L.TileLayer && (layer instanceof L.TileLayer)) {
this._tileLayersNum--;
this._tileLayersToLoad--;
layer.off('load', this._onTileLayerLoad, this);
this._tileLayersToLoad--;
layer.off('load', this._onTileLayerLoad, this);
}
return this.fire('layerremove', {layer: layer});
return this;
},
hasLayer: function (layer) {
@ -2043,6 +2061,7 @@ L.Map = L.Class.extend({
if (loading) {
this.fire('load');
this.eachLayer(this._layerAdd, this);
}
this.fire('viewreset', {hard: !preserveMapOffset});
@ -2184,6 +2203,11 @@ L.Map = L.Class.extend({
return this;
},
_layerAdd: function (layer) {
layer.onAdd(this);
this.fire('layeradd', {layer: layer});
},
// private methods for getting map state
@ -2550,7 +2574,11 @@ 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;
}
@ -2655,11 +2683,11 @@ L.TileLayer = L.Class.extend({
var options = this.options;
if (!options.continuousWorld && options.noWrap) {
if (!options.continuousWorld) {
var limit = this._getWrapTileNum();
// 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; }
}
@ -3193,15 +3221,15 @@ L.Icon = L.Class.extend({
L.setOptions(this, options);
},
createIcon: function () {
return this._createIcon('icon');
createIcon: function (oldIcon) {
return this._createIcon('icon', oldIcon);
},
createShadow: function () {
return this._createIcon('shadow');
createShadow: function (oldIcon) {
return this._createIcon('shadow', oldIcon);
},
_createIcon: function (name) {
_createIcon: function (name, oldIcon) {
var src = this._getIconUrl(name);
if (!src) {
@ -3211,7 +3239,12 @@ L.Icon = L.Class.extend({
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);
return img;
@ -3245,14 +3278,17 @@ L.Icon = L.Class.extend({
}
},
_createImg: function (src) {
var el;
_createImg: function (src, el) {
if (!L.Browser.ie6) {
el = document.createElement('img');
if (!el) {
el = document.createElement('img');
}
el.src = src;
} else {
el = document.createElement('div');
if (!el) {
el = document.createElement('div');
}
el.style.filter =
'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
}
@ -3404,9 +3440,6 @@ L.Marker = L.Class.extend({
},
setIcon: function (icon) {
if (this._map) {
this._removeIcon();
}
this.options.icon = icon;
@ -3434,32 +3467,38 @@ L.Marker = L.Class.extend({
classToAdd = animation ? 'leaflet-zoom-animated' : 'leaflet-zoom-hide',
needOpacityUpdate = false;
if (!this._icon) {
var reuseIcon = this._icon;
if (!reuseIcon) {
this._icon = options.icon.createIcon();
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);
}
} else {
this._icon = this.options.icon.createIcon(this._icon);
}
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();
if (this._shadow) {
L.DomUtil.addClass(this._shadow, classToAdd);
needOpacityUpdate = (this.options.opacity < 1);
}
} else {
this._shadow = this.options.icon.createShadow(this._shadow);
}
if (needOpacityUpdate) {
@ -3468,9 +3507,11 @@ L.Marker = L.Class.extend({
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);
}
},
@ -3762,7 +3803,7 @@ L.Popup = L.Class.extend({
if (this._animated) {
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;
}
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) {
this._map.off('click', this._onClick, this);
this._map.off('mousemove', this._onMouseMove, this);
}
this._requestUpdate();
@ -5095,8 +5137,8 @@ L.LineUtil = {
return false;
// other cases
} else {
codeOut = codeA || codeB,
p = this._getEdgeIntersection(a, b, codeOut, bounds),
codeOut = codeA || codeB;
p = this._getEdgeIntersection(a, b, codeOut, bounds);
newCode = this._getBitCode(p, bounds);
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.
*/
@ -7049,7 +7102,7 @@ L.Map.TouchZoom = L.Handler.extend({
center = map.layerPointToLatLng(origin),
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 () {
@ -7079,7 +7132,7 @@ L.Map.TouchZoom = L.Handler.extend({
zoom = map._limitZoom(oldZoom + roundZoomDelta),
scale = map.getZoomScale(zoom) / this._scale;
map._animateZoom(center, zoom, origin, scale, null, true);
map._animateZoom(center, zoom, origin, scale);
},
_getScaleOrigin: function () {
@ -8408,7 +8461,7 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
return true;
},
_animateZoom: function (center, zoom, origin, scale, delta, backwards) {
_animateZoom: function (center, zoom, origin, scale, delta) {
this._animatingZoom = true;
@ -8429,8 +8482,7 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
zoom: zoom,
origin: origin,
scale: scale,
delta: delta,
backwards: backwards
delta: delta
});
},
@ -8466,8 +8518,7 @@ L.TileLayer.include({
this._prepareBgBuffer();
}
var transform = L.DomUtil.TRANSFORM,
bg = this._bgBuffer;
var bg = this._bgBuffer;
if (firstFrame) {
//prevent bg buffer from clearing right after zoom
@ -8477,12 +8528,10 @@ L.TileLayer.include({
L.Util.falseFn(bg.offsetWidth);
}
var scaleStr = L.DomUtil.getScaleString(e.scale, e.origin),
oldTransform = bg.style[transform];
var transform = L.DomUtil.TRANSFORM,
initialTransform = e.delta ? L.DomUtil.getTranslateString(e.delta) : bg.style[transform];
bg.style[transform] = e.backwards ?
(e.delta ? L.DomUtil.getTranslateString(e.delta) : oldTransform) + ' ' + scaleStr :
scaleStr + ' ' + oldTransform;
bg.style[transform] = initialTransform + ' ' + L.DomUtil.getScaleString(e.scale, e.origin);
},
_endZoomAnim: function () {
@ -8517,8 +8566,10 @@ L.TileLayer.include({
// if foreground layer doesn't have many tiles but bg layer does,
// keep the existing bg layer and just zoom it some more
if (bg && this._getLoadedTilesPercentage(bg) > 0.5 &&
this._getLoadedTilesPercentage(front) < 0.5) {
var bgLoaded = this._getLoadedTilesPercentage(bg),
frontLoaded = this._getLoadedTilesPercentage(front);
if (bg && bgLoaded > 0.5 && frontLoaded < 0.5) {
front.style.visibility = 'hidden';
this._stopLoadingImages(front);

8
external/leaflet.js vendored

File diff suppressed because one or more lines are too long