Adding support for minNativeZoom in TileLayer.js

This commit is contained in:
Julio Garcia 2016-11-08 10:02:41 -08:00 committed by Per Liedman
parent 4c484462dc
commit 4eba3a0973

View File

@ -48,6 +48,12 @@ L.TileLayer = L.GridLayer.extend({
// from `maxNativeZoom` level and auto-scaled.
maxNativeZoom: null,
// @option minNativeZoom: Number = null
// Minimum zoom number the tile source has available. If it is specified,
// the tiles on all zoom levels lower than `minNativeZoom` will be loaded
// from `minNativeZoom` level and auto-scaled.
minNativeZoom: null,
// @option subdomains: String|String[] = 'abc'
// Subdomains of the tile service. Can be passed in the form of one string (where each letter is a subdomain name) or an array of strings.
subdomains: 'abc',
@ -197,12 +203,20 @@ L.TileLayer = L.GridLayer.extend({
var map = this._map,
tileSize = L.GridLayer.prototype.getTileSize.call(this),
zoom = this._tileZoom + this.options.zoomOffset,
zoomN = this.options.maxNativeZoom;
minNativeZoom = this.options.minNativeZoom,
maxNativeZoom = this.options.maxNativeZoom;
// increase tile size when overscaling
return zoomN !== null && zoom > zoomN ?
tileSize.divideBy(map.getZoomScale(zoomN, zoom)).round() :
tileSize;
// decrease tile size when scaling below minNativeZoom
if (minNativeZoom !== null && zoom < minNativeZoom) {
return tileSize.divideBy(map.getZoomScale(minNativeZoom, zoom)).round();
}
// increase tile size when scaling above maxNativeZoom
if(maxNativeZoom !== null && zoom > maxNativeZoom){
return tileSize.divideBy(map.getZoomScale(maxNativeZoom, zoom)).round();
}
return tileSize;
},
_onTileRemove: function (e) {
@ -210,17 +224,29 @@ L.TileLayer = L.GridLayer.extend({
},
_getZoomForUrl: function () {
var zoom = this._tileZoom,
maxZoom = this.options.maxZoom,
zoomReverse = this.options.zoomReverse,
zoomOffset = this.options.zoomOffset,
minNativeZoom = this.options.minNativeZoom,
maxNativeZoom = this.options.maxNativeZoom;
var options = this.options,
zoom = this._tileZoom;
if (options.zoomReverse) {
zoom = options.maxZoom - zoom;
if (zoomReverse) {
zoom = maxZoom - zoom;
}
zoom += options.zoomOffset;
zoom += zoomOffset;
return options.maxNativeZoom !== null ? Math.min(zoom, options.maxNativeZoom) : zoom;
if (minNativeZoom !== null && zoom < minNativeZoom) {
return minNativeZoom;
}
// increase tile size when scaling above maxNativeZoom
if(maxNativeZoom !== null && zoom > maxNativeZoom) {
return maxNativeZoom;
}
return zoom;
},
_getSubdomain: function (tilePoint) {