-
Notifications
You must be signed in to change notification settings - Fork 6
/
iNat_UTFgrid_based_density_map_for_Leaflet.html
399 lines (366 loc) · 31.8 KB
/
iNat_UTFgrid_based_density_map_for_Leaflet.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="iNaturalist Observation Density Map Based on UTFGrid Data and Integrated in Leaflet.js" />
<title>iNaturalist Observation Density 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;
};
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 dmarkerOpacity = {type:'circle',size:0.75,offset:{x:0,y:0},scaleType:'opacity',scaleFactor:1,colorRGB:[255,0,0]};
var dmarkerGradRainbow = {type:'square',size:0.75,offset:{x:0,y:0},scaleType:'grad_rainbow',scaleFactor:5};
var marker = null;
if (this.options.marker) {
marker = this.options.marker;
marker.scaleType = marker.scaleType || dmarkerOpacity.scaleType;
if (marker.scaleType==='grad_rainbow') {
marker.type = marker.type || dmarkerGradRainbow.type;
marker.size = marker.size || dmarkerGradRainbow.size;
marker.offset = marker.offset || dmarkerGradRainbow.offset;
marker.offset.x = marker.offset.x || dmarkerGradRainbow.offset.x;
marker.offset.y = marker.offset.y || dmarkerGradRainbow.offset.y;
marker.scaleFactor = marker.scaleFactor || dmarkerGradRainbow.scaleFactor;
}
else { // default = if (marker.scaleType==='opacity')
marker.type = marker.type || dmarkerOpacity.type;
marker.size = marker.size || dmarkerOpacity.size;
marker.offset = marker.offset || dmarkerOpacity.offset;
marker.offset.x = marker.offset.x || dmarkerOpacity.offset.x;
marker.offset.y = marker.offset.y || dmarkerOpacity.offset.y;
marker.scaleFactor = marker.scaleFactor || dmarkerOpacity.scaleFactor;
marker.colorRGB = marker.colorRGB || dmarkerOpacity.colorRGB;
};
}
else { marker = dmarkerOpacity };
var markerType = marker.type;
var scaleType = marker.scaleType;
var offset = marker.offset;
var scaleFactor = marker.scaleFactor;
// get UTFgrid
var url = freplacexyz(this.options.url,coords.x,coords.y,coords.z);
fetch(url)
.then((response) => {
if (!response.ok) { throw new Error(response.status+': '+response.statusText); };
return response.json();
})
// draw markers on a canvas object
.then((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 i = utfgrid.grid[cell.y].charCodeAt(cell.x);
i = i-((i>=93)?34:(i>=35)?33:32);
var d = utfgrid.data[utfgrid.keys[i]];
var markerColor = 0; //default to black
if (d!=null) {
var cellCount = d.cellCount;
if (scaleType==='grad_rainbow') {
var f = cellCount/scaleFactor;
f = (f<0)?0:(f>1)?1:f;
markerColor = 'hsl('+(240+f*-300)+','+(f*70+30)+'%,50%)'; //hsl format; opacity can be controlled at the gridLayer level
}
else { // default = if (scaleType==='opacity')
var opacity = cellCount/scaleFactor;
markerColor = 'rgba('+marker.colorRGB+','+opacity+')'; //rgba format
};
if (['circle','ring'].includes(markerType)) {
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 (markerType==='ring') {
ctx.strokeStyle = markerColor;
ctx.stroke();
}
else {
ctx.fillStyle = markerColor;
ctx.fill();
};
}
else { // default = if(markerType==='square')
ctx.fillStyle = markerColor;
ctx.fillRect(cell.x*cellSize.x-cellSize.x+offset.x,cell.y*cellSize.y-cellSize.y+offset.y,cellSize.x*marker.size*2,cellSize.y*marker.size*2);
};
};
};
};
})
.catch((err) => { console.error(err); });
// 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>Note: This was originally created before the introduction of iNaturalist's Grid style tiles, which are conceptually the same kind of visualization as provided here. Unless you have a need for customization not available with the Grid tiles, it will be better to use those tiles in most cases.</p>
<p>This is an example of an iNaturalist observation density map created using UTFgrid data and integrated as an extension of a Leaflet.js grid layer.</p>
<p>By default, this example shows a version of the density map that scales on opacity. There is also a version that uses a color gradient, which can be selected in the layer selector (in the top-right corner of the map). If you prefer to see gradient markers by default instead of opacity markers, use defaultstyle=gradient in your URL parameter string.</p>
<p>There are also other layers that may be useful for comparison purposes. By default, these are hidden, but you can choose to show taxon place, taxon range, and place layers by default by using showtaxonplace=true, showtaxonrange=true, and showplace=true, respectively.</p>
<p>The example returns all iNaturalist observations by default, but it will also handle filter parameters added to the URL. For example, to see only observations in 2019, add "?year=2019" to the end of the URL. Note, however, that the scaling factor of the markers is not dynamic. So filtering for, say, a taxon with very few observations may seem to return nothing in the opacity version of the density map at lower zoom levels. (The gradient version of the density map will still show the observations.)</p>
<p>The scaling factor in this example is configured as 100,000 for zoom levels 0 to 2; 10,000 for levels 3 to 5; 1,000 for levels 6 to 7; 100 for levels 8 to 10; 10 for levels 11 to 12; and 5 for levels 13 and higher. It's also possible to pass in custom scale factors in the URL parameters. For example, to query for Rudbeckia amplexicaulis with an appropriate scale factor(s), I could add "?taxon_id=200073&scale_factor=5,4,3,2,2,1" or "?taxon_id=200073&scale_factor=5" to my URL.</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 (not integrated into Leaflet.js), 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') || 'opacity';
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_map_for_Leaflet.html','iNat_UTFgrid_based_custom_density_map.html');
document.getElementById('otherpage').innerHTML = '<a href="'+otherurl+'">'+otherurl+'</a>';
// the main iNat UTFGrid API
//note that iNat technically provides 3 UTFGrid endpoints, but as far as I can tell, they provide identical functionality.
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 scaled on opacity; set different scaleFactors at different zoom levels
var l_utfgdm_opacity1 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:0,maxZoom:2,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[0]||100000):100000),colorRGB:[255,0,0]}})
var l_utfgdm_opacity2 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:3,maxZoom:5,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[1]||10000):10000),colorRGB:[255,0,0]}})
var l_utfgdm_opacity3 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:6,maxZoom:7,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[2]||1000):1000),colorRGB:[255,0,0]}})
var l_utfgdm_opacity4 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:8,maxZoom:10,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[3]||100):100),colorRGB:[255,0,0]}})
var l_utfgdm_opacity5 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:11,maxZoom:12,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[4]||10):10),colorRGB:[255,0,0]}})
var l_utfgdm_opacity6 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:13,maxZoom:20,attribution:utfgridapi.attr,marker:{type:'circle',size:0.75,scaleType:'opacity',scaleFactor:(sfarray!=null?(sfarray[5]||5):5),colorRGB:[255,0,0]}})
var g_utfgdm_opacity = L.layerGroup([l_utfgdm_opacity1,l_utfgdm_opacity2,l_utfgdm_opacity3,l_utfgdm_opacity4,l_utfgdm_opacity5,l_utfgdm_opacity6]);
// iNat UTFGrid-based density map scaled on a gradient; set different scaleFactors at different zoom levels
var l_utfgdm_gradient1 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:0,maxZoom:2,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[0]||100000):100000)},opacity:0.65})
var l_utfgdm_gradient2 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:3,maxZoom:5,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[1]||10000):10000)},opacity:0.65})
var l_utfgdm_gradient3 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:6,maxZoom:7,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[2]||1000):1000)},opacity:0.65})
var l_utfgdm_gradient4 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:8,maxZoom:10,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[3]||100):100)},opacity:0.65})
var l_utfgdm_gradient5 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:11,maxZoom:12,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[4]||10):10)},opacity:0.65})
var l_utfgdm_gradient6 = L.gridLayer.utfGridDensityMap({url:utfgridapi.url+'?'+winurlparams,minZoom:13,maxZoom:20,attribution:utfgridapi.attr,marker:{type:'square',size:0.9,scaleType:'grad_rainbow',scaleFactor:(sfarray!=null?(sfarray[5]||5):5)},opacity:0.65})
var g_utfgdm_gradient = L.layerGroup([l_utfgdm_gradient1,l_utfgdm_gradient2,l_utfgdm_gradient3,l_utfgdm_gradient4,l_utfgdm_gradient5,l_utfgdm_gradient6]);
// 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==='gradient'?g_utfgdm_gradient:g_utfgdm_opacity);
// 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 Density (opacity)":g_utfgdm_opacity,
"iNaturalist Observations Density (gradient)":g_utfgdm_gradient,
"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>