bc82990dd72a7150e6b8ed5d2aa1b6e92dbba1eb
[lhc/web/www.git] / www / plugins / gis / lib / leaflet / plugins / leaflet-providers.js
1 (function (root, factory) {
2 if (typeof define === 'function' && define.amd) {
3 // AMD. Register as an anonymous module.
4 define(['leaflet'], factory);
5 } else if (typeof modules === 'object' && module.exports) {
6 // define a Common JS module that relies on 'leaflet'
7 module.exports = factory(require('leaflet'));
8 } else {
9 // Assume Leaflet is loaded into global object L already
10 factory(L);
11 }
12 }(this, function (L) {
13 'use strict';
14
15 L.TileLayer.Provider = L.TileLayer.extend({
16 initialize: function (arg, options) {
17 var providers = L.TileLayer.Provider.providers;
18
19 var parts = arg.split('.');
20
21 var providerName = parts[0];
22 var variantName = parts[1];
23
24 if (!providers[providerName]) {
25 throw 'No such provider (' + providerName + ')';
26 }
27
28 var provider = {
29 url: providers[providerName].url,
30 options: providers[providerName].options
31 };
32
33 // overwrite values in provider from variant.
34 if (variantName && 'variants' in providers[providerName]) {
35 if (!(variantName in providers[providerName].variants)) {
36 throw 'No such variant of ' + providerName + ' (' + variantName + ')';
37 }
38 var variant = providers[providerName].variants[variantName];
39 var variantOptions;
40 if (typeof variant === 'string') {
41 variantOptions = {
42 variant: variant
43 };
44 } else {
45 variantOptions = variant.options;
46 }
47 provider = {
48 url: variant.url || provider.url,
49 options: L.Util.extend({}, provider.options, variantOptions)
50 };
51 } else if (typeof provider.url === 'function') {
52 provider.url = provider.url(parts.splice(1, parts.length - 1).join('.'));
53 }
54
55 var forceHTTP = window.location.protocol === 'file:' || provider.options.forceHTTP;
56 if (provider.url.indexOf('//') === 0 && forceHTTP) {
57 provider.url = 'http:' + provider.url;
58 }
59
60 // If retina option is set
61 if (provider.options.retina) {
62 // Check retina screen
63 if (options.detectRetina && L.Browser.retina) {
64 // The retina option will be active now
65 // But we need to prevent Leaflet retina mode
66 options.detectRetina = false;
67 } else {
68 // No retina, remove option
69 provider.options.retina = '';
70 }
71 }
72
73 // replace attribution placeholders with their values from toplevel provider attribution,
74 // recursively
75 var attributionReplacer = function (attr) {
76 if (attr.indexOf('{attribution.') === -1) {
77 return attr;
78 }
79 return attr.replace(/\{attribution.(\w*)\}/,
80 function (match, attributionName) {
81 return attributionReplacer(providers[attributionName].options.attribution);
82 }
83 );
84 };
85 provider.options.attribution = attributionReplacer(provider.options.attribution);
86
87 // Compute final options combining provider options with any user overrides
88 var layerOpts = L.Util.extend({}, provider.options, options);
89 L.TileLayer.prototype.initialize.call(this, provider.url, layerOpts);
90 }
91 });
92
93 /**
94 * Definition of providers.
95 * see http://leafletjs.com/reference.html#tilelayer for options in the options map.
96 */
97
98 L.TileLayer.Provider.providers = {
99 OpenStreetMap: {
100 url: '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
101 options: {
102 maxZoom: 19,
103 attribution:
104 '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
105 },
106 variants: {
107 Mapnik: {},
108 BlackAndWhite: {
109 url: 'http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png',
110 options: {
111 maxZoom: 18
112 }
113 },
114 DE: {
115 url: 'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
116 options: {
117 maxZoom: 18
118 }
119 },
120 France: {
121 url: 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
122 options: {
123 attribution: '&copy; Openstreetmap France | {attribution.OpenStreetMap}'
124 }
125 },
126 HOT: {
127 url: 'http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png',
128 options: {
129 attribution: '{attribution.OpenStreetMap}, Tiles courtesy of <a href="http://hot.openstreetmap.org/" target="_blank">Humanitarian OpenStreetMap Team</a>'
130 }
131 }
132 }
133 },
134 OpenSeaMap: {
135 url: 'http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png',
136 options: {
137 attribution: 'Map data: &copy; <a href="http://www.openseamap.org">OpenSeaMap</a> contributors'
138 }
139 },
140 OpenTopoMap: {
141 url: '//{s}.tile.opentopomap.org/{z}/{x}/{y}.png',
142 options: {
143 maxZoom: 16,
144 attribution: 'Map data: {attribution.OpenStreetMap}, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: &copy; <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'
145 }
146 },
147 Thunderforest: {
148 url: '//{s}.tile.thunderforest.com/{variant}/{z}/{x}/{y}.png',
149 options: {
150 attribution:
151 '&copy; <a href="http://www.thunderforest.com/">Thunderforest</a>, {attribution.OpenStreetMap}',
152 variant: 'cycle'
153 },
154 variants: {
155 OpenCycleMap: 'cycle',
156 Transport: {
157 options: {
158 variant: 'transport',
159 maxZoom: 19
160 }
161 },
162 TransportDark: {
163 options: {
164 variant: 'transport-dark',
165 maxZoom: 19
166 }
167 },
168 SpinalMap: {
169 options: {
170 variant: 'spinal-map',
171 maxZoom: 11
172 }
173 },
174 Landscape: 'landscape',
175 Outdoors: 'outdoors',
176 Pioneer: 'pioneer'
177 }
178 },
179 OpenMapSurfer: {
180 url: 'http://korona.geog.uni-heidelberg.de/tiles/{variant}/x={x}&y={y}&z={z}',
181 options: {
182 maxZoom: 20,
183 variant: 'roads',
184 attribution: 'Imagery from <a href="http://giscience.uni-hd.de/">GIScience Research Group @ University of Heidelberg</a> &mdash; Map data {attribution.OpenStreetMap}'
185 },
186 variants: {
187 Roads: 'roads',
188 AdminBounds: {
189 options: {
190 variant: 'adminb',
191 maxZoom: 19
192 }
193 },
194 Grayscale: {
195 options: {
196 variant: 'roadsg',
197 maxZoom: 19
198 }
199 }
200 }
201 },
202 Hydda: {
203 url: 'http://{s}.tile.openstreetmap.se/hydda/{variant}/{z}/{x}/{y}.png',
204 options: {
205 variant: 'full',
206 attribution: 'Tiles courtesy of <a href="http://openstreetmap.se/" target="_blank">OpenStreetMap Sweden</a> &mdash; Map data {attribution.OpenStreetMap}'
207 },
208 variants: {
209 Full: 'full',
210 Base: 'base',
211 RoadsAndLabels: 'roads_and_labels'
212 }
213 },
214 MapQuestOpen: {
215 /* Mapquest does support https, but with a different subdomain:
216 * https://otile{s}-s.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.{ext}
217 * which makes implementing protocol relativity impossible.
218 */
219 url: 'http://otile{s}.mqcdn.com/tiles/1.0.0/{type}/{z}/{x}/{y}.{ext}',
220 options: {
221 type: 'map',
222 ext: 'jpg',
223 attribution:
224 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> &mdash; ' +
225 'Map data {attribution.OpenStreetMap}',
226 subdomains: '1234'
227 },
228 variants: {
229 OSM: {},
230 Aerial: {
231 options: {
232 type: 'sat',
233 attribution:
234 'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> &mdash; ' +
235 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency'
236 }
237 },
238 HybridOverlay: {
239 options: {
240 type: 'hyb',
241 ext: 'png',
242 opacity: 0.9
243 }
244 }
245 }
246 },
247 MapBox: {
248 url: '//api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}',
249 options: {
250 attribution:
251 'Imagery from <a href="http://mapbox.com/about/maps/">MapBox</a> &mdash; ' +
252 'Map data {attribution.OpenStreetMap}',
253 subdomains: 'abcd'
254 }
255 },
256 Stamen: {
257 url: '//stamen-tiles-{s}.a.ssl.fastly.net/{variant}/{z}/{x}/{y}.{ext}',
258 options: {
259 attribution:
260 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, ' +
261 '<a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; ' +
262 'Map data {attribution.OpenStreetMap}',
263 subdomains: 'abcd',
264 minZoom: 0,
265 maxZoom: 20,
266 variant: 'toner',
267 ext: 'png'
268 },
269 variants: {
270 Toner: 'toner',
271 TonerBackground: 'toner-background',
272 TonerHybrid: 'toner-hybrid',
273 TonerLines: 'toner-lines',
274 TonerLabels: 'toner-labels',
275 TonerLite: 'toner-lite',
276 Watercolor: {
277 options: {
278 variant: 'watercolor',
279 minZoom: 1,
280 maxZoom: 16
281 }
282 },
283 Terrain: {
284 options: {
285 variant: 'terrain',
286 minZoom: 4,
287 maxZoom: 18,
288 bounds: [[22, -132], [70, -56]]
289 }
290 },
291 TerrainBackground: {
292 options: {
293 variant: 'terrain-background',
294 minZoom: 4,
295 maxZoom: 18,
296 bounds: [[22, -132], [70, -56]]
297 }
298 },
299 TopOSMRelief: {
300 options: {
301 variant: 'toposm-color-relief',
302 ext: 'jpg',
303 bounds: [[22, -132], [51, -56]]
304 }
305 },
306 TopOSMFeatures: {
307 options: {
308 variant: 'toposm-features',
309 bounds: [[22, -132], [51, -56]],
310 opacity: 0.9
311 }
312 }
313 }
314 },
315 Esri: {
316 url: '//server.arcgisonline.com/ArcGIS/rest/services/{variant}/MapServer/tile/{z}/{y}/{x}',
317 options: {
318 variant: 'World_Street_Map',
319 attribution: 'Tiles &copy; Esri'
320 },
321 variants: {
322 WorldStreetMap: {
323 options: {
324 attribution:
325 '{attribution.Esri} &mdash; ' +
326 'Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012'
327 }
328 },
329 DeLorme: {
330 options: {
331 variant: 'Specialty/DeLorme_World_Base_Map',
332 minZoom: 1,
333 maxZoom: 11,
334 attribution: '{attribution.Esri} &mdash; Copyright: &copy;2012 DeLorme'
335 }
336 },
337 WorldTopoMap: {
338 options: {
339 variant: 'World_Topo_Map',
340 attribution:
341 '{attribution.Esri} &mdash; ' +
342 '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'
343 }
344 },
345 WorldImagery: {
346 options: {
347 variant: 'World_Imagery',
348 attribution:
349 '{attribution.Esri} &mdash; ' +
350 'Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
351 }
352 },
353 WorldTerrain: {
354 options: {
355 variant: 'World_Terrain_Base',
356 maxZoom: 13,
357 attribution:
358 '{attribution.Esri} &mdash; ' +
359 'Source: USGS, Esri, TANA, DeLorme, and NPS'
360 }
361 },
362 WorldShadedRelief: {
363 options: {
364 variant: 'World_Shaded_Relief',
365 maxZoom: 13,
366 attribution: '{attribution.Esri} &mdash; Source: Esri'
367 }
368 },
369 WorldPhysical: {
370 options: {
371 variant: 'World_Physical_Map',
372 maxZoom: 8,
373 attribution: '{attribution.Esri} &mdash; Source: US National Park Service'
374 }
375 },
376 OceanBasemap: {
377 options: {
378 variant: 'Ocean_Basemap',
379 maxZoom: 13,
380 attribution: '{attribution.Esri} &mdash; Sources: GEBCO, NOAA, CHS, OSU, UNH, CSUMB, National Geographic, DeLorme, NAVTEQ, and Esri'
381 }
382 },
383 NatGeoWorldMap: {
384 options: {
385 variant: 'NatGeo_World_Map',
386 maxZoom: 16,
387 attribution: '{attribution.Esri} &mdash; National Geographic, Esri, DeLorme, NAVTEQ, UNEP-WCMC, USGS, NASA, ESA, METI, NRCAN, GEBCO, NOAA, iPC'
388 }
389 },
390 WorldGrayCanvas: {
391 options: {
392 variant: 'Canvas/World_Light_Gray_Base',
393 maxZoom: 16,
394 attribution: '{attribution.Esri} &mdash; Esri, DeLorme, NAVTEQ'
395 }
396 }
397 }
398 },
399 OpenWeatherMap: {
400 url: 'http://{s}.tile.openweathermap.org/map/{variant}/{z}/{x}/{y}.png',
401 options: {
402 maxZoom: 19,
403 attribution: 'Map data &copy; <a href="http://openweathermap.org">OpenWeatherMap</a>',
404 opacity: 0.5
405 },
406 variants: {
407 Clouds: 'clouds',
408 CloudsClassic: 'clouds_cls',
409 Precipitation: 'precipitation',
410 PrecipitationClassic: 'precipitation_cls',
411 Rain: 'rain',
412 RainClassic: 'rain_cls',
413 Pressure: 'pressure',
414 PressureContour: 'pressure_cntr',
415 Wind: 'wind',
416 Temperature: 'temp',
417 Snow: 'snow'
418 }
419 },
420 HERE: {
421 /*
422 * HERE maps, formerly Nokia maps.
423 * These basemaps are free, but you need an API key. Please sign up at
424 * http://developer.here.com/getting-started
425 *
426 * Note that the base urls contain '.cit' whichs is HERE's
427 * 'Customer Integration Testing' environment. Please remove for production
428 * envirionments.
429 */
430 url:
431 '//{s}.{base}.maps.cit.api.here.com/maptile/2.1/' +
432 '{type}/{mapID}/{variant}/{z}/{x}/{y}/{size}/{format}?' +
433 'app_id={app_id}&app_code={app_code}&lg={language}',
434 options: {
435 attribution:
436 'Map &copy; 1987-2014 <a href="http://developer.here.com">HERE</a>',
437 subdomains: '1234',
438 mapID: 'newest',
439 'app_id': '<insert your app_id here>',
440 'app_code': '<insert your app_code here>',
441 base: 'base',
442 variant: 'normal.day',
443 maxZoom: 20,
444 type: 'maptile',
445 language: 'eng',
446 format: 'png8',
447 size: '256'
448 },
449 variants: {
450 normalDay: 'normal.day',
451 normalDayCustom: 'normal.day.custom',
452 normalDayGrey: 'normal.day.grey',
453 normalDayMobile: 'normal.day.mobile',
454 normalDayGreyMobile: 'normal.day.grey.mobile',
455 normalDayTransit: 'normal.day.transit',
456 normalDayTransitMobile: 'normal.day.transit.mobile',
457 normalNight: 'normal.night',
458 normalNightMobile: 'normal.night.mobile',
459 normalNightGrey: 'normal.night.grey',
460 normalNightGreyMobile: 'normal.night.grey.mobile',
461
462 basicMap: {
463 options: {
464 type: 'basetile'
465 }
466 },
467 mapLabels: {
468 options: {
469 type: 'labeltile',
470 format: 'png'
471 }
472 },
473 trafficFlow: {
474 options: {
475 base: 'traffic',
476 type: 'flowtile'
477 }
478 },
479 carnavDayGrey: 'carnav.day.grey',
480 hybridDay: {
481 options: {
482 base: 'aerial',
483 variant: 'hybrid.day'
484 }
485 },
486 hybridDayMobile: {
487 options: {
488 base: 'aerial',
489 variant: 'hybrid.day.mobile'
490 }
491 },
492 pedestrianDay: 'pedestrian.day',
493 pedestrianNight: 'pedestrian.night',
494 satelliteDay: {
495 options: {
496 base: 'aerial',
497 variant: 'satellite.day'
498 }
499 },
500 terrainDay: {
501 options: {
502 base: 'aerial',
503 variant: 'terrain.day'
504 }
505 },
506 terrainDayMobile: {
507 options: {
508 base: 'aerial',
509 variant: 'terrain.day.mobile'
510 }
511 }
512 }
513 },
514 FreeMapSK: {
515 url: 'http://t{s}.freemap.sk/T/{z}/{x}/{y}.jpeg',
516 options: {
517 minZoom: 8,
518 maxZoom: 16,
519 subdomains: '1234',
520 bounds: [[47.204642, 15.996093], [49.830896, 22.576904]],
521 attribution:
522 '{attribution.OpenStreetMap}, vizualization CC-By-SA 2.0 <a href="http://freemap.sk">Freemap.sk</a>'
523 }
524 },
525 MtbMap: {
526 url: 'http://tile.mtbmap.cz/mtbmap_tiles/{z}/{x}/{y}.png',
527 options: {
528 attribution:
529 '{attribution.OpenStreetMap} &amp; USGS'
530 }
531 },
532 CartoDB: {
533 url: 'http://{s}.basemaps.cartocdn.com/{variant}/{z}/{x}/{y}.png',
534 options: {
535 attribution: '{attribution.OpenStreetMap} &copy; <a href="http://cartodb.com/attributions">CartoDB</a>',
536 subdomains: 'abcd',
537 maxZoom: 19,
538 variant: 'light_all'
539 },
540 variants: {
541 Positron: 'light_all',
542 PositronNoLabels: 'light_nolabels',
543 PositronOnlyLabels: 'light_only_labels',
544 DarkMatter: 'dark_all',
545 DarkMatterNoLabels: 'dark_nolabels',
546 DarkMatterOnlyLabels: 'dark_only_labels'
547 }
548 },
549 HikeBike: {
550 url: 'http://{s}.tiles.wmflabs.org/{variant}/{z}/{x}/{y}.png',
551 options: {
552 maxZoom: 19,
553 attribution: '{attribution.OpenStreetMap}',
554 variant: 'hikebike'
555 },
556 variants: {
557 HikeBike: {},
558 HillShading: {
559 options: {
560 maxZoom: 15,
561 variant: 'hillshading'
562 }
563 }
564 }
565 },
566 BasemapAT: {
567 url: '//maps{s}.wien.gv.at/basemap/{variant}/normal/google3857/{z}/{y}/{x}.{format}',
568 options: {
569 maxZoom: 19,
570 attribution: 'Datenquelle: <a href="www.basemap.at">basemap.at</a>',
571 subdomains: ['', '1', '2', '3', '4'],
572 format: 'png',
573 bounds: [[46.358770, 8.782379], [49.037872, 17.189532]],
574 variant: 'geolandbasemap'
575 },
576 variants: {
577 basemap: 'geolandbasemap',
578 grau: 'bmapgrau',
579 overlay: 'bmapoverlay',
580 highdpi: {
581 options: {
582 variant: 'bmaphidpi',
583 format: 'jpeg'
584 }
585 },
586 orthofoto: {
587 options: {
588 variant: 'bmaporthofoto30cm',
589 format: 'jpeg'
590 }
591 }
592 }
593 },
594 NASAGIBS: {
595 url: '//map1.vis.earthdata.nasa.gov/wmts-webmerc/{variant}/default/{time}/{tilematrixset}{maxZoom}/{z}/{y}/{x}.{format}',
596 options: {
597 attribution:
598 'Imagery provided by services from the Global Imagery Browse Services (GIBS), operated by the NASA/GSFC/Earth Science Data and Information System ' +
599 '(<a href="https://earthdata.nasa.gov">ESDIS</a>) with funding provided by NASA/HQ.',
600 bounds: [[-85.0511287776, -179.999999975], [85.0511287776, 179.999999975]],
601 minZoom: 1,
602 maxZoom: 9,
603 format: 'jpg',
604 time: '',
605 tilematrixset: 'GoogleMapsCompatible_Level'
606 },
607 variants: {
608 ModisTerraTrueColorCR: 'MODIS_Terra_CorrectedReflectance_TrueColor',
609 ModisTerraBands367CR: 'MODIS_Terra_CorrectedReflectance_Bands367',
610 ViirsEarthAtNight2012: {
611 options: {
612 variant: 'VIIRS_CityLights_2012',
613 maxZoom: 8
614 }
615 },
616 ModisTerraLSTDay: {
617 options: {
618 variant: 'MODIS_Terra_Land_Surface_Temp_Day',
619 format: 'png',
620 maxZoom: 7,
621 opacity: 0.75
622 }
623 },
624 ModisTerraSnowCover: {
625 options: {
626 variant: 'MODIS_Terra_Snow_Cover',
627 format: 'png',
628 maxZoom: 8,
629 opacity: 0.75
630 }
631 },
632 ModisTerraAOD: {
633 options: {
634 variant: 'MODIS_Terra_Aerosol',
635 format: 'png',
636 maxZoom: 6,
637 opacity: 0.75
638 }
639 },
640 ModisTerraChlorophyll: {
641 options: {
642 variant: 'MODIS_Terra_Chlorophyll_A',
643 format: 'png',
644 maxZoom: 7,
645 opacity: 0.75
646 }
647 }
648 }
649 },
650 NLS: {
651 // NLS maps are copyright National library of Scotland.
652 // http://maps.nls.uk/projects/api/index.html
653 // Please contact NLS for anything other than non-commercial low volume usage
654 //
655 // Map sources: Ordnance Survey 1:1m to 1:63K, 1920s-1940s
656 // z0-9 - 1:1m
657 // z10-11 - quarter inch (1:253440)
658 // z12-18 - one inch (1:63360)
659 url: '//nls-{s}.tileserver.com/nls/{z}/{x}/{y}.jpg',
660 options: {
661 attribution: '<a href="http://geo.nls.uk/maps/">National Library of Scotland Historic Maps</a>',
662 bounds: [[49.6, -12], [61.7, 3]],
663 minZoom: 1,
664 maxZoom: 18,
665 subdomains: '0123',
666 }
667 }
668 };
669
670 L.tileLayer.provider = function (provider, options) {
671 return new L.TileLayer.Provider(provider, options);
672 };
673
674 return L;
675 }));