From d77c6e70ece4aeac3f927314a8f285e1c0085bef Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Sat, 17 Nov 2018 10:53:05 +0000 Subject: [PATCH] Add geocoding names to search --- CHANGELOG.md | 1 + README.md | 3 ++- package.json | 2 +- worldmap/index.html | 34 ++++++++++++++++++++++++++++++---- worldmap/worldmap.appcache | 2 +- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5bf90b..e571b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### Change Log for Node-RED Worldmap + - v1.5.11 - Let search also try geocoding lookup if not marks found. - v1.5.10 - Allow latest mark added to open popup, and allow `popped=false` to close. - v1.5.7 - Tidy up sidc entry, and drag-ability of nodes on drawing layer. - v1.5.6 - Add search command and clear search functionality. diff --git a/README.md b/README.md index 343494b..209e5aa 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ map web page for plotting "things" on. ### Updates +- v1.5.11 - Let search also try geocoding lookup if not marks found. - v1.5.10 - Allow latest mark added to open popup, and allow `popped=false` to close. - v1.5.7 - Tidy up sidc entry, and drag-ability of nodes on drawing layer. - v1.5.6 - Add search command and clear search functionality. @@ -242,7 +243,7 @@ Optional properties include - **lon** - move map to specified longitude. - **zoom** - move map to specified zoom level (1 - world, 13 to 20 max zoom depending on map). - **layer** - set map to specified base layer name - `{command:{layer:"Esri"}}` - - **search** - search markers on map for name containing `string`. An empty string `""` clears the search results. - `{command:{search:"Dave"}}` + - **search** - search markers on map for name containing `string`. If not found in existing markers, will then try geocoding looking using Nominatim. An empty string `""` clears the search results. - `{command:{search:"Dave"}}` - **showlayer** - show the named overlay(s) - `{command:{showlayer:"foo"}}` or `{command:{showlayer:["foo","bar"]}}` - **hidelayer** - hide the named overlay(s) - `{command:{hidelayer:"bar"}}` or `{command:{hidelayer:["bar","another"}}` - **side** - add a second map alongside with slide between them. Use the name of a *baselayer* to add - or "none" to remove the control. - `{command:{side:"Esri Satellite"}}` diff --git a/package.json b/package.json index edc0c33..511cdd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-contrib-web-worldmap", - "version": "1.5.10", + "version": "1.5.11", "description": "A Node-RED node to provide a web page of a world map for plotting things on.", "dependencies": { "cgi": "0.3.1", diff --git a/worldmap/index.html b/worldmap/index.html index bbe7e3b..bcd6ed6 100644 --- a/worldmap/index.html +++ b/worldmap/index.html @@ -391,10 +391,36 @@ function doSearch() { } } moveToMarks(); - if (lockit) { - document.getElementById('searchRes').innerHTML = " Found "+marks.length+" results within bounds."; - } else { - document.getElementById('searchRes').innerHTML = " Found "+marks.length+" results."; + if (marks.length === 0) { + // If no markers found let's try a geolookup... + var protocol = location.protocol; + if (protocol == "file:") { protocol = "https:"; } + var searchUrl = protocol + "//nominatim.openstreetmap.org/search?format=json&limit=1&q="; + + fetch(searchUrl + value) // Call the fetch function passing the url of the API as a parameter + .then((resp) => resp.json()) + .then(function(data) { + if (data.length > 0) { + var bb = data[0].boundingbox; + map.fitBounds([ [bb[0],bb[2]], [bb[1],bb[3]] ]); + map.panTo([data[0].lat, data[0].lon]); + } + else { + document.getElementById('searchRes').innerHTML = " Not Found"; + } + }) + .catch(function(err) { + if (err.toString() === "TypeError: Failed to fetch") { + document.getElementById('searchRes').innerHTML = " Not Found"; + } + }); + } + else { + if (lockit) { + document.getElementById('searchRes').innerHTML = " Found "+marks.length+" results within bounds."; + } else { + document.getElementById('searchRes').innerHTML = " Found "+marks.length+" results."; + } } } diff --git a/worldmap/worldmap.appcache b/worldmap/worldmap.appcache index c07e28a..36f3860 100644 --- a/worldmap/worldmap.appcache +++ b/worldmap/worldmap.appcache @@ -1,5 +1,5 @@ CACHE MANIFEST -# date: Nov 9th 2018 - v1.5.10 +# date: Nov 9th 2018 - v1.5.11 CACHE: index.html