From 7ee1ad61627f9a2af04f080cfa95a30f3c8e4525 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 31 Oct 2024 11:27:20 +0800 Subject: 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 --- src/MenuItem.mjs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/MenuItem.mjs') 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) => { ], }) } + +export const addLinkbyNominatim = (range) => { + return Item({ + text: 'Add Link by Geocoding', + onclick: () => { + const place = range.toString() + fetch(`https://nominatim.openstreetmap.org/search?q=${place.toString()}&format=json`) + .then(res => res.json()) + .then(places => { + if (places.length === 0) return + console.log('nomiatim', places) + range.deleteContents() + places.forEach(p => { + const a = document.createElement('a') + a.className = 'not-geolink from-geocoding' + a.href = `geo:${p.lat},${p.lon}?name=${p.name}&osm=${p.osm_type}/${p.osm_id}` + a.textContent = place + range.insertNode(a) + }) + }) + }, + }) +} -- cgit v1.2.3-70-g09d2