update build

This commit is contained in:
Vladimir Agafonkin 2013-05-08 13:02:15 +03:00
parent 0849d06c1b
commit aae54a34d4
2 changed files with 160 additions and 75 deletions

227
dist/leaflet-src.js vendored
View File

@ -384,6 +384,10 @@ L.Mixin.Events = {
removeEventListener: function (types, fn, context) { // ([String, Function, Object]) or (Object[, Object])
if (!this[eventsKey]) {
return this;
}
if (!types) {
return this.clearAllEventListeners();
}
@ -392,7 +396,7 @@ L.Mixin.Events = {
var events = this[eventsKey],
contextId = context && L.stamp(context),
i, len, type, listeners, j, indexKey, indexLenKey, typeIndex;
i, len, type, listeners, j, indexKey, indexLenKey, typeIndex, removed;
types = L.Util.splitWords(types);
@ -414,7 +418,10 @@ L.Mixin.Events = {
if (listeners) {
for (j = listeners.length - 1; j >= 0; j--) {
if ((listeners[j].action === fn) && (!context || (listeners[j].context === context))) {
listeners.splice(j, 1);
removed = listeners.splice(j, 1);
// 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;
}
}
@ -1482,7 +1489,6 @@ L.Map = L.Class.extend({
this._initContainer(id);
this._initLayout();
this.callInitHooks();
this._initEvents();
if (options.maxBounds) {
@ -1490,10 +1496,14 @@ L.Map = L.Class.extend({
}
if (options.center && options.zoom !== undefined) {
this.setView(L.latLng(options.center), options.zoom, true);
this.setView(L.latLng(options.center), options.zoom, {reset: true});
}
this._initLayers(options.layers);
this._handlers = [];
this.callInitHooks();
},
@ -1505,19 +1515,19 @@ L.Map = L.Class.extend({
return this;
},
setZoom: function (zoom) { // (Number)
return this.setView(this.getCenter(), zoom);
setZoom: function (zoom, options) {
return this.setView(this.getCenter(), zoom, {zoom: options});
},
zoomIn: function (delta) {
return this.setZoom(this._zoom + (delta || 1));
zoomIn: function (delta, options) {
return this.setZoom(this._zoom + (delta || 1), options);
},
zoomOut: function (delta) {
return this.setZoom(this._zoom - (delta || 1));
zoomOut: function (delta, options) {
return this.setZoom(this._zoom - (delta || 1), options);
},
setZoomAround: function (latlng, zoom) {
setZoomAround: function (latlng, zoom, options) {
var scale = this.getZoomScale(zoom),
viewHalf = this.getSize().divideBy(2),
containerPoint = latlng instanceof L.Point ? latlng : this.latLngToContainerPoint(latlng),
@ -1525,31 +1535,33 @@ L.Map = L.Class.extend({
centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale),
newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
return this.setView(newCenter, zoom);
return this.setView(newCenter, zoom, {zoom: options});
},
fitBounds: function (bounds, paddingTopLeft, paddingBottomRight) { // (LatLngBounds || ILayer[, Point, Point])
fitBounds: function (bounds, options) {
options = options || {};
bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds);
paddingTopLeft = L.point(paddingTopLeft || [0, 0]);
paddingBottomRight = L.point(paddingBottomRight || paddingTopLeft);
var paddingTL = L.point(options.paddingTopLeft || options.padding || [0, 0]),
paddingBR = L.point(options.paddingBottomRight || options.padding || [0, 0]),
zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR)),
paddingOffset = paddingBR.subtract(paddingTL).divideBy(2),
var zoom = this.getBoundsZoom(bounds, false, paddingTopLeft.add(paddingBottomRight)),
paddingOffset = paddingBottomRight.subtract(paddingTopLeft).divideBy(2),
swPoint = this.project(bounds.getSouthWest(), zoom),
nePoint = this.project(bounds.getNorthEast(), zoom),
center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom);
return this.setView(center, zoom);
return this.setView(center, zoom, options);
},
fitWorld: function () {
return this.fitBounds([[-90, -180], [90, 180]]);
fitWorld: function (options) {
return this.fitBounds([[-90, -180], [90, 180]], options);
},
panTo: function (center) { // (LatLng)
return this.setView(center, this._zoom);
panTo: function (center, options) { // (LatLng)
return this.setView(center, this._zoom, {pan: options});
},
panBy: function (offset) { // (Point)
@ -1723,10 +1735,12 @@ L.Map = L.Class.extend({
addHandler: function (name, HandlerClass) {
if (!HandlerClass) { return; }
this[name] = new HandlerClass(this);
var handler = this[name] = new HandlerClass(this);
this._handlers.push(handler);
if (this.options[name]) {
this[name].enable();
handler.enable();
}
return this;
@ -1736,8 +1750,18 @@ L.Map = L.Class.extend({
if (this._loaded) {
this.fire('unload');
}
this._initEvents('off');
delete this._container._leaflet;
this._clearPanes();
if (this._clearControlPos) {
this._clearControlPos();
}
this._clearHandlers();
return this;
},
@ -1968,6 +1992,10 @@ L.Map = L.Class.extend({
return L.DomUtil.create('div', className, container || this._panes.objectsPane);
},
_clearPanes: function () {
this._container.removeChild(this._mapPane);
},
_initLayers: function (layers) {
layers = layers ? (L.Util.isArray(layers) ? layers : [layers]) : [];
@ -2141,6 +2169,12 @@ L.Map = L.Class.extend({
}
},
_clearHandlers: function () {
for (var i = 0, len = this._handlers.length; i < len; i++) {
this._handlers[i].disable();
}
},
whenReady: function (callback, context) {
if (this._loaded) {
callback.call(context || this, this);
@ -2619,25 +2653,31 @@ L.TileLayer = L.Class.extend({
return false; // already loaded
}
if (!this.options.continuousWorld) {
var options = this.options;
if (!options.continuousWorld && options.noWrap) {
var limit = this._getWrapTileNum();
if (this.options.noWrap && (tilePoint.x < 0 || tilePoint.x >= limit) ||
tilePoint.y < 0 || tilePoint.y >= limit) {
return false; // exceeds world bounds
}
// don't load if exceeds world bounds
if (tilePoint.x < 0 || tilePoint.x >= limit ||
tilePoint.y < 0 || tilePoint.y >= limit) { return false; }
}
if (this.options.bounds) {
var tileSize = this.options.tileSize,
if (options.bounds) {
var tileSize = options.tileSize,
nwPoint = tilePoint.multiplyBy(tileSize),
sePoint = nwPoint.add([tileSize, tileSize]),
nw = this._map.unproject(nwPoint),
se = this._map.unproject(sePoint);
if (!this.options.bounds.intersects([nw, se])) {
return false;
// TODO temporary hack, will be removed after refactoring projections
// https://github.com/Leaflet/Leaflet/issues/1618
if (!options.continuousWorld && !options.noWrap) {
nw = nw.wrap();
se = se.wrap();
}
if (!options.bounds.intersects([nw, se])) { return false; }
}
return true;
@ -3512,14 +3552,16 @@ L.Marker = L.Class.extend({
if ((!this.dragging || !this.dragging._enabled) && this._map.dragging && this._map.dragging.moved()) { return; }
this.fire(e.type, {
originalEvent: e
originalEvent: e,
latlng: this._latlng
});
},
_fireMouseEvent: function (e) {
this.fire(e.type, {
originalEvent: e
originalEvent: e,
latlng: this._latlng
});
// TODO proper custom event propagation
@ -3574,14 +3616,15 @@ L.DivIcon = L.Icon.extend({
html: (String)
bgPos: (Point)
*/
className: 'leaflet-div-icon'
className: 'leaflet-div-icon',
html: false
},
createIcon: function () {
var div = document.createElement('div'),
options = this.options;
if (options.html) {
if (options.html !== false) {
div.innerHTML = options.html;
}
@ -3731,7 +3774,7 @@ L.Popup = L.Class.extend({
_close: function () {
if (this._map) {
this._map.removeLayer(this);
this._map.closePopup(this);
}
},
@ -3912,11 +3955,14 @@ L.Map.include({
return this.addLayer(popup);
},
closePopup: function () {
if (this._popup) {
this.removeLayer(this._popup);
closePopup: function (popup) {
if (!popup || popup === this._popup) {
popup = this._popup;
this._popup = null;
}
if (popup) {
this.removeLayer(popup);
}
return this;
}
});
@ -4027,10 +4073,10 @@ L.LayerGroup = L.Class.extend({
},
removeLayer: function (layer) {
var id = this.getLayerId(layer);
var id = layer in this._layers ? layer : this.getLayerId(layer);
if (this._map && this._layers[id]) {
this._map.removeLayer(layer);
this._map.removeLayer(this._layers[id]);
}
delete this._layers[id];
@ -4041,7 +4087,7 @@ L.LayerGroup = L.Class.extend({
hasLayer: function (layer) {
if (!layer) { return false; }
return (this.getLayerId(layer) in this._layers);
return (layer in this._layers || this.getLayerId(layer) in this._layers);
},
clearLayers: function () {
@ -4086,8 +4132,13 @@ L.LayerGroup = L.Class.extend({
return this;
},
getLayer: function (id) {
return this._layers[id];
},
getLayers: function () {
var layers = [];
for (var i in this._layers) {
layers.push(this._layers[i]);
}
@ -4137,6 +4188,10 @@ L.FeatureGroup = L.LayerGroup.extend({
},
removeLayer: function (layer) {
if (layer in this._layers) {
layer = this._layers[layer];
}
layer.off(L.FeatureGroup.EVENTS, this._propagateEvent, this);
L.LayerGroup.prototype.removeLayer.call(this, layer);
@ -4861,7 +4916,7 @@ L.Path = (L.Path.SVG && !window.L_PREFER_CANVAS) || !L.Browser.canvas ? L.Path :
},
_onMouseMove: function (e) {
if (this._map._animatingZoom) { return; }
if (!this._map || this._map._animatingZoom) { return; }
// TODO don't do on each move
if (this._containsPoint(e.layerPoint)) {
@ -5377,7 +5432,7 @@ L.Polygon = L.Polyline.extend({
// filter out last point if its equal to the first one
latlngs = this._latlngs;
if (latlngs[0].equals(latlngs[latlngs.length - 1])) {
if (latlngs.length >= 2 && latlngs[0].equals(latlngs[latlngs.length - 1])) {
latlngs.pop();
}
},
@ -6563,7 +6618,11 @@ L.Map.Drag = L.Handler.extend({
} else {
L.Util.requestAnimFrame(function () {
map.panBy(offset, decelerationDuration, ease, true);
map.panBy(offset, {
duration: decelerationDuration,
easeLinearity: ease,
noMoveStart: true
});
});
}
}
@ -7460,6 +7519,10 @@ L.Map.include({
createCorner('top', 'right');
createCorner('bottom', 'left');
createCorner('bottom', 'right');
},
_clearControlPos: function () {
this._container.removeChild(this._controlContainer);
}
});
@ -7850,6 +7913,9 @@ L.Control.Layers = L.Control.extend({
var className = 'leaflet-control-layers',
container = this._container = L.DomUtil.create('div', className);
//Makes this work on IE10 Touch devices by stopping it from firing a mouseout event when the touch is released
container.setAttribute('aria-haspopup', true);
if (!L.Browser.touch) {
L.DomEvent.disableClickPropagation(container);
L.DomEvent.on(container, 'mousewheel', L.DomEvent.stopPropagation);
@ -8040,6 +8106,7 @@ L.PosAnimation = L.Class.extend({
this._el = el;
this._inProgress = true;
this._newPos = newPos;
this.fire('start');
@ -8078,7 +8145,7 @@ L.PosAnimation = L.Class.extend({
// you can't easily get intermediate values of properties animated with CSS3 Transitions,
// we need to parse computed style (in case of transform it returns matrix string)
_transformRe: /(-?[\d\.]+), (-?[\d\.]+)\)/,
_transformRe: /([-+]?(?:\d*\.)?\d+)\D*, ([-+]?(?:\d*\.)?\d+)\D*\)/,
_getPos: function () {
var left, top, matches,
@ -8105,6 +8172,10 @@ L.PosAnimation = L.Class.extend({
this._el.style[L.DomUtil.TRANSITION] = '';
// jshint camelcase: false
// make sure L.DomUtil.getPosition returns the final position value after animation
this._el._leaflet_pos = this._newPos;
clearInterval(this._stepTimer);
this.fire('step').fire('end');
@ -8119,24 +8190,27 @@ L.PosAnimation = L.Class.extend({
L.Map.include({
setView: function (center, zoom, forceReset) {
setView: function (center, zoom, options) {
zoom = this._limitZoom(zoom);
center = L.latLng(center);
options = options || {};
if (this._panAnim) {
this._panAnim.stop();
}
var zoomChanged = (this._zoom !== zoom),
canBeAnimated = this._loaded && !forceReset && !!this._layers;
if (this._loaded && !options.reset && options !== true) {
if (canBeAnimated) {
if (options.animate !== undefined) {
options.zoom = L.extend({animate: options.animate}, options.zoom);
options.pan = L.extend({animate: options.animate}, options.pan);
}
// try animating pan or zoom
var animated = zoomChanged ?
this.options.zoomAnimation && this._animateZoomIfClose && this._animateZoomIfClose(center, zoom) :
this._animatePanIfClose(center);
var animated = (this._zoom !== zoom) ?
this._tryAnimatedZoom && this._tryAnimatedZoom(center, zoom, options.zoom) :
this._tryAnimatedPan(center, options.pan);
if (animated) {
// prevent resize handler call, the view will refresh after animation anyway
@ -8151,10 +8225,9 @@ L.Map.include({
return this;
},
panBy: function (offset, duration, easeLinearity, noMoveStart) {
panBy: function (offset, options) {
offset = L.point(offset).round();
// TODO add options instead of arguments to setView/panTo/panBy/etc.
options = options || {};
if (!offset.x && !offset.y) {
return this;
@ -8170,14 +8243,20 @@ L.Map.include({
}
// don't fire movestart if animating inertia
if (!noMoveStart) {
if (!options.noMoveStart) {
this.fire('movestart');
}
L.DomUtil.addClass(this._mapPane, 'leaflet-pan-anim');
// animate pan unless animate: false specified
if (options.animate !== false) {
L.DomUtil.addClass(this._mapPane, 'leaflet-pan-anim');
var newPos = this._getMapPanePos().subtract(offset);
this._panAnim.run(this._mapPane, newPos, duration || 0.25, easeLinearity);
var newPos = this._getMapPanePos().subtract(offset);
this._panAnim.run(this._mapPane, newPos, options.duration || 0.25, options.easeLinearity);
} else {
this._rawPanBy(offset);
this.fire('move').fire('moveend');
}
return this;
},
@ -8191,13 +8270,15 @@ L.Map.include({
this.fire('moveend');
},
_animatePanIfClose: function (center) {
_tryAnimatedPan: function (center, options) {
// difference between the new and current centers in pixels
var offset = this._getCenterOffset(center)._floor();
if (!this.getSize().contains(offset)) { return false; }
// don't animate too far unless animate: true specified in options
if ((options && options.animate) !== true && !this.getSize().contains(offset)) { return false; }
this.panBy(offset, options);
this.panBy(offset);
return true;
}
});
@ -8277,7 +8358,7 @@ L.PosAnimation = L.DomUtil.TRANSITION ? L.PosAnimation : L.PosAnimation.extend({
*/
L.Map.mergeOptions({
zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android23 && !L.Browser.mobileOpera,
zoomAnimation: true,
zoomAnimationThreshold: 4
});
@ -8299,20 +8380,24 @@ L.Map.include(!L.DomUtil.TRANSITION ? {} : {
}
},
_animateZoomIfClose: function (center, zoom) {
_tryAnimatedZoom: function (center, zoom, options) {
if (this._animatingZoom) { return true; }
// don't animate if zoom difference is too large
if (Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { return false; }
options = options || {};
// don't animate if disabled, not supported or zoom difference is too large
if (!this.options.zoomAnimation || options.animate === false ||
!L.DomUtil.TRANSITION || L.Browser.android23 || L.Browser.mobileOpera ||
Math.abs(zoom - this._zoom) > this.options.zoomAnimationThreshold) { return false; }
// offset is the pixel coords of the zoom origin relative to the current center
var scale = this.getZoomScale(zoom),
offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale),
origin = this._getCenterLayerPoint()._add(offset);
// only animate if the zoom origin is within one screen from the current center
if (!this.getSize().contains(offset)) { return false; }
// don't animate if the zoom origin isn't within one screen from the current center, unless forced
if (options.animate !== true && !this.getSize().contains(offset)) { return false; }
this
.fire('movestart')

8
dist/leaflet.js vendored

File diff suppressed because one or more lines are too long