-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
877 lines (792 loc) · 36.2 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Javier Jimenez Shaw">
<title>CRS Explorer - PROJ</title>
<style>
body { font-family: Lato,proxima-nova,Helvetica Neue,Arial,sans-serif; color: #202020 }
thead { font-weight: bold; }
th { cursor: pointer; background-color: #DDD; }
label { white-space: nowrap; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.screen-msg { display: none; }
@media only screen and (max-width: 480px) {
th:nth-child(3), th:nth-child(4), th:nth-child(6),
td:nth-child(3), td:nth-child(4), td:nth-child(6) {
display: none
}
.screen-msg { display: unset; }
}
#mapid { height: 400px; width: 800px; max-width: 80%; }
.sticky { position: sticky; top: 0; }
.area { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; width: 20em; display: block; }
.hide { display: none; }
.odd { background-color: #EEEEEE; }
.order { color: #777; font-size: small; padding-left: 0.5em; }
.loader-text { color: darkred; }
.message-text { color: darkred; }
.wkts_cell { white-space: nowrap; }
.wkt1 { margin-right: 0.3em; }
.sr-icon { vertical-align: text-bottom; }
td, th { padding-left: 0.25em; padding-right: 0.25em; }
.circle {
background-color: #3388ff; /* For browsers that do not support gradients */
background-image: radial-gradient(#ccdaed, #3388ff, #3388ff);
border-radius: 50%; /* make the div a circular shape */
cursor: ne-resize !important;
}
</style>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<link rel="icon" type="image/x-icon" href="./favicon.ico"/>
<base target="_blank">
<meta name="google-site-verification" content="MhCjgTBKAzLd1y46INE_vmHIiJ_TLHrDc98XC_jYB14" />
</head>
<body onload="load()">
<h1>CRS Explorer - PROJ <span id="proj_version">9.5.1</span> codes</h1>
<div>
<label for="version">PROJ version: </label>
<select name="version" id="version" onchange="versionChanged(this)">
<option value="latest">latest</option>
<option value="9.5.1">9.5.1</option>
<option value="9.5.0">9.5.0</option>
<option value="9.4.1">9.4.1</option>
<option value="9.4.0">9.4.0</option>
<option value="9.3.1">9.3.1</option>
<option value="9.3.0">9.3.0</option>
<option value="9.2.1">9.2.1</option>
<option value="9.2.0">9.2.0</option>
<option value="9.1.1">9.1.1</option>
<option value="9.1.0">9.1.0</option>
<option value="9.0.1">9.0.1</option>
<option value="9.0.0">9.0.0</option>
<option value="8.2.1">8.2.1</option>
</select>
</div>
<br>
<div>This page shows a list of the Coordinate Reference Systems included in <a href="https://proj.org">PROJ</a>.
<span id="version_link">(see generation <a id="metadata" href="./metadata.txt">metadata file</a>)</span>
<br>You can filter by type, authority, name and location (clicking on the map).
<br>Selecting the area of use of any CRS displays it as a rectangle in the map.
<br>Visit the source code in <a href="https://github.com/jjimenezshaw/crs-explorer">GitHub</a>.
</div>
<br>
<div id="mapcont"><div id="mapid"></div></div>
<div><label title="Keeps the map always visible"><input type="checkbox" id="stickyCb">Sticky map</label> |
Click the map to select a location. Drag the point for an area. <button type="button" id="delete">Delete location</button> <span id="location"></span></div>
<div id="filters"> </div>
<div id="authorities"> </div>
<br>
<div id="searcher">
<form>Filter by name: <input type="text" name="value" tabindex="1">
<button type="submit">Search</button>
<a href="javascript:toggleInfo()" title="Show/hide info" target="_self"> < ℹ > </a>
<span id="activeSearch" class="hide"> Active filter: <span id="activeSearchTxt"></span></span>
<div class="hide" id="search_info">
<ul>
<li>Write many words to do an "and" search on the "Name" column</li>
<li>Use | (pipe) separator to do an "or" search</li>
<li>Enclose the terms in quotes (") to search them together</li>
<li>Add a dash (-) to exclude an expression</li>
<li>Search is case insensitive</li>
<li>Numbers only are considered also as ids, and searched as codes</li>
<li>examples: <br> <code>"sachusetts mainland" -(ftUS)</code> <br> <code>4326 | 32632 | CH1903 LV95</code></li>
</ul>
</div>
</form>
</div>
<div id="message" class="message-text hide"><br> >> Select CRS types to display, like Projected, Geographic 2D or Vertical << </div>
<div class="screen-msg"><br>Your window width is too small. Some columns were removed. Rotate you mobile or enlarge the window to see them all.</div>
<h3>Selected & Filtered Systems (<span class='loader-text'>Loading…</span><span class='counter-text'></span>)</h3>
<div id="tables"></div>
<br>
<div id="copyright">© <a href="https://github.com/jjimenezshaw/">Javier Jimenez Shaw</a> </div>
<script>
let map = L.map('mapid').setView([0, 0], 1);
let filters = {
latlng : null,
latlng2 : null,
searchText : '',
ignoreWorld : false,
allowDeprecated : false,
authorities : {},
activeTypes: {},
};
let alreadyLoadedSet = new Set();
let fullDB = null;
let divCircle = L.divIcon({ className: 'circle'})
let marker = L.marker([0,0], {icon: divCircle, draggable: true});
let marker2 = L.marker([0,0], {icon: divCircle, draggable: true}); // L.circleMarker([0,0], {radius:5, draggable: true});
let boundingBox = null;
let rectangles = {};
let hooverRect = null;
// to load older versions of PROJ
let versioned_url = '';
let versioned_tag = '';
let osm = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 18,
}).addTo(map);
let osmde = L.tileLayer('https://tile.openstreetmap.de/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 18,
});
let carto = L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/rastertiles/voyager/{z}/{x}/{y}.png', {
attribution: '© Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.',
maxZoom: 18,
});
var baseMaps = {
"OSM": osm,
"OSM (de)": osmde,
"Carto (en)": carto
};
var layerControl = L.control.layers(baseMaps).addTo(map);
function querystringFromFilters() {
let dic = {}
if (filters.latlng) {
dic.latlng = filters.latlng.lat.toFixed(6) + ',' + filters.latlng.lng.toFixed(6);
}
if (filters.latlng2) {
dic.latlng += ',' + filters.latlng2.lat.toFixed(6) + ',' + filters.latlng2.lng.toFixed(6);
}
if (filters.searchText) dic.searchText = encodeURIComponent(filters.searchText);
dic.ignoreWorld = filters.ignoreWorld ? 'true' : 'false';
dic.allowDeprecated = filters.allowDeprecated ? 'true' : 'false';
dic.authorities = Object.keys(filters.authorities).filter(key => filters.authorities[key]).join(',');
dic.activeTypes = Object.keys(filters.activeTypes).filter(key => filters.activeTypes[key]).join(',');
dic.map = currentMapName();
if (versioned_tag) {
dic.v = versioned_tag;
}
let res = Object.keys(dic).map(key => key +'='+ dic[key]).join('&');
return res;
}
function currentMapName() {
if (map.hasLayer(osm))
return 'osm';
else if (map.hasLayer(osmde))
return 'osmde';
else if (map.hasLayer(carto))
return 'carto';
return '';
}
function updateMapFromParams(input) {
if (input.map == 'osm')
map.addLayer(osm);
else if (input.map == 'osmde')
map.addLayer(osmde);
else if (input.map == 'carto')
map.addLayer(carto);
else
map.addLayer(osm); // default map tiles
map.on('baselayerchange', updateURL);
}
function updateFiltersFromParams(input) {
let dic = {
latlng : '',
searchText : '',
ignoreWorld : 'false',
allowDeprecated : 'false',
authorities : 'EPSG',
activeTypes: '',
}; // defaults
if (input.all == 'true') {
dic.ignoreWorld = 'false';
dic.allowDeprecated = 'true';
dic.authorities = Object.keys(filters.authorities).join(',');
dic.activeTypes = Object.keys(filters.activeTypes).join(',');
}
Object.assign(dic, input);
function setCheck(id, group, checked) {
if (group && !(id in group)) return false;
let obj = document.getElementById(id);
if (!obj) return false;
if (checked) {
obj.setAttribute('checked', '');
} else {
obj.removeAttribute('checked');
}
return true;
}
try {
const latlng = dic.latlng.split(',');
if (latlng.length == 4) setLatlng(L.latLng(latlng.slice(0,2)), L.latLng(latlng.slice(2,4)));
else if (latlng.length >= 2) setLatlng(L.latLng(latlng.slice(0,2)));
} catch (ignore) {}
setSearchText(decodeURIComponent(dic.searchText))
dic.authorities.split(',').forEach(auth => {
if (setCheck(auth, filters.authorities, true)) filters.authorities[auth] = true;
});
dic.activeTypes.split(',').forEach(type => {
if (setCheck(type, filters.activeTypes, true)) filters.activeTypes[type] = true;
});
filters.ignoreWorld = dic.ignoreWorld == 'true';
setCheck('ignoreWorld', null, filters.ignoreWorld);
filters.allowDeprecated = dic.allowDeprecated == 'true';
setCheck('allowDeprecated', null, filters.allowDeprecated);
}
function setLatlng(latlng, latlng2 = null) {
function updateText() {
let location = 'Clicked location: ' + filters.latlng;
if (map.hasLayer(marker2)) location = 'Selected box: ' + filters.latlng + ', ' + filters.latlng2;
document.querySelector('#location').innerHTML = location;
}
function fillLatLng2(latlng2) {
filters.latlng2 = latlng2;
if (latlng2) {
marker2.setLatLng(filters.latlng2).addTo(map);
boundingBox.setBounds(L.latLngBounds(filters.latlng, filters.latlng2)).addTo(map);
}
}
if (!boundingBox) boundingBox = L.rectangle(L.latLngBounds(latlng, latlng));
boundingBox.removeFrom(map);
marker2.removeFrom(map);
filters.latlng = latlng;
fillLatLng2(latlng2)
marker.on('dragstart', function(ev) {
if (!map.hasLayer(marker2)) {
fillLatLng2(filters.latlng)
}
});
marker.on('drag', function(ev) {
filters.latlng = ev.latlng
boundingBox.setBounds(L.latLngBounds(filters.latlng, filters.latlng2))
});
marker2.on('drag', function(ev) {
filters.latlng2 = ev.latlng
boundingBox.setBounds(L.latLngBounds(filters.latlng, filters.latlng2))
});
marker.on('dragend', function(ev) {
updateText();
runFilter();
})
marker2.on('dragend', function(ev) {
updateText();
runFilter();
})
marker.setLatLng(filters.latlng).addTo(map);
updateText();
}
map.on('click', function(e) {
setLatlng(e.latlng)
runFilter();
});
document.querySelector('#delete').addEventListener('click', function () {
if (filters.latlng) {
filters.latlng = null;
filters.latlng2 = null;
marker && marker.removeFrom(map);
marker2 && marker2.removeFrom(map);
boundingBox && boundingBox.removeFrom(map);
document.querySelector('#location').innerHTML = '';
runFilter();
}
});
document.querySelector('#stickyCb').addEventListener('click', function (ev) {
document.querySelector('#mapcont').classList[ev.target.checked ? 'add' : 'remove']('sticky');
});
function makeRectangle (area_of_use, color) {
let bounds = null;
let off0 = 0, off2 = 0;
if (area_of_use[0] < area_of_use[2]) {
} else if (Math.abs(area_of_use[0]) < Math.abs(area_of_use[2])) {
off2 = 360
} else {
off0 = 360
}
bounds = [[area_of_use[1], area_of_use[0]-off0], [area_of_use[3], area_of_use[2]+off2]];
return L.rectangle(bounds, {color: color});
}
function clickArea(ev, code, area_of_use) {
if (!(code in rectangles)) {
rectangles[code] = {layer : makeRectangle(area_of_use, 'green')};
}
rectangles[code].layer[ev.target.checked ? 'addTo' : 'removeFrom'](map);
}
function mouseOnArea(ev, code, area_of_use, enter) {
if (hooverRect) {
hooverRect.removeFrom(map);
hooverRect = null;
}
if (enter) {
hooverRect = makeRectangle(area_of_use, 'coral');
hooverRect.addTo(map);
}
}
let tabs = [
{ id:'PROJECTED_CRS', str:'Projected'},
{ id:'GEOGRAPHIC_2D_CRS', str:'Geographic 2D'},
{ id:'GEOGRAPHIC_3D_CRS' , str:'Geographic 3D'},
{ id:'GEOCENTRIC_CRS', str:'Geocentric' },
{ id:'GEODETIC_CRS', str:'Geodetic' },
{ id:'VERTICAL_CRS', str:'Vertical' },
{ id:'COMPOUND_CRS', str:'Compound'},
{ id:'CRS', str:'Other' },
];
let form = document.querySelector("form");
form.addEventListener("submit", function(event) {
event.preventDefault();
let str = form.elements.value.value;
setSearchText(str)
runFilter();
});
function setSearchText(str) {
form.elements.value.value = str;
str = str.trim();
filters.searchText = str;
if (str) {
document.querySelector('#activeSearch').classList.remove('hide');
document.querySelector('#activeSearchTxt').innerText = str;
} else {
document.querySelector('#activeSearch').classList.add('hide');
}
}
function toggleInfo() {
document.querySelector("#search_info").classList.toggle('hide');
}
function createTables() {
tabs.forEach(tab => filters.activeTypes[tab.id] = false);
let tabdiv = document.querySelector(`#tables`);
let tb = document.createElement('table');
tabdiv.appendChild(tb);
const ascCaret = '▲';
const desCaret = '▼';
let header = tb.createTHead();
let row = header.insertRow();
let order = '<span class="order"></span>';
['Code', 'Name', 'Area of Use', 'Type', 'WKT', 'Deprecated'].forEach(e => row.appendChild(document.createElement('th')).innerHTML = e + order);
let tblBody = document.createElement('tbody');
tb.appendChild(tblBody);
row.querySelector('th').asc = true;
row.querySelector('.order').innerHTML = ascCaret;
Array.from(tb.querySelectorAll('th')).forEach(th => th.addEventListener('click', (() => slowTask(() => {
Array.from(header.querySelectorAll('.order')).forEach(o => o.innerHTML = '');
th.asc = !th.asc;
sortOnTh(th);
th.querySelector('.order').innerHTML = th.asc ? ascCaret : desCaret;
}))));
}
function sortOnTh(th) {
const getCellValue = (tr, idx) => {
let str = tr.children[idx].innerText || tr.children[idx].textContent ;
if (idx == 0) {
let v = str.split(':');
str = v[0] + v[1].padStart(7,'0');
}
return str;
};
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
const tb = document.querySelector(`#tables > table`)
const tblBody = tb.querySelector('tbody');
if (!th) {
th = Array.from(tb.querySelectorAll('thead .order')).find(el => el.innerHTML != "").parentNode;
}
const idx = Array.from(th.parentNode.children).indexOf(th)
Array.from(tblBody.querySelectorAll('tr'))
.sort(comparer(idx, th.asc))
.forEach(tr => tblBody.appendChild(tr) );
colorBackground();
}
function createCheckboxes() {
let div = document.querySelector('#filters');
div.innerHTML = '';
tabs.forEach(tab => {
let el = document.createElement('label');
el.innerHTML = `<input type="checkbox" class="crstype" id="${tab.id}">${tab.str}`;
div.appendChild(el);
el.querySelector(`input`).addEventListener('click', function (ev) {
filters.activeTypes[tab.id] = ev.target.checked;
runFilter();
});
div.appendChild(document.createTextNode(' ')); // otherwise Firefox does not break between labels
});
div.appendChild(document.createTextNode(' | '));
let el = document.createElement('label');
div.appendChild(el).innerHTML = `<input type="checkbox" id="ignoreWorld">Ignore World`;
el.title = "Do not show CRS with area of use longitude from -180 to 180";
el.querySelector('input').addEventListener('change', function (ev) {
filters.ignoreWorld = ev.target.checked;
runFilter();
});
div.appendChild(document.createTextNode(' '));
el = document.createElement('label');
div.appendChild(el).innerHTML = `<input type="checkbox" id="allowDeprecated">Allow deprecated`;
el.title = "Display also deprecated systems";
el.querySelector('input').addEventListener('click', function (ev) {
filters.allowDeprecated = ev.target.checked;
runFilter();
});
}
function createAuthorities(db) {
let auths = []
db.forEach(crs => {
if (!auths.includes(crs.auth_name)) {
auths.push(crs.auth_name);
}
});
let div = document.querySelector('#authorities');
div.innerHTML = '';
auths.forEach(auth => {
let el = document.createElement('label');
el.innerHTML = `<input type="checkbox" id="${auth}"}>${auth}`;
div.appendChild(el);
filters.authorities[auth] = false;
document.querySelector(`#${auth}`).addEventListener('change', function (ev) {
filters.authorities[auth] = ev.target.checked;
runFilter();
});
div.appendChild(document.createTextNode(' '));
});
}
function slowTask(cb) {
document.querySelector('.loader-text').classList.remove('hide');
document.querySelector('.counter-text').classList.add('hide');
setTimeout(function() {
cb();
document.querySelector('.loader-text').classList.add('hide');
document.querySelector('.counter-text').classList.remove('hide');
}, 0);
}
let runCounter = 0;
function updateURL() {
let url = new URL(location);
url.search = querystringFromFilters();
if (runCounter == 0) {
} else if (runCounter == 1) {
window.history.pushState(null, '', url.toString());
} else {
window.history.replaceState(null, '', url.toString());
}
runCounter++;
}
function runFilter() {
updateURL();
slowTask(runFilterCb);
}
function intersects(box1, box2) {
if (box1.n < box2.s || box2.n < box1.s) {
return false;
}
if (box1.w <= box1.e && box2.w <= box2.e) {
// none crosses the antimeridian
return Math.max(box1.w, box2.w) <= Math.min(box1.e, box2.e);
} else if (box1.w > box1.e && box2.w > box2.e) {
// both cross the antimeridian
return true;
} else {
// one crosses the antimeridian
return box2.w <= box1.e || box1.w <= box2.e;
}
}
function normalizeLong(lng) {
while(lng < -180) {
lng += 360;
}
while (lng > 180) {
lng -= 360;
}
return lng;
}
function runFilterCb() {
fillTables();
// Show message to select a type if none is selected.
let message = document.querySelector('#message');
if (Object.keys(filters.activeTypes).find(t => filters.activeTypes[t])) {
message.classList.add('hide');
} else {
message.classList.remove('hide');
}
let byCode = [];
if (filters.searchText) {
Array.from(document.querySelectorAll(`tbody > tr`)).forEach(r => r.classList.add('hide'));
// first split in blocks divided by or |
const ors = filters.searchText.match(/([^\|]+)/g);
ors.forEach(or => {
let selector = '';
const number = or.match(/^\s*([1-9]\d*)\s*$/);
if (number && number.length == 2) {
selector = `tbody > tr[data-id$=":${number[1]}"] , `;
byCode = byCode.concat(fullDB.filter(crs => crs.code === number[1]));
}
const strs = or.match(/(-?".*?"|[^"\s]+)(?=\s*|\s*$)/g);
const selectorsArray = strs.map(x => {
if (x.charAt(0) == '-') {
x = x.replaceAll('"', '');
return `:not([data-crs-name*="${x.substring(1)}" i])`;
} else {
x = x.replaceAll('"', '');
return `[data-crs-name*="${x}" i]`;
}
});
selector += `tbody > tr${selectorsArray.join('')}`;
Array.from(document.querySelectorAll(selector)).forEach(r => r.classList.remove('hide'));
})
} else {
Array.from(document.querySelectorAll(`tbody > tr`)).forEach(r => r.classList.remove('hide'));
}
let selectorsArray = [];
if (filters.ignoreWorld) selectorsArray.push('[data-world="true"]');
if (!filters.allowDeprecated) selectorsArray.push('[data-deprecated="true"]');
Object.keys(filters.authorities).forEach(auth => {
if (!filters.authorities[auth]) {
selectorsArray.push(`[data-auth="${auth}"]`);
}
});
Object.keys(filters.activeTypes).forEach(t => {
if (!filters.activeTypes[t]) {
selectorsArray.push(`[data-type="${t}"]`);
}
});
if (selectorsArray.length > 0) {
const selector = selectorsArray.map(e => `tbody > tr${e}`).join(' , ');
Array.from(document.querySelectorAll(selector)).forEach(r => r.classList.add('hide'));
}
const latlng = filters.latlng;
const latlng2 = filters.latlng2;
if (latlng){
let w = latlng.lng;
let e = w;
let n = latlng.lat;
let s = n;
if (latlng2) {
w = Math.min(w, latlng2.lng);
e = Math.max(e, latlng2.lng);
n = Math.max(n, latlng2.lat);
s = Math.min(s, latlng2.lat);
}
if (e-w >= 360) {
w = -180;
e = 180;
} else {
w = normalizeLong(w);
e = normalizeLong(e);
}
const box1 = {w:w, s:s, e:e, n:n};
Array.from(document.querySelectorAll(`tbody > tr:not(.hide)`)).forEach(r => {
const box2 = {w:r.area_of_use[0], s:r.area_of_use[1], e:r.area_of_use[2], n:r.area_of_use[3]};
const use = intersects(box1, box2);
if (!use) r.classList.add('hide');
});
}
document.querySelector('#activeSearchTxt').innerText = filters.searchText;
colorBackground();
countElements();
byCode.forEach(crs =>{
let code = crs.auth_name + ":" + crs.code;
selector = `tbody > tr[data-id="${code}"]:not(.hide)`;
if (!document.querySelector(selector)) {
let reasons = [];
if (!filters.authorities[crs.auth_name]) {
reasons.push(crs.auth_name);
}
if (!filters.activeTypes[crs.type]) {
reasons.push(`${tabs.find(tab => tab.id == crs.type).str}`);
}
if (!filters.allowDeprecated && crs.deprecated) {
reasons.push('deprecated');
}
if (filters.ignoreWorld && crs.area_of_use[0] == -180 && crs.area_of_use[2] == 180) {
reasons.push('world-area-of-use');
}
if (reasons.length == 0) {
// filter by coordinates?
let areaName = crs.area_of_use[4];
if (areaName.length > 32) {
areaName = areaName.slice(0,32) + " …";
}
reasons.push(areaName);
}
let activeSearch = document.querySelector('#activeSearchTxt');
activeSearch.innerHTML += `<br> > <b>${code}</b> (${reasons.join(', ')}) is not displayed. Set filters properly.`;
}
})
}
function colorBackground() {
Array.from(document.querySelectorAll(`tbody`)).forEach(tbody => {
let counter = 0;
Array.from(tbody.querySelectorAll(`tr:not(.hide)`)).forEach(r => {
counter += 1;
r.classList[counter % 2 ? 'remove' : 'add']('odd');
})
});
}
function countElements() {
const c = document.querySelectorAll(`#tables tbody tr:not(.hide)`).length;
document.querySelector('.counter-text').innerHTML = c;
}
function fillWktsField(wkts, crs) {
['1', '2'].forEach(n => {
const filename = `${versioned_url}./wkt${n}/${crs.auth_name}/${crs.code}.txt`;
let a = document.createElement('a');
a.setAttribute('href', filename);
a.innerText = `[${n}]`;
a.classList.add(`wkt${n}`);
let timeoutId = null
a.addEventListener('mouseenter', e => {
if (a.getAttribute('title')) return;
timeoutId = setTimeout(() => {
timeoutId = null;
fetch(filename, { method: "GET" })
.then(response => response.text())
.then(text => {
text = text.replaceAll("'", "\'");
a.setAttribute('title', text);
});
}, 300);
});
a.addEventListener('mouseleave', e => {
clearTimeout(timeoutId);
timeoutId = null;
});
wkts.appendChild(a);
});
wkts.classList.add('wkts_cell');
let a = document.createElement('span')
const sr = 'https://spatialreference.org';
const auth_lower = crs.auth_name.toLowerCase();
a.innerHTML = ` <a href="${sr}/ref/${auth_lower}/${crs.code}/" ` +
` title="Open ${crs.auth_name}:${crs.code} in spatialreference.org">` +
`<img class="sr-icon" src="${sr}/favicon.ico" width="16"></a>`;
wkts.appendChild(a);
}
function fillTables(db) {
function hashAlreadyLoaded(auth, type) {
return auth + ":" + type;
}
if (!db) {
db = fullDB;
}
const activeAuthorities = Object.keys(filters.authorities).filter(key => filters.authorities[key]);
const activeTypes = Object.keys(filters.activeTypes).filter(key => filters.activeTypes[key]);
let allDone = true;
const selectedSet = new Set();
activeAuthorities.forEach(auth => {
activeTypes.forEach(type => {
const hash = hashAlreadyLoaded(auth, type);
selectedSet.add(hash)
if (!alreadyLoadedSet.has(hash)) {
allDone = false;
}
})
})
if (allDone) return;
tabmap = {};
tabs.forEach(tab => tabmap[tab.id] = tab.str);
let table = document.querySelector('#tables table > tbody');
db.filter (crs => {
const hash = hashAlreadyLoaded(crs.auth_name, crs.type);
return !alreadyLoadedSet.has(hash) && selectedSet.has(hash);
}).forEach (crs => {
let code = crs.auth_name + ":" + crs.code;
let row = table.insertRow();
row.classList.add('hide')
row.setAttribute('data-crs-name', crs.name);
row.setAttribute('data-type', crs.type);
row.setAttribute('data-id', code);
row.setAttribute('data-auth', crs.auth_name);
row.setAttribute('data-deprecated', crs.deprecated);
row.setAttribute('data-world', crs.area_of_use[0] == -180 && crs.area_of_use[2] == 180);
row.area_of_use = crs.area_of_use.slice(0, 4);
let linkedCode = code;
if (crs.auth_name == "EPSG") {
const scapedName = crs.name.replace(/[^0-9a-zA-Z]+/g, '-');
linkedCode = `<a href="https://epsg.org/crs_${crs.code}/${scapedName}.html">${code}</a>`;
}
row.insertCell().innerHTML = linkedCode;
row.insertCell().innerHTML = crs.name;
let area = row.insertCell();
area.innerHTML = `<label><input type="checkbox"> ${crs.area_of_use[4]}</label>`;
area.querySelector(`input`).addEventListener('click', function (ev) {clickArea(ev, code, crs.area_of_use)});
area.title = crs.area_of_use[4];
area.classList.add('area');
area.addEventListener('mouseenter', ev => mouseOnArea(ev, code, crs.area_of_use, true));
area.addEventListener('mouseleave', ev => mouseOnArea(ev, code, crs.area_of_use, false));
row.insertCell().innerHTML = tabmap[crs.type];
let wkts = row.insertCell();
fillWktsField(wkts, crs);
row.insertCell().innerHTML = crs.deprecated;
});
selectedSet.forEach(elem => alreadyLoadedSet.add(elem));
sortOnTh();
}
function paramsToDic(location) {
const url = new URL(location);
let dic = {};
for (let k of url.searchParams.keys()) {
dic[k] = url.searchParams.get(k);
}
return dic;
}
function updateFromParams(location) {
const dic = paramsToDic(location);
updateMapFromParams(dic);
updateFiltersFromParams(dic);
}
function versionChanged(that) {
const v = that.value;
if (v && v != 'latest') {
versioned_tag = v;
} else {
versioned_tag = '';
}
updateURL();
window.location.reload();
}
function processVersionFromParams(location) {
const dic = paramsToDic(location);
const v = dic['v'];
if (v && v != 'latest') {
var sel = document.getElementById("version");
if (!Array.from(sel.options).find(o => o.value == v)) {
window.alert(`Invalid version tag [${v}]. Latest will be used.`);
return;
}
versioned_tag = v;
versioned_url = `https://raw.githubusercontent.com/OSGeo/PROJ-CRS-Explorer/${v}/`;
document.getElementById("proj_version").innerText = versioned_tag + '*';
document.getElementById("metadata").href = versioned_url + 'metadata.txt';
sel.value = versioned_tag;
}
}
function loadDb() {
processVersionFromParams(window.location)
const url = versioned_url + 'crslist.json';
fetch(url, {
method: "GET",
})
.then(response => {
if (!response.ok) {
const message = "Something went wrong downloading " + url
alert(message);
updateURL();
throw new Error(message);
}
return response.json();
})
.then(data => {
fullDB = data;
createAuthorities(data);
updateFromParams(window.location);
fillTables(data);
runFilter();
})
.catch((error) => {
console.log(error)
});
}
function load() {
setTimeout(function() {
createCheckboxes();
createTables();
loadDb();
}, 1);
}
</script>
</body>
</html>