update build

This commit is contained in:
Vladimir Agafonkin 2013-04-22 17:08:19 +03:00
parent eafa54635b
commit 2ec3dc57c0
2 changed files with 188 additions and 222 deletions

334
dist/leaflet-src.js vendored
View File

@ -68,10 +68,8 @@ L.Util = {
args = Array.prototype.slice.call(arguments, 3);
for (i in obj) {
if (obj.hasOwnProperty(i)) {
method.apply(context, [i, obj[i]].concat(args));
}
}
return true;
}
@ -113,8 +111,12 @@ L.Util = {
return Math.round(num * pow) / pow;
},
trim: function (str) {
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '');
},
splitWords: function (str) {
return str.replace(/^\s+|\s+$/g, '').split(/\s+/);
return L.Util.trim(str).split(/\s+/);
},
setOptions: function (obj, options) {
@ -125,17 +127,15 @@ L.Util = {
getParamString: function (obj, existingUrl) {
var params = [];
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
params.push(encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]));
}
}
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&');
},
template: function (str, data) {
return str.replace(/\{ *([\w_]+) *\}/g, function (str, key) {
var value = data[key];
if (!data.hasOwnProperty(key)) {
if (value === undefined) {
throw new Error('No value provided for variable ' + str);
} else if (typeof value === 'function') {
value = value(data);
@ -456,7 +456,6 @@ L.Mixin.Events = {
typeIndex = events[type + '_idx'];
for (contextId in typeIndex) {
if (typeIndex.hasOwnProperty(contextId)) {
listeners = typeIndex[contextId];
if (listeners) {
@ -465,7 +464,6 @@ L.Mixin.Events = {
}
}
}
}
return this;
},
@ -969,15 +967,7 @@ L.DomUtil = {
},
removeClass: function (el, name) {
function replaceFn(w, match) {
if (match === name) { return ''; }
return w;
}
el.className = el.className
.replace(/(\S+)\s*/g, replaceFn)
.replace(/(^\s+|\s+$)/, '');
el.className = L.Util.trim((' ' + el.className + ' ').replace(' ' + name + ' ', ' '));
},
setOpacity: function (el, value) {
@ -1533,22 +1523,28 @@ L.Map = L.Class.extend({
return this.setView(newCenter, zoom);
},
fitBounds: function (bounds) { // (LatLngBounds)
bounds = L.latLngBounds(bounds);
fitBounds: function (bounds, paddingTopLeft, paddingBottomRight) { // (LatLngBounds || ILayer[, Point, Point])
var zoom = this.getBoundsZoom(bounds),
swPoint = this.project(bounds.getSouthWest()),
nePoint = this.project(bounds.getNorthEast()),
center = this.unproject(swPoint.add(nePoint).divideBy(2));
bounds = bounds.getBounds ? bounds.getBounds() : L.latLngBounds(bounds);
paddingTopLeft = L.point(paddingTopLeft || [0, 0]);
paddingBottomRight = L.point(paddingBottomRight || paddingTopLeft);
var zoom = this.getBoundsZoom(bounds, false, paddingTopLeft.add(paddingBottomRight)),
paddingOffset = new L.Point(
paddingBottomRight.x - paddingTopLeft.x,
paddingBottomRight.y - paddingTopLeft.y).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);
},
fitWorld: function () {
var sw = new L.LatLng(-60, -170),
ne = new L.LatLng(85, 179);
return this.fitBounds(new L.LatLngBounds(sw, ne));
return this.fitBounds([[-90, -180], [90, 180]]);
},
panTo: function (center) { // (LatLng)
@ -1679,16 +1675,13 @@ L.Map = L.Class.extend({
hasLayer: function (layer) {
if (!layer) { return false; }
var id = L.stamp(layer);
return this._layers.hasOwnProperty(id);
return (L.stamp(layer) in this);
},
eachLayer: function (method, context) {
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
method.call(context, this._layers[i]);
}
}
return this;
},
@ -1786,37 +1779,26 @@ L.Map = L.Class.extend({
return Math.min(z1, z2);
},
getBoundsZoom: function (bounds, inside) { // (LatLngBounds, Boolean) -> Number
getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number
bounds = L.latLngBounds(bounds);
var size = this.getSize(),
zoom = this.options.minZoom || 0,
var zoom = this.getMinZoom() - (inside ? 1 : 0),
maxZoom = this.getMaxZoom(),
ne = bounds.getNorthEast(),
sw = bounds.getSouthWest(),
boundsSize,
nePoint,
swPoint,
zoomNotFound = true;
size = this.getSize(),
if (inside) {
zoom--;
}
nw = bounds.getNorthWest(),
se = bounds.getSouthEast(),
zoomNotFound = true,
boundsSize;
padding = L.point(padding || [0, 0]);
do {
zoom++;
nePoint = this.project(ne, zoom);
swPoint = this.project(sw, zoom);
boundsSize = this.project(se, zoom).subtract(this.project(nw, zoom)).add(padding);
zoomNotFound = !inside ? size.contains(boundsSize) : boundsSize.x < size.x || boundsSize.y < size.y;
boundsSize = new L.Point(
Math.abs(nePoint.x - swPoint.x),
Math.abs(swPoint.y - nePoint.y));
if (!inside) {
zoomNotFound = boundsSize.x <= size.x && boundsSize.y <= size.y;
} else {
zoomNotFound = boundsSize.x < size.x || boundsSize.y < size.y;
}
} while (zoomNotFound && zoom <= maxZoom);
if (zoomNotFound && inside) {
@ -2030,6 +2012,10 @@ L.Map = L.Class.extend({
var loading = !this._loaded;
this._loaded = true;
if (loading) {
this.fire('load');
}
this.fire('viewreset', {hard: !preserveMapOffset});
this.fire('move');
@ -2039,10 +2025,6 @@ L.Map = L.Class.extend({
}
this.fire('moveend', {hard: !preserveMapOffset});
if (loading) {
this.fire('load');
}
},
_rawPanBy: function (offset) {
@ -2060,7 +2042,6 @@ L.Map = L.Class.extend({
oldZoomSpan = this._getZoomSpan();
for (i in this._zoomBoundLayers) {
if (this._zoomBoundLayers.hasOwnProperty(i)) {
var layer = this._zoomBoundLayers[i];
if (!isNaN(layer.options.minZoom)) {
minZoom = Math.min(minZoom, layer.options.minZoom);
@ -2069,7 +2050,6 @@ L.Map = L.Class.extend({
maxZoom = Math.max(maxZoom, layer.options.maxZoom);
}
}
}
if (i === undefined) { // we have no tilelayers
this._layersMaxZoom = this._layersMinZoom = undefined;
@ -2509,10 +2489,8 @@ L.TileLayer = L.Class.extend({
if (L.Browser.ielt9) {
for (i in tiles) {
if (tiles.hasOwnProperty(i)) {
L.DomUtil.setOpacity(tiles[i], this.options.opacity);
}
}
} else {
L.DomUtil.setOpacity(this._container, this.options.opacity);
}
@ -2520,11 +2498,9 @@ L.TileLayer = L.Class.extend({
// stupid webkit hack to force redrawing of tiles
if (L.Browser.webkit) {
for (i in tiles) {
if (tiles.hasOwnProperty(i)) {
tiles[i].style.webkitTransform += ' translate(0,0)';
}
}
}
},
_initContainer: function () {
@ -2553,12 +2529,8 @@ L.TileLayer = L.Class.extend({
},
_reset: function (e) {
var tiles = this._tiles;
for (var key in tiles) {
if (tiles.hasOwnProperty(key)) {
this.fire('tileunload', {tile: tiles[key]});
}
for (var key in this._tiles) {
this.fire('tileunload', {tile: this._tiles[key]});
}
this._tiles = {};
@ -2681,7 +2653,6 @@ L.TileLayer = L.Class.extend({
var kArr, x, y, key;
for (key in this._tiles) {
if (this._tiles.hasOwnProperty(key)) {
kArr = key.split(':');
x = parseInt(kArr[0], 10);
y = parseInt(kArr[1], 10);
@ -2691,7 +2662,6 @@ L.TileLayer = L.Class.extend({
this._removeTile(key);
}
}
}
},
_removeTile: function (key) {
@ -2984,12 +2954,8 @@ L.TileLayer.Canvas = L.TileLayer.extend({
},
redraw: function () {
var tiles = this._tiles;
for (var i in tiles) {
if (tiles.hasOwnProperty(i)) {
this._redrawTile(tiles[i]);
}
for (var i in this._tiles) {
this._redrawTile(this._tiles[i]);
}
return this;
},
@ -3663,6 +3629,7 @@ L.Popup = L.Class.extend({
closeButton: true,
offset: new L.Point(0, 6),
autoPanPadding: new L.Point(5, 5),
keepInView: false,
className: '',
zoomAnimation: true
},
@ -3689,21 +3656,21 @@ L.Popup = L.Class.extend({
}
map._panes.popupPane.appendChild(this._container);
map.on('viewreset', this._updatePosition, this);
if (this._animated) {
map.on('zoomanim', this._zoomAnimation, this);
}
if (map.options.closePopupOnClick) {
map.on('preclick', this._close, this);
}
map.on(this._getEvents(), this);
this._update();
if (animFade) {
L.DomUtil.setOpacity(this._container, 1);
}
this.fire('open');
map.fire('popupopen', {popup: this});
if (this._source) {
this._source.fire('popupopen', {popup: this});
}
},
addTo: function (map) {
@ -3721,17 +3688,21 @@ L.Popup = L.Class.extend({
L.Util.falseFn(this._container.offsetWidth); // force reflow
map.off({
viewreset: this._updatePosition,
preclick: this._close,
zoomanim: this._zoomAnimation
}, this);
map.off(this._getEvents(), this);
if (map.options.fadeAnimation) {
L.DomUtil.setOpacity(this._container, 0);
}
this._map = null;
this.fire('close');
map.fire('popupclose', {popup: this});
if (this._source) {
this._source.fire('popupclose', {popup: this});
}
},
setLatLng: function (latlng) {
@ -3746,15 +3717,27 @@ L.Popup = L.Class.extend({
return this;
},
_getEvents: function () {
var events = {
viewreset: this._updatePosition
};
if (this._animated) {
events.zoomanim = this._zoomAnimation;
}
if (this._map.options.closePopupOnClick) {
events.preclick = this._close;
}
if (this.options.keepInView) {
events.moveend = this._adjustPan;
}
return events;
},
_close: function () {
var map = this._map;
if (map) {
map._popup = null;
map
.removeLayer(this)
.fire('popupclose', {popup: this});
if (this._map) {
this._map.removeLayer(this);
}
},
@ -3858,7 +3841,7 @@ L.Popup = L.Class.extend({
this._containerBottom = -offset.y - (animated ? 0 : pos.y);
this._containerLeft = -Math.round(this._containerWidth / 2) + offset.x + (animated ? 0 : pos.x);
//Bottom position the popup in case the height of the popup changes (images loading etc)
// bottom position the popup in case the height of the popup changes (images loading etc)
this._container.style.bottom = this._containerBottom + 'px';
this._container.style.left = this._containerLeft + 'px';
},
@ -3888,18 +3871,18 @@ L.Popup = L.Class.extend({
dx = 0,
dy = 0;
if (containerPos.x < 0) {
dx = containerPos.x - padding.x;
}
if (containerPos.x + containerWidth > size.x) {
if (containerPos.x + containerWidth > size.x) { // right
dx = containerPos.x + containerWidth - size.x + padding.x;
}
if (containerPos.y < 0) {
dy = containerPos.y - padding.y;
if (containerPos.x - dx < 0) { // left
dx = containerPos.x - padding.x;
}
if (containerPos.y + containerHeight > size.y) {
if (containerPos.y + containerHeight > size.y) { // bottom
dy = containerPos.y + containerHeight - size.y + padding.y;
}
if (containerPos.y - dy < 0) { // top
dy = containerPos.y - padding.y;
}
if (dx || dy) {
map
@ -3919,6 +3902,32 @@ L.popup = function (options, source) {
};
L.Map.include({
openPopup: function (popup, latlng, options) { // (Popup) or (String || HTMLElement, LatLng[, Object])
this.closePopup();
if (!(popup instanceof L.Popup)) {
var content = popup;
popup = new L.Popup(options)
.setLatLng(latlng)
.setContent(content);
}
this._popup = popup;
return this.addLayer(popup);
},
closePopup: function () {
if (this._popup) {
this.removeLayer(this._popup);
this._popup = null;
}
return this;
}
});
/*
* Popup extension to L.Marker, adding popup-related methods.
*/
@ -3993,30 +4002,6 @@ L.Marker.include({
});
/*
* Adds popup-related methods to L.Map.
*/
L.Map.include({
openPopup: function (popup) {
this.closePopup();
this._popup = popup;
return this
.addLayer(popup)
.fire('popupopen', {popup: this._popup});
},
closePopup: function () {
if (this._popup) {
this._popup._close();
}
return this;
}
});
/*
* L.LayerGroup is a class to combine several layers into one so that
* you can manipulate the group (e.g. add/remove it) as one layer.
@ -4062,8 +4047,7 @@ L.LayerGroup = L.Class.extend({
hasLayer: function (layer) {
if (!layer) { return false; }
var id = this.getLayerId(layer);
return this._layers.hasOwnProperty(id);
return (this.getLayerId(layer) in this._layers);
},
clearLayers: function () {
@ -4076,14 +4060,12 @@ L.LayerGroup = L.Class.extend({
i, layer;
for (i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
layer = this._layers[i];
if (layer[methodName]) {
layer[methodName].apply(layer, args);
}
}
}
return this;
},
@ -4105,20 +4087,16 @@ L.LayerGroup = L.Class.extend({
eachLayer: function (method, context) {
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
method.call(context, this._layers[i]);
}
}
return this;
},
getLayers: function () {
var layers = [];
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
layers.push(this._layers[i]);
}
}
return layers;
},
@ -4704,7 +4682,7 @@ L.Path = L.Browser.svg || !L.Browser.vml ? L.Path : L.Path.extend({
if (options.dashArray) {
stroke.dashStyle = options.dashArray instanceof Array ?
options.dashArray.join(' ') :
options.dashArray.replace(/ *, */g, ' ');
options.dashArray.replace(/( *, *)/g, ' ');
} else {
stroke.dashStyle = '';
}
@ -5805,7 +5783,7 @@ L.GeoJSON = L.FeatureGroup.extend({
if (options.filter && !options.filter(geojson)) { return; }
var layer = L.GeoJSON.geometryToLayer(geojson, options.pointToLayer);
var layer = L.GeoJSON.geometryToLayer(geojson, options.pointToLayer, options.coordsToLatLng);
layer.feature = geojson;
layer.defaultOptions = layer.options;
@ -5845,48 +5823,52 @@ L.GeoJSON = L.FeatureGroup.extend({
});
L.extend(L.GeoJSON, {
geometryToLayer: function (geojson, pointToLayer) {
geometryToLayer: function (geojson, pointToLayer, coordsToLatLng) {
var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,
coords = geometry.coordinates,
layers = [],
latlng, latlngs, i, len, layer;
coordsToLatLng = coordsToLatLng || this.coordsToLatLng;
switch (geometry.type) {
case 'Point':
latlng = this.coordsToLatLng(coords);
latlng = coordsToLatLng(coords);
return pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng);
case 'MultiPoint':
for (i = 0, len = coords.length; i < len; i++) {
latlng = this.coordsToLatLng(coords[i]);
latlng = coordsToLatLng(coords[i]);
layer = pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng);
layers.push(layer);
}
return new L.FeatureGroup(layers);
case 'LineString':
latlngs = this.coordsToLatLngs(coords);
latlngs = this.coordsToLatLngs(coords, 0, coordsToLatLng);
return new L.Polyline(latlngs);
case 'Polygon':
latlngs = this.coordsToLatLngs(coords, 1);
latlngs = this.coordsToLatLngs(coords, 1, coordsToLatLng);
return new L.Polygon(latlngs);
case 'MultiLineString':
latlngs = this.coordsToLatLngs(coords, 1);
latlngs = this.coordsToLatLngs(coords, 1, coordsToLatLng);
return new L.MultiPolyline(latlngs);
case 'MultiPolygon':
latlngs = this.coordsToLatLngs(coords, 2);
latlngs = this.coordsToLatLngs(coords, 2, coordsToLatLng);
return new L.MultiPolygon(latlngs);
case 'GeometryCollection':
for (i = 0, len = geometry.geometries.length; i < len; i++) {
layer = this.geometryToLayer({
geometry: geometry.geometries[i],
type: 'Feature',
properties: geojson.properties
}, pointToLayer);
layers.push(layer);
}
return new L.FeatureGroup(layers);
@ -5896,40 +5878,33 @@ L.extend(L.GeoJSON, {
}
},
coordsToLatLng: function (coords, reverse) { // (Array, Boolean) -> LatLng
var lat = parseFloat(coords[reverse ? 0 : 1]),
lng = parseFloat(coords[reverse ? 1 : 0]);
return new L.LatLng(lat, lng);
coordsToLatLng: function (coords) { // (Array[, Boolean]) -> LatLng
return new L.LatLng(coords[1], coords[0]);
},
coordsToLatLngs: function (coords, levelsDeep, reverse) { // (Array, Number, Boolean) -> Array
var latlng,
latlngs = [],
i, len;
coordsToLatLngs: function (coords, levelsDeep, coordsToLatLng) { // (Array[, Number, Function]) -> Array
var latlng, i, len,
latlngs = [];
for (i = 0, len = coords.length; i < len; i++) {
latlng = levelsDeep ?
this.coordsToLatLngs(coords[i], levelsDeep - 1, reverse) :
this.coordsToLatLng(coords[i], reverse);
this.coordsToLatLngs(coords[i], levelsDeep - 1, coordsToLatLng) :
(coordsToLatLng || this.coordsToLatLng)(coords[i]);
latlngs.push(latlng);
}
return latlngs;
}
});
},
L.extend(L.GeoJSON, {
latLngToCoords: function (latLng) {
return [latLng.lng, latLng.lat];
},
latLngsToCoords: function (latLngs) {
var coords = [],
i, len;
var coords = [];
for (i = 0, len = latLngs.length; i < len; i++) {
for (var i = 0, len = latLngs.length; i < len; i++) {
coords.push(L.GeoJSON.latLngToCoords(latLngs[i]));
}
@ -6400,12 +6375,10 @@ L.Draggable = L.Class.extend({
}
for (i in L.Draggable.MOVE) {
if (L.Draggable.MOVE.hasOwnProperty(i)) {
L.DomEvent
.off(document, L.Draggable.MOVE[i], this._onMove)
.off(document, L.Draggable.END[i], this._onUp);
}
}
if (this._moved) {
// ensure drag is not fired after dragend
@ -7300,14 +7273,14 @@ L.Map.Keyboard = L.Handler.extend({
var key = e.keyCode,
map = this._map;
if (this._panKeys.hasOwnProperty(key)) {
if (key in this._panKeys) {
map.panBy(this._panKeys[key]);
if (map.options.maxBounds) {
map.panInsideBounds(map.options.maxBounds);
}
} else if (this._zoomKeys.hasOwnProperty(key)) {
} else if (key in this._zoomKeys) {
map.setZoom(map.getZoom() + this._zoomKeys[key]);
} else {
@ -7465,9 +7438,7 @@ L.control = function (options) {
};
/*
* Adds control-related methods to L.Map.
*/
// adds control-related methods to L.Map
L.Map.include({
addControl: function (control) {
@ -7660,7 +7631,7 @@ L.Control.Attribution = L.Control.extend({
var attribs = [];
for (var i in this._attributions) {
if (this._attributions.hasOwnProperty(i) && this._attributions[i]) {
if (this._attributions[i]) {
attribs.push(i);
}
}
@ -7838,16 +7809,12 @@ L.Control.Layers = L.Control.extend({
this._handlingClick = false;
for (var i in baseLayers) {
if (baseLayers.hasOwnProperty(i)) {
this._addLayer(baseLayers[i], i);
}
}
for (i in overlays) {
if (overlays.hasOwnProperty(i)) {
this._addLayer(overlays[i], i, true);
}
}
},
onAdd: function (map) {
@ -7955,18 +7922,17 @@ L.Control.Layers = L.Control.extend({
this._overlaysList.innerHTML = '';
var baseLayersPresent = false,
overlaysPresent = false;
overlaysPresent = false,
i, obj;
for (var i in this._layers) {
if (this._layers.hasOwnProperty(i)) {
var obj = this._layers[i];
for (i in this._layers) {
obj = this._layers[i];
this._addItem(obj);
overlaysPresent = overlaysPresent || obj.overlay;
baseLayersPresent = baseLayersPresent || !obj.overlay;
}
}
this._separator.style.display = (overlaysPresent && baseLayersPresent ? '' : 'none');
this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
},
_onLayerChange: function (e) {

8
dist/leaflet.js vendored

File diff suppressed because one or more lines are too long