diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2024-10-31 11:27:20 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2024-10-31 12:01:51 +0800 |
commit | 7ee1ad61627f9a2af04f080cfa95a30f3c8e4525 (patch) | |
tree | cff733c310788f802fe00fbcdd8f4054a3ef4075 /src/MenuItem.mjs | |
parent | 2bcad7ff9a42ad39a4b2f24c4af9b6a5578ba1fd (diff) |
feat: add menu-item for Geocoding
* Use nominatim for API calls
* Create multiple GeoLinks for each results in response
* Also add menu-item DELETE to remove duplicated GeoLinks from one
Geocoding
Diffstat (limited to 'src/MenuItem.mjs')
-rw-r--r-- | src/MenuItem.mjs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/MenuItem.mjs b/src/MenuItem.mjs index 103f43e..13dbc44 100644 --- a/src/MenuItem.mjs +++ b/src/MenuItem.mjs | |||
@@ -586,3 +586,26 @@ export const editMap = (map, dumbymap) => { | |||
586 | ], | 586 | ], |
587 | }) | 587 | }) |
588 | } | 588 | } |
589 | |||
590 | export const addLinkbyNominatim = (range) => { | ||
591 | return Item({ | ||
592 | text: 'Add Link by Geocoding', | ||
593 | onclick: () => { | ||
594 | const place = range.toString() | ||
595 | fetch(`https://nominatim.openstreetmap.org/search?q=${place.toString()}&format=json`) | ||
596 | .then(res => res.json()) | ||
597 | .then(places => { | ||
598 | if (places.length === 0) return | ||
599 | console.log('nomiatim', places) | ||
600 | range.deleteContents() | ||
601 | places.forEach(p => { | ||
602 | const a = document.createElement('a') | ||
603 | a.className = 'not-geolink from-geocoding' | ||
604 | a.href = `geo:${p.lat},${p.lon}?name=${p.name}&osm=${p.osm_type}/${p.osm_id}` | ||
605 | a.textContent = place | ||
606 | range.insertNode(a) | ||
607 | }) | ||
608 | }) | ||
609 | }, | ||
610 | }) | ||
611 | } | ||