|
1 | | -function init_map(area_of_use) { |
| 1 | +async function init_map(area_of_use, crs_type, id) { |
2 | 2 | if (!area_of_use) return; |
3 | | - let map = L.map('map').setView([0, 0], 1); |
| 3 | + let map = L.map('map'); |
4 | 4 | let osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { |
5 | 5 | attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
6 | 6 | maxZoom: 18, |
7 | 7 | }).addTo(map); |
8 | 8 | let rect = makeRectangle(area_of_use, 'green').addTo(map); |
9 | 9 | map.fitBounds(rect.getBounds()); |
| 10 | + if (crs_type === 'PROJECTED_CRS' || crs_type === 'GEOGRAPHIC_2D_CRS') { |
| 11 | + const decimals = crs_type === 'PROJECTED_CRS' ? 1 : 6; |
| 12 | + const proj = new Proj(); |
| 13 | + await proj.init(); |
| 14 | + const transformer = proj.create_transformer_from_crs({source_crs: 'EPSG:4326', target_crs: id}); |
| 15 | + const axes = proj.crs_axes({crs: id}); |
| 16 | + document.querySelector('#coordinates table tr:nth-child(1) .name').innerText = axes[0].name + ': '; |
| 17 | + document.querySelector('#coordinates table tr:nth-child(2) .name').innerText = axes[1].name + ': '; |
| 18 | + |
| 19 | + const marker = L.marker(rect.getCenter(), {draggable: true}).addTo(map); |
| 20 | + marker.on('move', (e) => { |
| 21 | + let res = [[NaN, NaN]]; |
| 22 | + try { |
| 23 | + res = transformer.transform({points: [[e.latlng.lat, e.latlng.lng]]}); |
| 24 | + } catch (_e) {} |
| 25 | + document.querySelector('#coordinates table tr:nth-child(1) .number').innerText = res[0][0].toFixed(decimals); |
| 26 | + document.querySelector('#coordinates table tr:nth-child(2) .number').innerText = res[0][1].toFixed(decimals); |
| 27 | + }); |
| 28 | + marker.setLatLng(rect.getCenter()); |
| 29 | + marker.once('move', (e) => { |
| 30 | + console.log(proj.proj_info()); |
| 31 | + document.getElementById('drag_marker').classList.add('hidden'); |
| 32 | + }); |
| 33 | + } |
10 | 34 | } |
11 | 35 |
|
12 | 36 | function makeRectangle (area_of_use, color) { |
|
0 commit comments