-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomTileLayer.js
146 lines (133 loc) · 5.45 KB
/
RandomTileLayer.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
L.RandomTileLayer = L.TileLayer.extend({
// These are taken from https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js
options: {
providers: [
{
name: "Stamen Toner",
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
'<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — ' +
'Map data {attribution.OpenStreetMap}',
url: "https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png"
},
{
name: "Stamen Watercolor",
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
'<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — ' +
'Map data {attribution.OpenStreetMap}',
url: "https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png"
},
{
name: "ESRI WorldTopoMap",
attribution: 'Tiles © Esri — ' +
'Esri, DeLorme, NAVTEQ, TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ordnance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User Community',
url: "//server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/{z}/{y}/{x}"
},
{
name: "ESRI WorldImagery",
attribution: 'Tiles © Esri — ' +
'Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community',
url: "//server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
},
{
name: "ESRI WorldTerrain",
attribution: 'Tiles © Esri — ' +
'Source: USGS, Esri, TANA, DeLorme, and NPS',
url: "//server.arcgisonline.com/ArcGIS/rest/services/World_Terrain_Base/MapServer/tile/{z}/{y}/{x}"
},
{
name: "ESRI WorldTerrain",
attribution: 'Tiles © Esri — ' +
'Esri, DeLorme, NAVTEQ',
url: "//server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}"
},
{
name: "Acetate Base",
attribution: '©2012 Esri & Stamen, Data from OSM and Natural Earth',
url: "http://a{s}.acetate.geoiq.com/tiles/acetate-base/{z}/{x}/{y}.png"
},
{
name: "CartoDB DarkMatter",
attribution: '{attribution.OpenStreetMap} © <a href="http://cartodb.com/attributions">CartoDB</a>',
url: "http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
},
{
name: "CartoDB Positron",
attribution: '{attribution.OpenStreetMap} © <a href="http://cartodb.com/attributions">CartoDB</a>',
url: "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
},
{
name: "OSM",
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
},
{
name: "OSM France",
attribution: '© Openstreetmap France | © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
url: "http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png"
},
{
name: "Thunderforest Outdoors",
attribution: '© <a href="http://www.opencyclemap.org">OpenCycleMap</a>, {attribution.OpenStreetMap}',
url: "//{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png"
},
{
name: "Thunderforest Transport Dark",
attribution: '© <a href="http://www.opencyclemap.org">OpenCycleMap</a>, {attribution.OpenStreetMap}',
url: "//{s}.tile.thunderforest.com/transport-dark/{z}/{x}/{y}.png"
},
{
name: "OpenMapSurfer Greyscale",
attribution: 'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> — Map data, {attribution.OpenStreetMap}',
url: "http://openmapsurfer.uni-hd.de/tiles/roadsg/x={x}&y={y}&z={z}"
}
],
maxZoom: 18,
subdomains: 'abc',
errorTileUrl: '',
zoomOffset: 0,
maxNativeZoom: null, // Number
tms: false,
zoomReverse: false,
detectRetina: false,
crossOrigin: false
},
initialize: function (options) {
options = L.setOptions(this, options);
// detecting retina displays, adjusting tileSize and zoom levels
if (options.detectRetina && L.Browser.retina && options.maxZoom > 0) {
options.tileSize = Math.floor(options.tileSize / 2);
options.zoomOffset++;
options.minZoom = Math.max(0, options.minZoom);
options.maxZoom--;
}
if (typeof options.subdomains === 'string') {
options.subdomains = options.subdomains.split('');
}
// for https://github.com/Leaflet/Leaflet/issues/137
if (!L.Browser.android) {
this.on('tileunload', this._onTileRemove);
}
},
setUrl: function (url, noRedraw) {
this._url = this._getUrl();
if (!noRedraw) {
this.redraw();
}
return this;
},
getTileUrl: function (coords) {
return L.Util.template(this._getUrl(), L.extend({
r: this.options.detectRetina && L.Browser.retina && this.options.maxZoom > 0 ? '@2x' : '',
s: this._getSubdomain(coords),
x: coords.x,
y: this.options.tms ? this._globalTileRange.max.y - coords.y : coords.y,
z: this._getZoomForUrl()
}, this.options));
},
_getUrl: function() {
return this.options.providers[Math.floor(Math.random() * (this.options.providers.length))].url;
}
});
L.randomTileLayer = function (options) {
return new L.RandomTileLayer(options);
};