more global refactoring
This commit is contained in:
parent
0474023675
commit
e5f934e97f
@ -11,16 +11,25 @@ L.Control.Attribution = L.Control.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onAdd: function (map) {
|
onAdd: function (map) {
|
||||||
this._map = map;
|
|
||||||
|
|
||||||
this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
|
this._container = L.DomUtil.create('div', 'leaflet-control-attribution');
|
||||||
L.DomEvent.disableClickPropagation(this._container);
|
L.DomEvent.disableClickPropagation(this._container);
|
||||||
|
|
||||||
|
map
|
||||||
|
.on('layeradd', this._onLayerAdd, this)
|
||||||
|
.on('layerremove', this._onLayerRemove, this);
|
||||||
|
|
||||||
this._update();
|
this._update();
|
||||||
|
|
||||||
return this._container;
|
return this._container;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onRemove: function (map) {
|
||||||
|
map
|
||||||
|
.off('layeradd', this._onLayerAdd)
|
||||||
|
.off('layerremove', this._onLayerRemove);
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
setPrefix: function (prefix) {
|
setPrefix: function (prefix) {
|
||||||
this.options.prefix = prefix;
|
this.options.prefix = prefix;
|
||||||
this._update();
|
this._update();
|
||||||
@ -65,5 +74,27 @@ L.Control.Attribution = L.Control.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._container.innerHTML = prefixAndAttribs.join(' — ');
|
this._container.innerHTML = prefixAndAttribs.join(' — ');
|
||||||
|
},
|
||||||
|
|
||||||
|
_onLayerAdd: function (e) {
|
||||||
|
if (e.layer.getAttribution) {
|
||||||
|
this.addAttribution(e.layer.getAttribution());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_onLayerRemove: function (e) {
|
||||||
|
if (e.layer.getAttribution) {
|
||||||
|
this.removeAttribution(e.layer.getAttribution());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
L.Map.mergeOptions({
|
||||||
|
attributionControl: true
|
||||||
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook(function () {
|
||||||
|
if (this.options.attributionControl) {
|
||||||
|
this.attributionControl = (new L.Control.Attribution()).addTo(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -26,3 +26,14 @@ L.Control.Zoom = L.Control.extend({
|
|||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.mergeOptions({
|
||||||
|
zoomControl: true
|
||||||
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook(function () {
|
||||||
|
if (this.options.zoomControl) {
|
||||||
|
this.zoomControl = new L.Control.Zoom();
|
||||||
|
this.addControl(this.zoomControl);
|
||||||
|
}
|
||||||
|
});
|
@ -16,9 +16,10 @@ L.Util = {
|
|||||||
return dest;
|
return dest;
|
||||||
},
|
},
|
||||||
|
|
||||||
bind: function (/*Function*/ fn, /*Object*/ obj) /*-> Object*/ {
|
bind: function (fn, obj) { // (Function, Object) -> Function
|
||||||
|
var args = Array.prototype.slice.call(arguments, 2);
|
||||||
return function () {
|
return function () {
|
||||||
return fn.apply(obj, arguments);
|
return fn.apply(obj, args || arguments);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -101,6 +102,7 @@ L.Util = {
|
|||||||
|
|
||||||
setOptions: function (obj, options) {
|
setOptions: function (obj, options) {
|
||||||
obj.options = L.Util.extend({}, obj.options, options);
|
obj.options = L.Util.extend({}, obj.options, options);
|
||||||
|
return obj.options;
|
||||||
},
|
},
|
||||||
|
|
||||||
getParamString: function (obj) {
|
getParamString: function (obj) {
|
||||||
|
@ -3,6 +3,7 @@ L.CRS.EPSG3395 = L.Util.extend({}, L.CRS, {
|
|||||||
code: 'EPSG:3395',
|
code: 'EPSG:3395',
|
||||||
|
|
||||||
projection: L.Projection.Mercator,
|
projection: L.Projection.Mercator,
|
||||||
|
|
||||||
transformation: (function () {
|
transformation: (function () {
|
||||||
var m = L.Projection.Mercator,
|
var m = L.Projection.Mercator,
|
||||||
r = m.R_MAJOR,
|
r = m.R_MAJOR,
|
||||||
|
@ -5,7 +5,7 @@ L.CRS.EPSG3857 = L.Util.extend({}, L.CRS, {
|
|||||||
projection: L.Projection.SphericalMercator,
|
projection: L.Projection.SphericalMercator,
|
||||||
transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5),
|
transformation: new L.Transformation(0.5 / Math.PI, 0.5, -0.5 / Math.PI, 0.5),
|
||||||
|
|
||||||
project: function (/*LatLng*/ latlng)/*-> Point*/ {
|
project: function (latlng) { // (LatLng) -> Point
|
||||||
var projectedPoint = this.projection.project(latlng),
|
var projectedPoint = this.projection.project(latlng),
|
||||||
earthRadius = 6378137;
|
earthRadius = 6378137;
|
||||||
return projectedPoint.multiplyBy(earthRadius);
|
return projectedPoint.multiplyBy(earthRadius);
|
||||||
|
5
src/geo/crs/CRS.Simple.js
Normal file
5
src/geo/crs/CRS.Simple.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
L.CRS.Simple = L.Util.extend({}, L.CRS, {
|
||||||
|
projection: L.Projection.LonLat,
|
||||||
|
transformation: new L.Transformation(1, 0, 1, 0)
|
||||||
|
});
|
@ -1,17 +1,25 @@
|
|||||||
|
|
||||||
L.CRS = {
|
L.CRS = {
|
||||||
latLngToPoint: function (/*LatLng*/ latlng, /*Number*/ scale)/*-> Point*/ {
|
latLngToPoint: function (latlng, zoom) { // (LatLng, Number) -> Point
|
||||||
var projectedPoint = this.projection.project(latlng);
|
var projectedPoint = this.projection.project(latlng),
|
||||||
|
scale = this.scale(zoom);
|
||||||
|
|
||||||
return this.transformation._transform(projectedPoint, scale);
|
return this.transformation._transform(projectedPoint, scale);
|
||||||
},
|
},
|
||||||
|
|
||||||
pointToLatLng: function (/*Point*/ point, /*Number*/ scale, /*(optional) Boolean*/ unbounded)/*-> LatLng*/ {
|
pointToLatLng: function (point, zoom, unbounded) { // (Point, Number[, Boolean]) -> LatLng
|
||||||
var untransformedPoint = this.transformation.untransform(point, scale);
|
var scale = this.scale(zoom),
|
||||||
|
untransformedPoint = this.transformation.untransform(point, scale);
|
||||||
|
|
||||||
return this.projection.unproject(untransformedPoint, unbounded);
|
return this.projection.unproject(untransformedPoint, unbounded);
|
||||||
//TODO get rid of 'unbounded' everywhere
|
//TODO get rid of 'unbounded' everywhere
|
||||||
},
|
},
|
||||||
|
|
||||||
project: function (latlng) {
|
project: function (latlng) {
|
||||||
return this.projection.project(latlng);
|
return this.projection.project(latlng);
|
||||||
|
},
|
||||||
|
|
||||||
|
scale: function (zoom) {
|
||||||
|
return 256 * Math.pow(2, zoom);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -5,7 +5,7 @@ L.Projection.Mercator = {
|
|||||||
R_MINOR: 6356752.3142,
|
R_MINOR: 6356752.3142,
|
||||||
R_MAJOR: 6378137,
|
R_MAJOR: 6378137,
|
||||||
|
|
||||||
project: function (/*LatLng*/ latlng) /*-> Point*/ {
|
project: function (latlng) { // (LatLng) -> Point
|
||||||
var d = L.LatLng.DEG_TO_RAD,
|
var d = L.LatLng.DEG_TO_RAD,
|
||||||
max = this.MAX_LATITUDE,
|
max = this.MAX_LATITUDE,
|
||||||
lat = Math.max(Math.min(max, latlng.lat), -max),
|
lat = Math.max(Math.min(max, latlng.lat), -max),
|
||||||
@ -25,7 +25,7 @@ L.Projection.Mercator = {
|
|||||||
return new L.Point(x, y);
|
return new L.Point(x, y);
|
||||||
},
|
},
|
||||||
|
|
||||||
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
|
unproject: function (point, unbounded) { // (Point, Boolean) -> LatLng
|
||||||
var d = L.LatLng.RAD_TO_DEG,
|
var d = L.LatLng.RAD_TO_DEG,
|
||||||
r = this.R_MAJOR,
|
r = this.R_MAJOR,
|
||||||
r2 = this.R_MINOR,
|
r2 = this.R_MINOR,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
L.Projection.SphericalMercator = {
|
L.Projection.SphericalMercator = {
|
||||||
MAX_LATITUDE: 85.0511287798,
|
MAX_LATITUDE: 85.0511287798,
|
||||||
|
|
||||||
project: function (/*LatLng*/ latlng) /*-> Point*/ {
|
project: function (latlng) { // (LatLng) -> Point
|
||||||
var d = L.LatLng.DEG_TO_RAD,
|
var d = L.LatLng.DEG_TO_RAD,
|
||||||
max = this.MAX_LATITUDE,
|
max = this.MAX_LATITUDE,
|
||||||
lat = Math.max(Math.min(max, latlng.lat), -max),
|
lat = Math.max(Math.min(max, latlng.lat), -max),
|
||||||
@ -13,7 +13,7 @@ L.Projection.SphericalMercator = {
|
|||||||
return new L.Point(x, y);
|
return new L.Point(x, y);
|
||||||
},
|
},
|
||||||
|
|
||||||
unproject: function (/*Point*/ point, /*Boolean*/ unbounded) /*-> LatLng*/ {
|
unproject: function (point, unbounded) { // (Point, Boolean) -> LatLng
|
||||||
var d = L.LatLng.RAD_TO_DEG,
|
var d = L.LatLng.RAD_TO_DEG,
|
||||||
lng = point.x * d,
|
lng = point.x * d,
|
||||||
lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d;
|
lat = (2 * Math.atan(Math.exp(point.y)) - (Math.PI / 2)) * d;
|
||||||
|
@ -71,9 +71,14 @@ L.Popup = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_close: function () {
|
_close: function () {
|
||||||
if (this._map) {
|
var map = this._map;
|
||||||
this._map._popup = null;
|
|
||||||
this._map.removeLayer(this);
|
if (map) {
|
||||||
|
map._popup = null;
|
||||||
|
|
||||||
|
map
|
||||||
|
.removeLayer(this)
|
||||||
|
.fire('popupclose', {popup: this});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
140
src/map/Map.js
140
src/map/Map.js
@ -6,66 +6,32 @@ L.Map = L.Class.extend({
|
|||||||
includes: L.Mixin.Events,
|
includes: L.Mixin.Events,
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
// projection
|
crs: L.CRS.EPSG3857,
|
||||||
crs: L.CRS.EPSG3857 || L.CRS.EPSG4326,
|
|
||||||
scale: function (zoom) {
|
|
||||||
return 256 * Math.pow(2, zoom);
|
|
||||||
},
|
|
||||||
|
|
||||||
// state
|
/*
|
||||||
center: null,
|
center: LatLng,
|
||||||
zoom: null,
|
zoom: Number,
|
||||||
layers: [],
|
layers: Array,
|
||||||
|
*/
|
||||||
|
|
||||||
// controls
|
|
||||||
zoomControl: true,
|
|
||||||
attributionControl: true,
|
|
||||||
|
|
||||||
// animation
|
|
||||||
fadeAnimation: L.DomUtil.TRANSITION && !L.Browser.android,
|
fadeAnimation: L.DomUtil.TRANSITION && !L.Browser.android,
|
||||||
zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android && !L.Browser.mobileOpera,
|
trackResize: true
|
||||||
|
|
||||||
// misc
|
|
||||||
trackResize: true,
|
|
||||||
worldCopyJump: true
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
initialize: function (id, options) { // (HTMLElement or String, Object)
|
initialize: function (id, options) { // (HTMLElement or String, Object)
|
||||||
L.Util.setOptions(this, options);
|
options = L.Util.setOptions(this, options);
|
||||||
|
|
||||||
// TODO method is too big, refactor
|
|
||||||
|
|
||||||
var container = this._container = L.DomUtil.get(id);
|
|
||||||
|
|
||||||
if (container._leaflet) {
|
|
||||||
throw new Error("Map container is already initialized.");
|
|
||||||
}
|
|
||||||
container._leaflet = true;
|
|
||||||
|
|
||||||
|
this._initContainer(id);
|
||||||
this._initLayout();
|
this._initLayout();
|
||||||
|
this._initHooks();
|
||||||
if (L.DomEvent) {
|
this._initEvents();
|
||||||
this._initEvents();
|
|
||||||
if (L.Handler) {
|
|
||||||
this._initInteraction();
|
|
||||||
}
|
|
||||||
if (L.Control) {
|
|
||||||
this._initControls();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
options = this.options;
|
|
||||||
|
|
||||||
if (options.maxBounds) {
|
if (options.maxBounds) {
|
||||||
this.setMaxBounds(options.maxBounds);
|
this.setMaxBounds(options.maxBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
var center = options.center,
|
if (options.center && typeof options.zoom !== 'undefined') {
|
||||||
zoom = options.zoom;
|
this.setView(options.center, options.zoom, true);
|
||||||
|
|
||||||
if (center && typeof zoom !== 'undefined') {
|
|
||||||
this.setView(center, zoom, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._initLayers(options.layers);
|
this._initLayers(options.layers);
|
||||||
@ -76,7 +42,6 @@ L.Map = L.Class.extend({
|
|||||||
|
|
||||||
// replaced by animation-powered implementation in Map.PanAnimation.js
|
// replaced by animation-powered implementation in Map.PanAnimation.js
|
||||||
setView: function (center, zoom) {
|
setView: function (center, zoom) {
|
||||||
// reset the map view
|
|
||||||
this._resetView(center, this._limitZoom(zoom));
|
this._resetView(center, this._limitZoom(zoom));
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@ -172,9 +137,7 @@ L.Map = L.Class.extend({
|
|||||||
|
|
||||||
var id = L.Util.stamp(layer);
|
var id = L.Util.stamp(layer);
|
||||||
|
|
||||||
if (this._layers[id]) {
|
if (this._layers[id]) { return this; }
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._layers[id] = layer;
|
this._layers[id] = layer;
|
||||||
|
|
||||||
@ -192,10 +155,6 @@ L.Map = L.Class.extend({
|
|||||||
layer.on('load', this._onTileLayerLoad, this);
|
layer.on('load', this._onTileLayerLoad, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.attributionControl && layer.getAttribution) {
|
|
||||||
this.attributionControl.addAttribution(layer.getAttribution());
|
|
||||||
}
|
|
||||||
|
|
||||||
var onMapLoad = function () {
|
var onMapLoad = function () {
|
||||||
layer.onAdd(this, insertAtTheBottom);
|
layer.onAdd(this, insertAtTheBottom);
|
||||||
this.fire('layeradd', {layer: layer});
|
this.fire('layeradd', {layer: layer});
|
||||||
@ -225,10 +184,6 @@ L.Map = L.Class.extend({
|
|||||||
layer.off('load', this._onTileLayerLoad, this);
|
layer.off('load', this._onTileLayerLoad, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.attributionControl && layer.getAttribution) {
|
|
||||||
this.attributionControl.removeAttribution(layer.getAttribution());
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.fire('layerremove', {layer: layer});
|
return this.fire('layerremove', {layer: layer});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -253,16 +208,13 @@ L.Map = L.Class.extend({
|
|||||||
|
|
||||||
this.fire('move');
|
this.fire('move');
|
||||||
|
|
||||||
function fireMoveEnd() {
|
|
||||||
this.fire('moveend');
|
|
||||||
}
|
|
||||||
|
|
||||||
clearTimeout(this._sizeTimer);
|
clearTimeout(this._sizeTimer);
|
||||||
this._sizeTimer = setTimeout(L.Util.bind(fireMoveEnd, this), 200);
|
this._sizeTimer = setTimeout(L.Util.bind(this.fire, this, 'moveend'), 200);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// TODO handler.addTo
|
||||||
addHandler: function (name, HandlerClass) {
|
addHandler: function (name, HandlerClass) {
|
||||||
if (!HandlerClass) { return; }
|
if (!HandlerClass) { return; }
|
||||||
|
|
||||||
@ -278,7 +230,7 @@ L.Map = L.Class.extend({
|
|||||||
|
|
||||||
// public methods for getting map state
|
// public methods for getting map state
|
||||||
|
|
||||||
getCenter: function (unbounded) { // (Boolean)
|
getCenter: function (unbounded) { // (Boolean) -> LatLng
|
||||||
var viewHalf = this.getSize().divideBy(2),
|
var viewHalf = this.getSize().divideBy(2),
|
||||||
centerPoint = this._getTopLeftPoint().add(viewHalf);
|
centerPoint = this._getTopLeftPoint().add(viewHalf);
|
||||||
|
|
||||||
@ -412,18 +364,28 @@ L.Map = L.Class.extend({
|
|||||||
|
|
||||||
project: function (latlng, zoom) { // (LatLng[, Number]) -> Point
|
project: function (latlng, zoom) { // (LatLng[, Number]) -> Point
|
||||||
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
||||||
return this.options.crs.latLngToPoint(latlng, this.options.scale(zoom));
|
return this.options.crs.latLngToPoint(latlng, zoom);
|
||||||
},
|
},
|
||||||
|
|
||||||
unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng
|
unproject: function (point, zoom, unbounded) { // (Point[, Number, Boolean]) -> LatLng
|
||||||
// TODO remove unbounded, making it true all the time?
|
// TODO remove unbounded, making it true all the time?
|
||||||
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
zoom = typeof zoom === 'undefined' ? this._zoom : zoom;
|
||||||
return this.options.crs.pointToLatLng(point, this.options.scale(zoom), unbounded);
|
return this.options.crs.pointToLatLng(point, zoom, unbounded);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// private methods that modify map state
|
// private methods that modify map state
|
||||||
|
|
||||||
|
_initContainer: function (id) {
|
||||||
|
var container = this._container = L.DomUtil.get(id);
|
||||||
|
|
||||||
|
if (container._leaflet) {
|
||||||
|
throw new Error("Map container is already initialized.");
|
||||||
|
}
|
||||||
|
|
||||||
|
container._leaflet = true;
|
||||||
|
},
|
||||||
|
|
||||||
_initLayout: function () {
|
_initLayout: function () {
|
||||||
var container = this._container;
|
var container = this._container;
|
||||||
|
|
||||||
@ -469,6 +431,15 @@ L.Map = L.Class.extend({
|
|||||||
return L.DomUtil.create('div', className, container || this._objectsPane);
|
return L.DomUtil.create('div', className, container || this._objectsPane);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_initializers: [],
|
||||||
|
|
||||||
|
_initHooks: function () {
|
||||||
|
var i, len;
|
||||||
|
for (i = 0, len = this._initializers.length; i < len; i++) {
|
||||||
|
this._initializers[i].call(this);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
_resetView: function (center, zoom, preserveMapOffset, afterZoomAnim) {
|
_resetView: function (center, zoom, preserveMapOffset, afterZoomAnim) {
|
||||||
|
|
||||||
var zoomChanged = (this._zoom !== zoom);
|
var zoomChanged = (this._zoom !== zoom);
|
||||||
@ -510,7 +481,7 @@ L.Map = L.Class.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_initLayers: function (layers) {
|
_initLayers: function (layers) {
|
||||||
layers = layers instanceof Array ? layers : [layers];
|
layers = layers ? (layers instanceof Array ? layers : [layers]) : [];
|
||||||
|
|
||||||
this._layers = {};
|
this._layers = {};
|
||||||
this._tileLayersNum = 0;
|
this._tileLayersNum = 0;
|
||||||
@ -522,18 +493,6 @@ L.Map = L.Class.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_initControls: function () {
|
|
||||||
// TODO refactor, this should happen automatically
|
|
||||||
if (this.options.zoomControl) {
|
|
||||||
this.zoomControl = new L.Control.Zoom();
|
|
||||||
this.addControl(this.zoomControl);
|
|
||||||
}
|
|
||||||
if (this.options.attributionControl) {
|
|
||||||
this.attributionControl = new L.Control.Attribution();
|
|
||||||
this.addControl(this.attributionControl);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_rawPanBy: function (offset) {
|
_rawPanBy: function (offset) {
|
||||||
var newPos = L.DomUtil.getPosition(this._mapPane).subtract(offset);
|
var newPos = L.DomUtil.getPosition(this._mapPane).subtract(offset);
|
||||||
L.DomUtil.setPosition(this._mapPane, newPos);
|
L.DomUtil.setPosition(this._mapPane, newPos);
|
||||||
@ -543,6 +502,8 @@ L.Map = L.Class.extend({
|
|||||||
// map events
|
// map events
|
||||||
|
|
||||||
_initEvents: function () {
|
_initEvents: function () {
|
||||||
|
if (!L.DomEvent) { return; }
|
||||||
|
|
||||||
L.DomEvent.addListener(this._container, 'click', this._onMouseClick, this);
|
L.DomEvent.addListener(this._container, 'click', this._onMouseClick, this);
|
||||||
|
|
||||||
var events = ['dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'contextmenu'];
|
var events = ['dblclick', 'mousedown', 'mouseenter', 'mouseleave', 'mousemove', 'contextmenu'];
|
||||||
@ -594,15 +555,6 @@ L.Map = L.Class.extend({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_initInteraction: function () {
|
|
||||||
this
|
|
||||||
.addHandler('dragging', L.Map.Drag)
|
|
||||||
.addHandler('touchZoom', L.Map.TouchZoom)
|
|
||||||
.addHandler('doubleClickZoom', L.Map.DoubleClickZoom)
|
|
||||||
.addHandler('scrollWheelZoom', L.Map.ScrollWheelZoom)
|
|
||||||
.addHandler('boxZoom', L.Map.BoxZoom);
|
|
||||||
},
|
|
||||||
|
|
||||||
_onTileLayerLoad: function () {
|
_onTileLayerLoad: function () {
|
||||||
// TODO super-ugly, refactor!!!
|
// TODO super-ugly, refactor!!!
|
||||||
// clear scaled tiles after all new tiles are loaded (for performance)
|
// clear scaled tiles after all new tiles are loaded (for performance)
|
||||||
@ -638,3 +590,13 @@ L.Map = L.Class.extend({
|
|||||||
return Math.max(min, Math.min(max, zoom));
|
return Math.max(min, Math.min(max, zoom));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook = function (fn) {
|
||||||
|
var args = Array.prototype.slice.call(arguments, 1);
|
||||||
|
|
||||||
|
var init = typeof fn === 'function' ? fn : function () {
|
||||||
|
this[fn].apply(this, args);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.prototype._initializers.push(init);
|
||||||
|
};
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
|
L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
|
||||||
setView: function (center, zoom, forceReset) {
|
setView: function (center, zoom, forceReset) {
|
||||||
zoom = this._limitZoom(zoom);
|
zoom = this._limitZoom(zoom);
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
L.Map.mergeOptions({
|
||||||
|
zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android && !L.Browser.mobileOpera
|
||||||
|
});
|
||||||
|
|
||||||
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
|
||||||
_zoomToIfCenterInView: function (center, zoom, centerOffset) {
|
_zoomToIfCenterInView: function (center, zoom, centerOffset) {
|
||||||
|
|
||||||
|
@ -12,11 +12,7 @@ L.Map.include({
|
|||||||
|
|
||||||
closePopup: function () {
|
closePopup: function () {
|
||||||
if (this._popup) {
|
if (this._popup) {
|
||||||
this
|
this._popup._close();
|
||||||
.removeLayer(this._popup)
|
|
||||||
.fire('popupclose', {popup: this._popup});
|
|
||||||
|
|
||||||
this._popup = null;
|
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -78,3 +78,5 @@ L.Map.BoxZoom = L.Handler.extend({
|
|||||||
map.fitBounds(bounds);
|
map.fitBounds(bounds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook('addHandler', 'boxZoom', L.Map.BoxZoom);
|
@ -19,3 +19,5 @@ L.Map.DoubleClickZoom = L.Handler.extend({
|
|||||||
this.setView(e.latlng, this._zoom + 1);
|
this.setView(e.latlng, this._zoom + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook('addHandler', 'doubleClickZoom', L.Map.DoubleClickZoom);
|
@ -4,10 +4,15 @@
|
|||||||
|
|
||||||
L.Map.mergeOptions({
|
L.Map.mergeOptions({
|
||||||
dragging: true,
|
dragging: true,
|
||||||
|
|
||||||
inertia: !L.Browser.android,
|
inertia: !L.Browser.android,
|
||||||
inertiaDeceleration: L.Browser.touch ? 3000 : 2000, // px/s^2
|
inertiaDeceleration: L.Browser.touch ? 3000 : 2000, // px/s^2
|
||||||
inertiaMaxSpeed: L.Browser.touch ? 1500 : 1000, // px/s
|
inertiaMaxSpeed: L.Browser.touch ? 1500 : 1000, // px/s
|
||||||
inertiaThreshold: L.Browser.touch ? 32 : 16 // ms
|
inertiaThreshold: L.Browser.touch ? 32 : 16, // ms
|
||||||
|
|
||||||
|
// TODO refactor, move to CRS
|
||||||
|
worldCopyJump: true,
|
||||||
|
continuousWorld: false
|
||||||
});
|
});
|
||||||
|
|
||||||
L.Map.Drag = L.Handler.extend({
|
L.Map.Drag = L.Handler.extend({
|
||||||
@ -83,7 +88,7 @@ L.Map.Drag = L.Handler.extend({
|
|||||||
|
|
||||||
_onPreDrag: function () {
|
_onPreDrag: function () {
|
||||||
var map = this._map,
|
var map = this._map,
|
||||||
worldWidth = map.options.scale(map.getZoom()),
|
worldWidth = map.options.crs.scale(map.getZoom()),
|
||||||
halfWidth = Math.round(worldWidth / 2),
|
halfWidth = Math.round(worldWidth / 2),
|
||||||
dx = this._initialWorldOffset.x,
|
dx = this._initialWorldOffset.x,
|
||||||
x = this._draggable._newPos.x,
|
x = this._draggable._newPos.x,
|
||||||
@ -142,3 +147,5 @@ L.Map.Drag = L.Handler.extend({
|
|||||||
this.panInsideBounds(this.options.maxBounds);
|
this.panInsideBounds(this.options.maxBounds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook('addHandler', 'dragging', L.Map.Drag);
|
@ -56,3 +56,5 @@ L.Map.ScrollWheelZoom = L.Handler.extend({
|
|||||||
return map.unproject(newCenterPoint, map._zoom, true);
|
return map.unproject(newCenterPoint, map._zoom, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook('addHandler', 'scrollWheelZoom', L.Map.ScrollWheelZoom);
|
@ -95,3 +95,5 @@ L.Map.TouchZoom = L.Handler.extend({
|
|||||||
this._map._runAnimation(center, zoom, finalScale / this._scale, this._startCenter.add(centerOffset));
|
this._map._runAnimation(center, zoom, finalScale / this._scale, this._startCenter.add(centerOffset));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
L.Map.addInitHook('addHandler', 'touchZoom', L.Map.TouchZoom);
|
Loading…
Reference in New Issue
Block a user