forked from glenrobertson/leaflet-tilelayer-geojson
-
Notifications
You must be signed in to change notification settings - Fork 5
/
TileLayer.Overzoom.js
64 lines (56 loc) · 2.42 KB
/
TileLayer.Overzoom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
L.TileLayer.Overzoom = {
overzoomOptions: {
// List of available server zoom levels in ascending order. Empty means all
// client zooms are available (default). Allows to only request tiles at certain
// zooms and resizes tiles on the other zooms.
serverZooms: []
},
// override _getTileSize to add serverZooms (when maxNativeZoom is not defined)
_getTileSize: function() {
var map = this._map,
options = this.options,
zoom = map.getZoom() + options.zoomOffset,
zoomN = options.maxNativeZoom || this._getServerZoom(zoom);
// increase tile size when overscaling
//return zoomN && zoom > zoomN ?
var tileSize = zoomN && zoom !== zoomN ?
Math.round(map.getZoomScale(zoom) / map.getZoomScale(zoomN) * options.tileSize) :
options.tileSize;
//console.log('tileSize = ' + tileSize + ', zoomOffset = ' + this.options.zoomOffset + ', serverZoom = ' + zoomN + ', zoom = ' + zoom);
return tileSize;
},
_getZoomForUrl: function () {
var zoom = L.TileLayer.prototype._getZoomForUrl.call(this);
var result = this._getServerZoom(zoom);
//console.log('zoomForUrl = ' + result);
return result;
},
// Returns the appropriate server zoom to request tiles for the current zoom level.
// Next lower or equal server zoom to current zoom, or minimum server zoom if no lower
// (should be restricted by setting minZoom to avoid loading too many tiles).
_getServerZoom: function(zoom) {
var serverZooms = this.options.serverZooms || [],
result = zoom;
// expects serverZooms to be sorted ascending
for (var i = 0, len = serverZooms.length; i < len; i++) {
if (serverZooms[i] <= zoom) {
result = serverZooms[i];
} else {
if (i === 0) {
// zoom < smallest serverZoom
result = serverZooms[0];
}
break;
}
}
return result;
}
};
if (typeof L.TileLayer.Vector !== 'undefined') {
L.TileLayer.Vector.include(L.TileLayer.Overzoom);
L.TileLayer.Vector.mergeOptions(L.TileLayer.Overzoom.overzoomOptions);
}
if (typeof L.TileLayer.Div !== 'undefined') {
L.TileLayer.Div.include(L.TileLayer.Overzoom);
L.TileLayer.Div.mergeOptions(L.TileLayer.Overzoom.overzoomOptions);
}