-
Notifications
You must be signed in to change notification settings - Fork 6
/
iNat_map_obs_interact_area_viz.html
980 lines (850 loc) · 46.9 KB
/
iNat_map_obs_interact_area_viz.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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="iNaturalist Map Observation Interaction Area Visualization" />
<title>iNaturalist Map Observation Interaction Area Visualization</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 dmarker = {size:0.75,offset:{x:0,y:0},colorRGB:[0,255,0]};
var marker = null;
if (this.options.marker) {
marker = this.options.marker;
marker.size = marker.size || dmarker.size;
marker.offset = marker.offset || dmarker.offset;
marker.offset.x = marker.offset.x || dmarker.offset.x;
marker.offset.y = marker.offset.y || dmarker.offset.y;
marker.colorRGB = marker.colorRGB || dmarker.colorRGB;
}
else { marker = dmarker };
var offset = marker.offset;
// 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
for (cx=0;cx<cellsPerTile.x;cx++) {
for (cy=0;cy<cellsPerTile.y;cy++) {
var cell = {x:cx,y:cy};
//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 opacity = 0.5;
var markerColor = 'rgba('+marker.colorRGB+','+opacity+')'; //rgba format
ctx.fillStyle = markerColor;
ctx.fillRect(cell.x*cellSize.x+offset.x,cell.y*cellSize.y+offset.y,cellSize.x*marker.size,cellSize.y*marker.size);
};
};
};
})
.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);
};
/*
https://github.com/mapbox/corslite
BSD 2-Clause License
Copyright (c) 2017, Mapbox
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
function corslite(url, callback, cors) {
var sent = false;
if (typeof window.XMLHttpRequest === 'undefined') {
return callback(Error('Browser not supported'));
}
if (typeof cors === 'undefined') {
var m = url.match(/^\s*https?:\/\/[^\/]*/);
cors = m && (m[0] !== location.protocol + '//' + location.hostname +
(location.port ? ':' + location.port : ''));
}
var x = new window.XMLHttpRequest();
function isSuccessful(status) {
return status >= 200 && status < 300 || status === 304;
}
if (cors && !('withCredentials' in x)) {
// IE8-9
x = new window.XDomainRequest();
// Ensure callback is never called synchronously, i.e., before
// x.send() returns (this has been observed in the wild).
// See https://github.com/mapbox/mapbox.js/issues/472
var original = callback;
callback = function() {
if (sent) {
original.apply(this, arguments);
} else {
var that = this, args = arguments;
setTimeout(function() {
original.apply(that, args);
}, 0);
}
}
}
function loaded() {
if (
// XDomainRequest
x.status === undefined ||
// modern browsers
isSuccessful(x.status)) callback.call(x, null, x);
else callback.call(x, x, null);
}
// Both `onreadystatechange` and `onload` can fire. `onreadystatechange`
// has [been supported for longer](http://stackoverflow.com/a/9181508/229001).
if ('onload' in x) {
x.onload = loaded;
} else {
x.onreadystatechange = function readystate() {
if (x.readyState === 4) {
loaded();
}
};
}
// Call the callback with the XMLHttpRequest object as an error and prevent
// it from ever being called again by reassigning it to `noop`
x.onerror = function error(evt) {
// XDomainRequest provides no evt parameter
callback.call(this, evt || true, null);
callback = function() { };
};
// IE9 must have onprogress be set to a unique function.
x.onprogress = function() { };
x.ontimeout = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};
x.onabort = function(evt) {
callback.call(this, evt, null);
callback = function() { };
};
// GET is the only supported HTTP Verb by XDomainRequest and is the
// only one supported here.
x.open('GET', url, true);
// Send the request. Sending data is not supported.
x.send(null);
sent = true;
return x;
}
if (typeof module !== 'undefined') module.exports = corslite;
/*
https://github.com/consbio/Leaflet.UTFGrid/blob/master/L.UTFGrid.js
Copyright (c) 2015 - 2017, Conservation Biology Institute
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//heavily modified from: https://raw.githubusercontent.com/danzel/Leaflet.utfgrid/leaflet-master/src/leaflet.utfgrid.js
//depends on corslite
L.UTFGrid = L.TileLayer.extend({
options: {
resolution: 4,
pointerCursor: true,
mouseInterval: 66 // Delay for mousemove events
},
_mouseOn: null,
_mouseOnTile: null,
_tileCharCode: null, // '<tileKey>:<charCode>' or null
_cache: null, // {<tileKey>: <utfgrid>}
_idIndex: null, // {<featureID>: {<tileKey1>: true, ...<tileKeyN>: true} }
_throttleMove: null, // holds throttled mousemove handler
//_throttleConnectEventHandlers: null, // holds throttled connection setup function
_updateCursor: function(){ }, //no-op, overridden below
onAdd: function (map) {
this._cache = {};
this._idIndex = {};
L.TileLayer.prototype.onAdd.call(this, map);
this._throttleMove = L.Util.throttle(this._move, this.options.mouseInterval, this);
if (this.options.pointerCursor) {
this._updateCursor = function(cursor) { this._container.style.cursor = cursor; }
}
map.on('boxzoomstart', this._disconnectMapEventHandlers, this);
// have to throttle or we get an immediate click event on boxzoomend
map.on('boxzoomend', this._throttleConnectEventHandlers, this);
this._connectMapEventHandlers();
},
onRemove: function () {
var map = this._map;
map.off('boxzoomstart', this._disconnectMapEventHandlers, this);
map.off('boxzoomend', this._throttleConnectEventHandlers, this);
this._disconnectMapEventHandlers();
this._updateCursor('');
L.TileLayer.prototype.onRemove.call(this, map);
},
createTile: function(coords) {
this._loadTile(coords);
return document.createElement('div'); // empty DOM node, required because this overrides L.TileLayer
},
setUrl: function(url, noRedraw) {
this._cache = {};
return L.TileLayer.prototype.setUrl.call(this, url, noRedraw);
},
_connectMapEventHandlers: function(){
this._map.on('click', this._onClick, this);
this._map.on('mousemove', this._throttleMove, this);
},
_disconnectMapEventHandlers: function(){
this._map.off('click', this._onClick, this);
this._map.off('mousemove', this._throttleMove, this);
},
_throttleConnectEventHandlers: function() {
setTimeout(this._connectMapEventHandlers.bind(this), 100);
},
_update: function (center, zoom) {
L.TileLayer.prototype._update.call(this, center, zoom);
},
_loadTile: function (coords) {
var url = this.getTileUrl(coords);
var key = this._tileCoordsToKey(coords);
var self = this;
if (this._cache[key]) { return }
corslite(url, function(err, response){
if (err) {
self.fire('error', {error: err});
return;
}
var data = JSON.parse(response.responseText);
self._cache[key] = data;
L.Util.bind(self._handleTileLoad, self)(key, data);
}, true);
},
_handleTileLoad: function(key, data) {
// extension point
},
_onClick: function (e) {
this.fire('click', this._objectForEvent(e));
},
_move: function (e) {
if (e.latlng == null){ return }
var on = this._objectForEvent(e);
if (on._tileCharCode !== this._tileCharCode) {
if (this._mouseOn) {
this.fire('mouseout', {
latlng: e.latlng,
data: this._mouseOn,
_tile: this._mouseOnTile,
_tileCharCode: this._tileCharCode
});
this._updateCursor('');
}
if (on.data) {
this.fire('mouseover', on);
this._updateCursor('pointer');
}
this._mouseOn = on.data;
this._mouseOnTile = on._tile;
this._tileCharCode = on._tileCharCode;
} else if (on.data) {
this.fire('mousemove', on);
}
},
_objectForEvent: function (e) {
if (!e.latlng) return; // keyboard <ENTER> events also pass through as click events but don't have latlng
var map = this._map,
point = map.project(e.latlng),
tileSize = this.options.tileSize,
resolution = this.options.resolution,
x = Math.floor(point.x / tileSize),
y = Math.floor(point.y / tileSize),
gridX = Math.floor((point.x - (x * tileSize)) / resolution),
gridY = Math.floor((point.y - (y * tileSize)) / resolution),
max = map.options.crs.scale(map.getZoom()) / tileSize;
x = (x + max) % max;
y = (y + max) % max;
var tileKey = this._tileCoordsToKey({z: map.getZoom(), x: x, y: y});
var data = this._cache[tileKey];
if (!data) {
return {
latlng: e.latlng,
data: null,
_tile: null,
_tileCharCode: null
};
}
var charCode = data.grid[gridY].charCodeAt(gridX);
var idx = this._utfDecode(charCode),
key = data.keys[idx],
result = data.data[key];
if (!data.data.hasOwnProperty(key)) {
result = null;
}
return {
latlng: e.latlng,
data: result,
id: (result)? result.id: null,
_tile: tileKey,
_tileCharCode: tileKey + ':' + charCode
};
},
_dataForCharCode: function (tileKey, charCode) {
var data = this._cache[tileKey];
var idx = this._utfDecode(charCode),
key = data.keys[idx],
result = data.data[key];
if (!data.data.hasOwnProperty(key)) {
result = null;
}
return result;
},
_utfDecode: function (c) {
if (c >= 93) {
c--;
}
if (c >= 35) {
c--;
}
return c - 32;
},
_utfEncode: function (c) {
//reverse of above, returns charCode for c
//derived from: https://github.com/mapbox/glower/blob/mb-pages/src/glower.js#L37
var charCode = c + 32;
if (charCode >= 34) {
charCode ++;
}
if (charCode >= 92) {
charCode ++;
}
return charCode;
}
});
L.utfGrid = function (url, options) {
return new L.UTFGrid(url, options);
};
L.UTFGridCanvas = L.UTFGrid.extend({
options: {
idField: 'ID', // Expects UTFgrid to have a property 'ID' that indicates the feature ID
buildIndex: true, // requires above field to be set properly
fillColor: 'black',
shadowBlur: 0, // Number of pixels for blur effect
shadowColor: null, // Color for shadow, if present. Defaults to fillColor.
debug: false // if true, show tile borders and tile keys
},
_adjacentTiles: null,
onAdd: function (map) {
this._adjacentTiles = [];
L.UTFGrid.prototype.onAdd.call(this, map);
},
createTile: function(coords) {
this._loadTile(coords);
var tile = document.createElement('canvas');
tile.width = tile.height = this.options.tileSize;
if (this.options.debug) {
this._drawDefaultTile(tile.getContext('2d'), this._tileCoordsToKey(coords));
}
return tile;
},
_connectMapEventHandlers: function(){
L.UTFGrid.prototype._connectMapEventHandlers.call(this);
this.on('mouseover', this._handleMouseOver, this);
this.on('mouseout', this._handleMouseOut, this);
},
_disconnectMapEventHandlers: function(){
L.UTFGrid.prototype._disconnectMapEventHandlers.call(this);
this.off('mouseover', this._handleMouseOver, this);
this.off('mouseout', this._handleMouseOut, this);
},
_handleMouseOver: function (e) {
if (e._tile == null || e._tileCharCode == null){ return }
this._clearAdjacentTiles();
// currently over this tile:
var curTile = e._tile;
this._drawTile(curTile, parseInt(e._tileCharCode.split(':')[3]));
if (e.data && this._idIndex) {
// draw adjacent tiles
var id = e.data[this.options.idField];
var zoomLevel = curTile.split(':')[2];
if (!(id && this._idIndex[id] && this._idIndex[id][zoomLevel])) { return }
var idx = this._idIndex[id][zoomLevel];
for (var tileKey in idx) {
//TODO: screen out any tiles that are not currently visible?
if (tileKey !== curTile) {
this._drawTile(tileKey, idx[tileKey]);
this._adjacentTiles.push(tileKey);
}
}
}
},
_handleMouseOut: function (e) {
this._resetTile(e._tile);
this._clearAdjacentTiles();
},
_clearAdjacentTiles: function() {
// clear out any adjacent tiles that were drawn
if (this._adjacentTiles) {
for (var i = 0; i < this._adjacentTiles.length; i++) {
this._resetTile(this._adjacentTiles[i]);
}
this._adjacentTiles = [];
}
},
_handleTileLoad: function(tileKey, data) {
// build index: {<id: {zoomLevel: {tileKey: tileCharCode} } }
if (this.options.buildIndex) {
var id, props, idx;
var idField = this.options.idField;
var zoomLevel = tileKey.split(':')[2];
for (var i = 0; i < data.keys.length; i++) {
props = data.data[data.keys[i]];
if (props) {
id = props[idField];
if (id) {
if (this._idIndex[id] == null) {
this._idIndex[id] = {};
}
idx = this._idIndex[id];
if (idx[zoomLevel] == null) {
idx[zoomLevel] = {};
}
idx[zoomLevel][tileKey] = this._utfEncode(i);
}
}
}
}
},
_drawTile: function(tileKey, charCode) {
// for a given tile, find all pixels that match character and repaint
// TODO: request animation frame?
if (this._tiles[tileKey] == null){ return }
var canvas = this._tiles[tileKey].el;
var ctx = canvas.getContext('2d');
this._resetTile(tileKey);
var grid = this._cache[tileKey].grid;
ctx.fillStyle = this.options.fillColor;
var dim = this.options.tileSize / this.options.resolution;
// TODO: order of traversal here may be backwards? Do y then x? (are data column major or row major?)
//modified slightly from: https://github.com/mapbox/glower/blob/mb-pages/src/glower.js
for (var x = 0; x < dim; x++) {
for (var y = 0; y < dim; y++) {
if (grid[y].charCodeAt(x) === charCode) {
var sweep = 1;
while (y < 63 && grid[y + 1].charCodeAt(x) === charCode) {
y++;
sweep++;
}
ctx.fillRect(x * 4, (y * 4) - ((sweep - 1) * 4), 4, 4 * sweep);
}
}
}
if (this.options.shadowBlur) {
this._addShadow(canvas, ctx);
}
},
_resetTile: function(tileKey) {
// clear the canvas
if (this._tiles[tileKey] == null){ return }
var tile = this._tiles[tileKey].el;
tile.width = this.options.tileSize; // hard reset of canvas
if (this.options.debug) {
this._drawDefaultTile(tile.getContext('2d'), tileKey);
}
},
_drawDefaultTile: function(ctx, tileKey) {
// if this.options.debug, add tileKey text and borders
ctx.fillStyle = 'black';
ctx.fillText(tileKey, 20, 20);
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(255, 0);
ctx.lineTo(255, 255);
ctx.lineTo(0, 255);
ctx.closePath();
ctx.stroke();
},
_addShadow: function(canvas, ctx) {
ctx.shadowBlur = this.options.shadowBlur;
ctx.shadowColor = this.options.shadowColor || this.options.fillColor;
//Blur effect copied from glower - https://github.com/cutting-room-floor/glower/blob/mb-pages/src/glower.js#L108
ctx.globalAlpha = 0.7;
ctx.globalCompositeOperation = 'lighter';
var a = 1;
ctx.drawImage(canvas, -a, -a);
ctx.drawImage(canvas, a, a);
ctx.drawImage(canvas, 0, -a);
ctx.drawImage(canvas, -a, 0);
ctx.globalAlpha = 1;
}
});
L.utfGridCanvas = function (url, options) {
return new L.UTFGridCanvas(url, options);
};
</script>
</head>
<body>
<div id="nav">
<p>Markers in maps in iNaturalist are generally delivered as tiled image files, not actually as individual markers. This means that a user cannot directly interact with the markers displayed on the maps.</p>
<p>Instead, a user interacts with an invisible UTFgrid layer -- a grid of square cells -- that sits on top of the marker layer. The idea is that if a user interacts with a UTFgrid cell that is positioned on top of a particular marker, then the action triggered should correspond to an action meaningful for that marker.</p>
<p>The UTFgrid cells do not always approximate the shape of their corresponding markers correctly. This page provides a way to visualize the areas where an interaction can take place, alongside the corresponding markers that would be shown on an iNaturalist map.</p>
<p>A few notes:</p>
<p>First, this page uses a different set of basemaps than those available in iNaturalist (since the ones that iNaturalist uses are not free).</p>
<p>Second, I *think* the iNaturalist maps do some sort of fancy offset for the pin-style markers (the ones that look like upside down teardrops) so that their corresponding interaction areas are effectively shifted up a bit. (The effect would be that the corresponding interaction area in iNaturalist would be the fat end of a pin vs the narrow tip of a pin in this page.) Since this page does not do any fancy offsetting, you will just have to mentally do the shift to imagine where you would need to hover and click on an iNaturalist map.</p>
<p>Finally, the set of observations displayed by this page can be modified by adding parameters to the page URL. For example, if you would to see just bird observations by loarie, you could add "?user_id=loarie&taxon_id=3" to the end of the base URL. See the API reference for the <a href="https://api.inaturalist.org/v1/docs/#!/Observations/get_observations">Get Observations endpoint</a> for a full list of parameters available to use.</p>
</div>
<div id="mapid"></div>
<script>
function fdate(str) {
str = str.replace(/t/i,' '); //replaces T (case insensitive) with a space
str = str.replace(/([+-]\d{2}\:?\d{2})/,' ($1)'); //puts parenthesis around time zone offset
str = str.replace(/z/i,' (+00:00)'); //replaces Z (case insensitve) with UTC
str = str.replace('+00:00','±00:00');
return str;
};
function fround(num,places) {
var n = num*1;
return n.toFixed(places);
};
//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');
// iNat UTFGrid Visualization, using grid-style UTFGrid at lower zooms and point-style UTFGrid at higher zooms
let utfgridapi_grid = {url:'https://api.inaturalist.org/v1/grid/{z}/{x}/{y}.grid.json',attr:'<a href="https://api.inaturalist.org/v1/docs/#!/UTFGrid/get_grid_zoom_x_y_grid_json">iNaturalist</a>'};
let utfgridapi_points = {url:'https://api.inaturalist.org/v1/points/{z}/{x}/{y}.grid.json',attr:'<a href="https://api.inaturalist.org/v1/docs/#!/UTFGrid/get_points_zoom_x_y_grid_json">iNaturalist</a>'};
var l_utfgdm1 = L.gridLayer.utfGridDensityMap({url:utfgridapi_grid.url+'?'+winurlparams,minZoom:0,maxZoom:9,attribution:utfgridapi_grid.attr,marker:{size:0.90,colorRGB:[0,255,0]}})
var l_utfgdm2 = L.gridLayer.utfGridDensityMap({url:utfgridapi_points.url+'?'+winurlparams,minZoom:10,maxZoom:20,attribution:utfgridapi_grid.attr,marker:{size:0.90,colorRGB:[176,0,176]}})
var g_utfgdm = L.layerGroup([l_utfgdm1,l_utfgdm2]);
// iNat Observation Layer, using grid markers at lower zooms and points at higher zooms
let inat_urlbase = 'https://api.inaturalist.org/v1/';
//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 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_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_gbif = L.tileLayer(gbif_density_point_py.url,{maxZoom:20, attribution:gbif_density_point_py.attribution});
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_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>'};
var l_inat_points = L.tileLayer(inat_points.url+'?'+winurlparams,{minZoom:10,maxZoom:20, attribution:inat_points.attribution});
var l_inat_grid = L.tileLayer(inat_grid.url+'?'+winurlparams,{minZoom:0,maxZoom:9,attribution:inat_grid.attribution});
var g_inat_obs = L.layerGroup([l_inat_grid,l_inat_points]);
// iNat UTFGrid Selection
// (hover to see selected area, and click to view selected observation)
function fpopup(obs) {
var s = (obs.photos.length==0) ? '[No Photo]' : '<img src="'+obs.photos[0].url+'" />';
s += (obs.photos.length>1) ? ' ['+obs.photos.length+']' : '';
s += '<br />observation #: <a target="_blank" href="'+obs.uri+'">'+obs.id+'</a> (grade: '+obs.quality_grade+')';
s += '<br />taxon: ' + ((obs.taxon==null) ? '[Unknown]' : obs.taxon.preferred_common_name ? (obs.taxon.preferred_common_name+' ('+obs.taxon.name+')') : obs.taxon.name );
s += '<br />observer: '+obs.user.login;
// s += '<br />location: '+obs.place_guess;
s += '<br />coordinates: '+fround(obs.geojson.coordinates[1],6)+', '+fround(obs.geojson.coordinates[0],6);
s += (obs.positional_accuracy==null) ? '' : ' ('+fround(obs.positional_accuracy,1)+'m)';
s += '<br />observed: '+((obs.time_observed_at==null) ? ((obs.observed_on==null) ? '[Unknown]': obs.observed_on) : fdate(obs.time_observed_at));
s += '<br />created: '+((obs.created_at==null) ? obs.created_at_details.date : fdate(obs.created_at));
s += '<br />last updated: '+fdate(obs.updated_at);
// if (obs.description==null) {}
// else if (obs.description.length < 200) {s += '<br />'+obs.description }
// else {s += '<br />'+(obs.description.substring(0,191)+'... (more)')};
L.popup().setLatLng([obs.geojson.coordinates[1],obs.geojson.coordinates[0]])
.setContent(s).openOn(mymap);
};
var u_inat_points = L.utfGrid(inat_urlbase+'points/{z}/{x}/{y}.grid.json?'+winurlparams, {
resolution: 4,
pointerCursor: true,
mouseInterval: 66, // Delay for mousemove events
minZoom:10,
maxZoom:20,
});
u_inat_points.on("click", function(e) { // "mouseover" and "mouseout" events not used here
if (e.data) {
corslite(inat_urlbase+'observations/'+e.data.id, function(err, response) {
if (err) {
self.fire('error', {error: err});
return;
};
var obsdata = JSON.parse(response.responseText);
fpopup(obsdata.results[0]);
}, true);
};
});
var u_inat_grid = L.utfGrid(inat_urlbase+'grid/{z}/{x}/{y}.grid.json?'+winurlparams, {
resolution: 4,
pointerCursor: true,
mouseInterval: 66, // Delay for mousemove events
minZoom:0,
maxZoom:9,
});
u_inat_grid.on("click", function(e) { // "mouseover" and "mouseout" events not used here
if (e.data) {
corslite(inat_urlbase+'observations/'+e.data.id, function(err, response) {
if (err) {
self.fire('error', {error: err});
return;
};
var obsdata = JSON.parse(response.responseText);
fpopup(obsdata.results[0]);
}, true);
};
});
var v_inat_points = L.utfGridCanvas(inat_urlbase+'points/{z}/{x}/{y}.grid.json?'+winurlparams, {
idField: 'id', // Expects UTFgrid to have a property 'ID' that indicates the feature ID
buildIndex: true, // requires above field to be set properly
fillColor: 'black',
shadowBlur: 0, // Number of pixels for blur effect
shadowColor: null, // Color for shadow, if present. Defaults to fillColor.
debug: false, // if true, show tile borders and tile keys
minZoom:10,
maxZoom:20,
});
var v_inat_grid = L.utfGridCanvas(inat_urlbase+'grid/{z}/{x}/{y}.grid.json?'+winurlparams, {
idField: 'id', // Expects UTFgrid to have a property 'ID' that indicates the feature ID
buildIndex: true, // requires above field to be set properly
fillColor: 'black',
shadowBlur: 0, // Number of pixels for blur effect
shadowColor: null, // Color for shadow, if present. Defaults to fillColor.
debug: false, // if true, show tile borders and tile keys
minZoom:0,
maxZoom:9,
});
var g_utfgdm_sel = L.layerGroup([u_inat_grid,u_inat_points,v_inat_grid,v_inat_points]);
// 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(g_inat_obs);
defaultlayers.push(g_utfgdm);
defaultlayers.push(g_utfgdm_sel);
// 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":g_inat_obs,
"iNaturalist Obs Interaction Area":g_utfgdm,
"iNaturalist Obs Active Interaction":g_utfgdm_sel,
"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>