-
Notifications
You must be signed in to change notification settings - Fork 6
/
iNat_UTFgrid_based_density_comparison_map.html
406 lines (376 loc) · 29.3 KB
/
iNat_UTFgrid_based_density_comparison_map.html
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="iNaturalist Observation Density Comparison Map Based on UTFGrid Data and Integrated in Leaflet.js" />
<title>iNaturalist Observation Density Comparison Map Based on UTFGrid Data and Integrated in Leaflet.js</title>
<style>
body { height:100vh; width:100vw; margin:0px; }
#nav { font:9pt Sans-serif; height:100vh; width:25vw; position:absolute; top:0vh; left:0vw; background:darkgray; }
#mapid { height:100vh; width:75vw; position:absolute; top:0vh; left:25vw; background:darkgray; }
p { margin:10px 10px 0px 10px; }
</style>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
<script>
// debug grid example from https://leafletjs.com/examples/extending/extending-2-layers.html
L.GridLayer.DebugCoords = L.GridLayer.extend({
createTile: function (coords) {
var tile = document.createElement('div');
tile.innerHTML = [coords.x, coords.y, coords.z].join(', ');
tile.style.outline = '1px solid red';
return tile;
}
});
L.gridLayer.debugCoords = function(opts) {
return new L.GridLayer.DebugCoords(opts);
};
// this allows a style filter to be applied to a basemap tile layer
L.TileLayer.StyleFilter = L.TileLayer.extend({
intialize: function (url, options) {
L.TileLayer.prototype.initialize.call(this, url, options);
},
styleFilter: function () {
var filters = this.options.filter || '';
return filters;
},
_initContainer: function () {
var tile = L.TileLayer.prototype._initContainer.call(this);
this._container.style.filter = this.styleFilter();
},
});
L.tileLayer.styleFilter = function (url, options) {
return new L.TileLayer.StyleFilter(url, options);
};
// iNaturalist UTFGrid Density Map
function freplacexyz(url,x,y,z) {
url = url.replace('{x}',x);
url = url.replace('{y}',y);
url = url.replace('{z}',z);
return url;
};
function fgetutfgrid(url) {
return fetch(url)
.then((response) => {
if (!response.ok) { throw new Error(response.status+': '+response.statusText); };
return response.json();
})
// .then((data) => { return data; })
.catch((err) => { console.error(err); });
};
L.GridLayer.UTFGridDensityMap = L.GridLayer.extend({
createTile: function (coords, done) {
var tile = document.createElement('canvas');
var tileSize = this.getTileSize();
tile.width = tileSize.x;
tile.height = tileSize.y;
var cellsPerTile = {x:64,y:64};
var cellSize = {x:tileSize.x/cellsPerTile.x,y:tileSize.y/cellsPerTile.y};
var ctx = tile.getContext('2d');
// default marker setups
var dmarker = {type:'relative',offset:{x:0,y:0},size:0.75};
var marker = null;
if (this.options.marker) {
marker = this.options.marker;
marker.type = marker.type || dmarker.type;
marker.size = marker.size || dmarker.size;
marker.offset = marker.offset || dmarker.offset;
}
else { marker = dmarkerOpacity };
var offset = marker.offset;
// get UTFgrid
var urlbase = this.options.url;
var url = new URL(urlbase);
var urlsp0 = new URLSearchParams(url.searchParams);
urlsp0.delete('d1b');
urlsp0.delete('d2b');
var urlsp1 = new URLSearchParams(url.searchParams);
urlsp1.set('d1',urlsp1.get('d1b'));
urlsp1.set('d2',urlsp1.get('d2b'));
urlsp1.delete('d1b');
urlsp1.delete('d2b');
urlbase = urlbase.replace(url.search,'');
url0 = urlbase+'?'+urlsp0;
url1 = urlbase+'?'+urlsp1;
var prom0 = fgetutfgrid(freplacexyz(url0,coords.x,coords.y,coords.z));
var prom1 = fgetutfgrid(freplacexyz(url1,coords.x,coords.y,coords.z));
Promise.all([prom0,prom1]).then(function(utfgrid) {
//draw markers on the tile canvas
//note that this code was originally written to assume a 64x64 UTFgrid.
//although the UTFgrid is still 64x64, the associated "grid tile" is actually only 32x32.
//theoretically, a 2x2 set of cells from the UTFgrid should correspond to a single cell from the "grid tile"; however, that is not actually the case (see https://forum.inaturalist.org/t/open-test-of-map-tile-improvements/7833/88).
//so this code attempts to mimic a 32x32 "grid tile" by using the bottom-right cell from each 2x2 set of UTFgrid cells.
//for (cx=0;cx<cellsPerTile.x;cx++) {
for (cx=0;cx<cellsPerTile.x/2;cx++) {
//for (cy=0;cy<cellsPerTile.y;cy++) {
for (cy=0;cy<cellsPerTile.y/2;cy++) {
//var cell = {x:cx,y:cy};
var cell = {x:cx*2+1,y:cy*2+1};
//for details about decoding the UTFgrid, see https://github.com/mapbox/utfgrid-spec/blob/master/1.2/utfgrid.md
var d = [];
for (u=0;u<utfgrid.length;u++) {
var i = utfgrid[u].grid[cell.y].charCodeAt(cell.x);
i = i-((i>=93)?34:(i>=35)?33:32);
d.push(utfgrid[u].data[utfgrid[u].keys[i]]);
};
for (j=0;j<d.length;j++) { d[j] = d[j] ? d[j].cellCount||0 : 0; } // set d = cellCount (set to 0 if undefined)
var markerColor = 0; // default to black
if (marker.type==='absolute') {
ctx.beginPath();
//var circleRadius = cellSize.x/2*marker.size;
//ctx.arc(cell.x*cellSize.x+cellSize.x/2+offset.x,cell.y*cellSize.y+cellSize.y/2+offset.y,circleRadius,0,2*Math.PI,false);
var circleRadius = cellSize.x*marker.size;
ctx.arc(cell.x*cellSize.x+offset.x,cell.y*cellSize.y+offset.y,circleRadius,0,2*Math.PI,false);
var dd = d[0]-d[1];
if ( (d[0]===0) && (d[1]===0) ) { // light gray ring
markerColor = 'rgba(128,128,128,0.15)';
ctx.strokeStyle = markerColor;
}
else if ( dd===0 ) { // gray ring
markerColor = 'rgba(64,64,64,0.50)';
ctx.strokeStyle = markerColor;
}
else if ( dd<0 ) { // decreases have a gray ring go from green through blue to magenta
var f = Math.log10(-dd);
f = (f>4)?4:f;
markerColor = 'hsla('+(120+(f*120/3))+',100%,50%,0.5)';
ctx.fillStyle = markerColor;
ctx.fill();
ctx.strokeStyle = 'rgba(64,64,64,0.50)'
}
else { // increases go from green through red to magenta (with no ring)
var f = Math.log10(dd);
f = (f>4)?4:f;
markerColor = 'hsla('+(120-(f*120/3))+',100%,50%,0.5)';
ctx.fillStyle = markerColor;
ctx.fill();
ctx.strokeStyle = markerColor;
};
ctx.stroke();
}
else {
ctx.beginPath();
//var circleRadius = cellSize.x/2*marker.size;
//ctx.arc(cell.x*cellSize.x+cellSize.x/2+offset.x,cell.y*cellSize.y+cellSize.y/2+offset.y,circleRadius,0,2*Math.PI,false);
var circleRadius = cellSize.x*marker.size;
ctx.arc(cell.x*cellSize.x+offset.x,cell.y*cellSize.y+offset.y,circleRadius,0,2*Math.PI,false);
if ( (d[0]===0) && (d[1]===0) ) { markerColor = 'rgba(128,128,128,0.15)'; } // light gray
else if ( d[1]<=0 ) {markerColor = 'rgba(192,0,0,0.50)'; } // dull red
else if ( d[0]<=0 ) { markerColor = 'rgba(0,0,192,0.50)'; } // dull blue
else {
var f = Math.log10(d[0]/d[1]);
f = (f<-1)?-1:(f>1)?1:f;
markerColor = 'hsla('+(120-(f*120))+',100%,50%,0.5)'; // green is no change (x1), high increase (x10) is red, high decrease (x0.1) is blue
ctx.fillStyle = markerColor;
ctx.fill();
};
ctx.strokeStyle = markerColor;
ctx.stroke();
};
};
};
});
// asynchronous call
setTimeout(function() {
done(null, tile);
}, 1000);
return tile;
}
});
L.gridLayer.utfGridDensityMap = function (options) {
return new L.GridLayer.UTFGridDensityMap(options);
};
</script>
</head>
<body>
<div id="nav">
<p>This map compares iNaturalist observation density between 2 time periods.</p>
<p>The current time period is defined by the paramters d1 (beginning observation date) and d2 (ending observation date), and the time period for comparison is defined by parameters d1b and d2b. You must input valid dates for all 4 of these parameters for this page to function properly. For example, this compares observations in 2019 to observations in 2018: <span id='exampleurl'></span>.</p>
<p>This will also handle other filter parameters added to the URL. For example, to see just bird observations, add "&taxon_id=3" to the end of the URL.</p>
<p>By default, the comparison is relative (A/B), and it is visualized on a log base 10 scale, where a value of 1 (1000% current vs comparison period) or more is red, a value of 0.5 (~316%) is yellow, a value of 0 (100%, or no change) is green, a value of -0.5 (~32%) is cyan, and a value of -1 (10%) or less is blue. In locations where there are no observations in the current time period, there will be a blue ring (unfilled circle). In cases where the comparison time period has no observations, there will be a red ring in that location.</p>
<p>There is also an optional absolute comparison (A-B), and it can be selected in the layer selector (in the top-right corner of the map). If you prefer absolute comparison by default instead of relative, use defaultstyle=absolute in your URL parameter string. Increases (A-B>0) are visualized on a log base 10 scale where a value of 0 (+1) is green, 1 (+10) is yellow-green, 2 (+100) is orange, 3 (+1000) is red, and 4 (+10000) or more is magenta. Decreases (A-B<0) have a gray ring and are fill-colored on an opposite log base 10 scale where 0 (-1) is green, 1 (-10) is blue-green, 2 (-100) is light blue, 3 (-1000) is dark blue, and 4 (-10000) or more is magenta. Zero change is denoted by a gray ring with no fill.</p>
<p>Default map center is 0,0 and default zoom is 2. You can change this by setting centerlat, centerlng, and defaultzoom parameters appropriately. Finally, you can hide the left pane by using hideleftpane=true.</p>
<p>For more information and other examples of UTFgrid-based density maps, see <span id='otherpage'></span></p>
</div>
<div id="mapid"></div>
<script>
//get parameters from the url
let winurlstr = window.location.href;
let winurlsearchstr = window.location.search;
let winurlexsearchstr = winurlstr.replace(winurlsearchstr,'');
let winurlparams = new URLSearchParams(winurlsearchstr.substring(1));
var taxon_id = winurlparams.get('taxon_id');
taxon_id = (taxon_id===null?null:taxon_id.split(',')[0]);
var place_id = winurlparams.get('place_id');
place_id = (place_id===null?null:place_id.split(',')[0]);
var scale_factor = winurlparams.get('scale_factor');
if (scale_factor) {
var sfarray = scale_factor.split(',');
for (sf=1;sf<6;sf++) { if (sfarray.length<=sf) {sfarray.push(sfarray[sf-1]);}; };
};
var centerlat = winurlparams.get('centerlat') || 0;
var centerlng = winurlparams.get('centerlng') || 0;
var defaultzoom = winurlparams.get('defaultzoom') || 2;
var defaultstyle = winurlparams.get('defaultstyle') || 'relative';
var hideleftpane = winurlparams.get('hideleftpane') || 'false';
var showtaxonplace = winurlparams.get('showtaxonplace') || 'false';
var showtaxonrange = winurlparams.get('showtaxonrange') || 'false';
var showplace = winurlparams.get('showplace') || 'false';
if (hideleftpane==='true') {
var mapdiv = document.getElementById('mapid');
mapdiv.style.left = '0vw';
mapdiv.style.width = '100vw';
var navdiv = document.getElementById('nav');
navdiv.style.visibility = 'hidden';
};
winurlparams.delete('scale_factor');
winurlparams.delete('centerlat');
winurlparams.delete('centerlng');
winurlparams.delete('defaultzoom');
winurlparams.delete('defaultstyle');
winurlparams.delete('hideleftpane');
winurlparams.delete('showtaxonplace');
winurlparams.delete('showtaxonrange');
winurlparams.delete('showplace');
var otherurl = winurlexsearchstr.replace('iNat_UTFgrid_based_density_comparison_map.html','iNat_UTFgrid_based_density_map_for_Leaflet.html');
document.getElementById('otherpage').innerHTML = '<a href="'+otherurl+'">'+otherurl+'</a>';
var exampleurl = winurlexsearchstr + '?d1=2022-01-01&d2=2022-12-31&d1b=2021-01-01&d2b=2021-12-31'
document.getElementById('exampleurl').innerHTML = '<a href="'+exampleurl+'">'+exampleurl+'</a>';
// the main iNat UTFGrid API
// note that iNat provides 4 UTFGrid endpoints. the grid and heatmap endpoints are interchangeable and the ones to use for this application.
let utfgridapi = {url:'https://api.inaturalist.org/v1/heatmap/{z}/{x}/{y}.grid.json',attr:'<a href="https://api.inaturalist.org/v1/docs/#!/UTFGrid/get_heatmap_zoom_x_y_grid_json">iNaturalist</a>'};
// iNat UTFGrid-based density map
var l_utfgdm_rel = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,attribution:utfgridapi.attr,marker:{type:'relative', size:0.75}})
var l_utfgdm_abs = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,attribution:utfgridapi.attr,marker:{type:'absolute', size:0.75}});
// other iNaturalist Observation Layers
let inat_urlbase = 'https://api.inaturalist.org/v1/';
let inat_points = {url:inat_urlbase+'points/{z}/{x}/{y}.png',description:'iNaturalist Observations (Points)',attribution:'<a href="https://api.inaturalist.org/v1/docs/#!/Observation_Tiles/get_points_zoom_x_y_png">iNaturalist observation data</a>'};
//let inat_circles = {url:inat_urlbase+'colored_heatmap/{z}/{x}/{y}.png',description:'iNaturalist Observations (Density Circles)',attribution:'<a href="https://api.inaturalist.org/v1/docs/#!/Observation_Tiles/get_colored_heatmap_zoom_x_y_png">iNaturalist observation data</a>'};
let inat_heat = {url:inat_urlbase+'heatmap/{z}/{x}/{y}.png',description:'iNaturalist Observations (Heatmap)',attribution:'<a href="https://api.inaturalist.org/v1/docs/#!/Observation_Tiles/get_heatmap_zoom_x_y_png">iNaturalist observation data</a>'};
let inat_grid = {url:inat_urlbase+'grid/{z}/{x}/{y}.png',description:'iNaturalist Observations (Grid)',attribution:'<a href="https://api.inaturalist.org/v1/docs/#!/Observation_Tiles/get_grid_zoom_x_y_png">iNaturalist observation data</a>'};
let gbif_density_point_py = {url:'https://api.gbif.org/v2/map/occurrence/density/{z}/{x}/{y}@1x.png?srs=EPSG:3857&style=purpleYellow.point&publishingOrg=28eb1a3f-1c15-4a95-931a-4af90ecb574d',description:'iNaturalist Observations in GBIF',attribution:'<a href="https://www.gbif.org/developer/maps">GBIF occurrence data</a>'};
var l_inat_points = L.tileLayer(inat_points.url+'?'+winurlparams,{maxZoom:20, attribution:inat_points.attribution});
//var l_inat_circles = L.tileLayer(inat_circles.url+'?'+winurlparams,{maxZoom:20, attribution:inat_circles.attribution});
var l_inat_heat = L.tileLayer(inat_heat.url+'?'+winurlparams,{maxZoom:20, attribution:inat_heat.attribution});
var l_inat_grid = L.tileLayer(inat_grid.url+'?'+winurlparams,{maxZoom:20, attribution:inat_grid.attribution});
var l_gbif = L.tileLayer(gbif_density_point_py.url,{maxZoom:20, attribution:gbif_density_point_py.attribution});
// Other iNaturalist Layers
var l_inat_place = L.tileLayer(inat_urlbase+'places/'+place_id+'/{z}/{x}/{y}.png',{maxZoom:20, attribution:'<a href="'+inat_urlbase+'docs/#!/Polygon_Tiles/get_places_place_id_zoom_x_y_png">iNaturalist place polygon</a>'});
// iNaturalist Taxon Places Checklist and Range Layers
var l_inat_taxonplace = L.tileLayer(inat_urlbase+'taxon_places/'+taxon_id+'/{z}/{x}/{y}.png',{maxZoom:20, attribution:'<a href="'+inat_urlbase+'docs/#!/Polygon_Tiles/get_taxon_places_taxon_id_zoom_x_y_png">iNaturalist taxon place checklist data</a>'});
var l_inat_taxonrange = L.tileLayer(inat_urlbase+'taxon_ranges/'+taxon_id+'/{z}/{x}/{y}.png',{maxZoom:20, attribution:'<a href="'+inat_urlbase+'docs/#!/Polygon_Tiles/get_taxon_ranges_taxon_id_zoom_x_y_png">iNaturalist taxon range data</a>'});
// Stamen Watercolor (now housed at Smithsonian)
let s_watercolor = {url:'https://watercolormaps.collection.cooperhewitt.org/tile/watercolor/{z}/{x}/{y}.jpg', attribution:'Map <a href="https://watercolormaps.collection.cooperhewitt.org">tiles</a> by <a href="http://stamen.com">Stamen Design</a>, under <a href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="https://openstreetmap.org">OpenStreetMap</a>, under <a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'};
var l_stamen_watercolor = L.tileLayer(s_watercolor.url,{minZoom:0, maxZoom:20, attribution:s_watercolor.attribution});
var l_stamen_watercolor_mod_muted = L.tileLayer.styleFilter(s_watercolor.url,{minZoom:0, maxZoom:20, attribution:s_watercolor.attribution, filter:'grayscale(85%)'});
var l_stamen_watercolor_mod_gray = L.tileLayer.styleFilter(s_watercolor.url,{minZoom:0, maxZoom:20, attribution:s_watercolor.attribution, filter:'grayscale(100%)'});
var l_stamen_watercolor_mod_darkgray = L.tileLayer.styleFilter(s_watercolor.url,{minZoom:0, maxZoom:20, attribution:s_watercolor.attribution, filter:'grayscale(100%) brightness(50%)'});
// OpenStreetMaps & OpenTopoMap
let s_osm_std = {url:'https://tile.openstreetmap.org/{z}/{x}/{y}.png', attribution:'© <a href="https://osm.org/copyright">OpenStreetMap</a>/ODbL - tiles from <a href="https://osm.org/">OpenStreetMap</a>'};
var l_osm_std = L.tileLayer(s_osm_std.url, {minZoom:0, maxNativeZoom:19, maxZoom:20, attribution:s_osm_std.attribution});
var l_osm_de = L.tileLayer('https://tile.openstreetmap.de/{z}/{x}/{y}.png', {minZoom:0, maxZoom:20, attribution:'© <a href="https://osm.org/copyright">OpenStreetMap</a>/ODbL - tiles <a href="https://openstreetmap.de/">OpenStreetMap Deutschland</a>'});
var l_osm_fr = L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {minZoom:0, maxZoom:20, attribution:'données © <a href="https://osm.org/copyright">OpenStreetMap</a>/ODbL - rendu <a href="https://openstreetmap.fr">OSM France</a>'});
var l_osm_hot = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {minZoom:0, maxNativeZoom:19, maxZoom:20, attribution:'données © <a href="https://osm.org/copyright">OpenStreetMap</a>/ODbL - Tiles courtesy of <a href="https://hot.openstreetmap.org/">Humanitarian OpenStreetMap Team</a>'});
let s_otm = {url:'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', attribution:'Kartendaten: © <a href="https://openstreetmap.org/copyright">OpenStreetMap</a>-Mitwirkende, SRTM | Kartendarstellung: © <a href="http://opentopomap.org/">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'};
var l_otm = L.tileLayer(s_otm.url,{minZoom:0, maxNativeZoom:17, maxZoom:20, attribution:s_otm.attribution});
// mods
var l_otm_mod_muted = L.tileLayer.styleFilter(s_otm.url,{minZoom:0, maxNativeZoom:17, maxZoom:20, attribution:s_otm.attribution, filter:'grayscale(60%)'});
var l_osm_std_mod_lightgray = L.tileLayer.styleFilter(s_osm_std.url, {minZoom:0, maxZoom:20, attribution:s_osm_std.attribution, filter:'grayscale(100%)'});
var l_osm_std_mod_medgray = L.tileLayer.styleFilter(s_osm_std.url, {minZoom:0, maxZoom:20, attribution:s_osm_std.attribution, filter:'grayscale(100%) brightness(50%) contrast(150%)'});
var l_osm_std_mod_medgray2 = L.tileLayer.styleFilter(s_osm_std.url, {minZoom:0, maxZoom:20, attribution:s_osm_std.attribution, filter:'grayscale(100%) brightness(50%) contrast(150%) invert(100%) contrast(125%)'});
var l_osm_std_mod_darkgray = L.tileLayer.styleFilter(s_osm_std.url, {minZoom:0, maxZoom:20, attribution:s_osm_std.attribution, filter:'grayscale(100%) invert(100%)'});
var l_osm_std_mod_darkest = L.tileLayer.styleFilter(s_osm_std.url, {minZoom:0, maxZoom:20, attribution:s_osm_std.attribution, filter:'grayscale(100%) invert(100%) brightness(80%) contrast(125%)'});
// EOX -- http://maps.eox.at/
// capabilities (including attribution) -- https://tiles.maps.eox.at/wmts/1.0.0/WMTSCapabilities.xml
function f_eox_url(tileset,format) { return `https://tiles.maps.eox.at/wmts/1.0.0/${tileset}/default/g/{z}/{y}/{x}.${format}`; };
// basemaps
var l_eox_osm = L.tileLayer(f_eox_url('osm_3857','jpg'),{minZoom:0, maxNativeZoom:18, maxZoom:20, attribution:'<a href="https://maps.eox.at">OpenStreetMap</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Rendering © <a href="https://eox.at">EOX</a> and <a href="https://github.com/mapserver/basemaps">MapServer</a> }'});
var l_eox_blackmarble = L.tileLayer(f_eox_url('blackmarble_3857','jpg'),{minZoom:0, maxNativeZoom:18, maxZoom:20, attribution:'<a href="https://maps.eox.at">Black Marble</a> { © <a href="http://nasa.gov">NASA</a> }'});
var l_eox_bluemarble = L.tileLayer(f_eox_url('bluemarble_3857','jpg'),{minZoom:0, maxNativeZoom:18, maxZoom:20, attribution:'<a href="https://maps.eox.at">Blue Marble</a> { © <a href="http://nasa.gov">NASA</a> }'});
var l_eox_terrain = L.tileLayer(f_eox_url('terrain_3857','jpg'),{minZoom:0, maxNativeZoom:18, maxZoom:20, attribution:'<a href="https://maps.eox.at">Terrain</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors and <a href="https://maps.eox.at/#data">others</a>, Rendering © <a href="https://eox.at">EOX</a> }'});
var l_eox_terrain_light = L.tileLayer(f_eox_url('terrain-light_3857','jpg'),{minZoom:0, maxNativeZoom:18, maxZoom:20, attribution:'<a href="https://maps.eox.at">Terrain Light</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors and <a href="https://maps.eox.at/#data">others</a>, Rendering © <a href="https://eox.at">EOX</a> }'});
var l_eox_sentinel2_2020 = L.tileLayer(f_eox_url('s2cloudless-2020_3857','jpg'),{minZoom:0, maxZoom:20, attribution:'<a xmlns:dct="http://purl.org/dc/terms/" href="https://s2maps.eu" property="dct:title">Sentinel-2 cloudless - https://s2maps.eu</a> by <a xmlns:cc="http://creativecommons.org/ns#" href="https://eox.at" property="cc:attributionName" rel="cc:attributionURL">EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2020) released under <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>. For commercial usage please see <a href="https://cloudless.eox.at">https://cloudless.eox.at</a>'});
var l_eox_sentinel2_2019 = L.tileLayer(f_eox_url('s2cloudless-2019_3857','jpg'),{minZoom:0, maxZoom:20, attribution:'<a xmlns:dct="http://purl.org/dc/terms/" href="https://s2maps.eu" property="dct:title">Sentinel-2 cloudless - https://s2maps.eu</a> by <a xmlns:cc="http://creativecommons.org/ns#" href="https://eox.at" property="cc:attributionName" rel="cc:attributionURL">EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2019) released under <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>. For commercial usage please see <a href="https://cloudless.eox.at">https://cloudless.eox.at</a>'});
var l_eox_sentinel2_2018 = L.tileLayer(f_eox_url('s2cloudless-2018_3857','jpg'),{minZoom:0, maxZoom:20, attribution:'<a xmlns:dct="http://purl.org/dc/terms/" href="https://s2maps.eu" property="dct:title">Sentinel-2 cloudless - https://s2maps.eu</a> by <a xmlns:cc="http://creativecommons.org/ns#" href="https://eox.at" property="cc:attributionName" rel="cc:attributionURL">EOX IT Services GmbH</a> (Contains modified Copernicus Sentinel data 2019) released under <a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>. For commercial usage please see <a href="https://cloudless.eox.at">https://cloudless.eox.at</a>'});
// overlays
var l_eox_hydrography = L.tileLayer(f_eox_url('hydrography_3857','png'),{minZoom:0, maxZoom:20, attribution:'<a href="https://maps.eox.at">Hydrography overlay</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Rendering © <a href="https://eox.at">EOX</a> and <a href="https://github.com/mapserver/basemaps">MapServer</a> }'});
var l_eox_coastline = L.tileLayer(f_eox_url('coastline_3857','png'),{minZoom:0, maxZoom:20, attribution:'<a href="https://maps.eox.at">Coastline overlay</a> { Rendering © <a href="https://eox.at">EOX</a> }'});
var l_eox_streets = L.tileLayer(f_eox_url('streets_3857','png'),{minZoom:0, maxZoom:20, attribution:'<a href="https://maps.eox.at">Streets overlay</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Rendering © <a href="https://eox.at">EOX</a> and <a href="https://github.com/mapserver/basemaps">MapServer</a> }'});
var l_eox_overlay = L.tileLayer(f_eox_url('overlay_3857','png'),{minZoom:0, maxZoom:20, attribution:'<a href="https://maps.eox.at">Overlay</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Rendering © <a href="https://eox.at">EOX</a> and <a href="https://github.com/mapserver/basemaps">MapServer</a> }'});
var l_eox_overlay_bright = L.tileLayer(f_eox_url('overlay_bright_3857','png'),{minZoom:0, maxZoom:20, attribution:'<a href="https://maps.eox.at">Overlay bright</a> { Data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Rendering © <a href="https://eox.at">EOX</a> and <a href="https://github.com/mapserver/basemaps">MapServer</a> }'});
//debug layer
var l_debug = L.gridLayer.debugCoords();
var defaultlayers = [l_osm_std_mod_medgray];
if (taxon_id!==null) {
if (showtaxonplace==='true') {defaultlayers.push(l_inat_taxonplace)};
if (showtaxonrange==='true') {defaultlayers.push(l_inat_taxonrange)};
};
if (place_id!==null) {
if (showplace==='true') {defaultlayers.push(l_inat_place)};
};
defaultlayers.push(defaultstyle==='absolute'?l_utfgdm_abs:l_utfgdm_rel);
// create map, and set default center coordinates, zoom level, and layers
var mymap = L.map('mapid', {
center: [centerlat,centerlng],
zoom: defaultzoom,
layers: defaultlayers,
doubleClickZoom: false
});
// define available basemaps (can view only one at a time)
var basemaps = {
"Stamen Watercolor": l_stamen_watercolor,
"Stamen Watercolor Mod (Muted)": l_stamen_watercolor_mod_muted,
"Stamen Watercolor Mod (Gray)": l_stamen_watercolor_mod_gray,
"Stamen Watercolor Mod (Dark Gray)": l_stamen_watercolor_mod_darkgray,
"OpenTopoMap": l_otm,
"OpenTopoMap Mod (Muted)": l_otm_mod_muted,
"OpenStreetMap Standard": l_osm_std,
"OpenStreetMap Std Mod (Light Gray)": l_osm_std_mod_lightgray,
"OpenStreetMap Std Mod (Gray 1)": l_osm_std_mod_medgray,
"OpenStreetMap Std Mod (Gray 2)": l_osm_std_mod_medgray2,
"OpenStreetMap Std Mod (Dark Gray)": l_osm_std_mod_darkgray,
"OpenStreetMap Std Mod (Near Black)": l_osm_std_mod_darkest,
"OpenStreetMap Deutschland": l_osm_de,
"OpenStreetMap France": l_osm_fr,
"OpenStreetMap Humanitarian": l_osm_hot,
"EOX OSM": l_eox_osm,
"EOX Black Marble": l_eox_blackmarble,
"EOX Blue Marble": l_eox_bluemarble,
"EOX Sentinel-2 2020": l_eox_sentinel2_2020,
"EOX Sentinel-2 2019": l_eox_sentinel2_2019,
"EOX Sentinel-2 2018": l_eox_sentinel2_2018,
"EOX Terrain": l_eox_terrain,
"EOX Terrain (Light)": l_eox_terrain_light,
};
// define available overlay maps (can view more than one at a time, arranged in order from lowest to highest)
var overlaymaps = {
"EOX Hydrography": l_eox_hydrography,
"EOX Streets": l_eox_streets,
"EOX Coastline": l_eox_coastline,
"EOX Overlay": l_eox_overlay,
"EOX Overlay (Bright)": l_eox_overlay_bright,
"iNaturalist Taxon Range": l_inat_taxonrange,
"iNaturalist Taxon Places": l_inat_taxonplace,
"iNaturalist Place": l_inat_place,
"iNaturalist Observations Density in GBIF (no filters)": l_gbif,
"iNaturalist Observations Heatmap": l_inat_heat,
//"iNaturalist Observations Circles": l_inat_circles,
"iNaturalist Observations Grid": l_inat_grid,
"iNaturalist Observations Points": l_inat_points,
"iNaturalist Observations Relative Comparison":l_utfgdm_rel,
"iNaturalist Observations Absolute Comparison":l_utfgdm_abs,
"Debug Grid":l_debug,
};
if (taxon_id===null) {
delete overlaymaps["iNaturalist Taxon Range"];
delete overlaymaps["iNaturalist Taxon Places"];
};
if (place_id===null) {
delete overlaymaps["iNaturalist Place"];
};
// add a layer selector control and scale bar
L.control.layers(basemaps, overlaymaps).addTo(mymap);
L.control.scale().addTo(mymap);
</script>
</body>
</html>