summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--objects.js7
-rw-r--r--threads.js28
2 files changed, 34 insertions, 1 deletions
diff --git a/objects.js b/objects.js
index 92367f1..3bdda48 100644
--- a/objects.js
+++ b/objects.js
@@ -219,6 +219,12 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'lat, lon of %s',
defaults: ['Tiergarten Berlin']
},
+ // TODO: move these to a 'map' category or so
+ reportGeocode: {
+ type: 'reporter',
+ category: 'motion',
+ spec: 'address at lon: %n lat: %n'
+ },
focusMap: {
type: 'command',
category: 'motion',
@@ -1772,6 +1778,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
if (cat === 'motion') {
blocks.push(block('userLon'));
blocks.push(block('userLat'));
+ blocks.push(block('reportGeocode'));
blocks.push(block('findLocation'));
blocks.push(block('focusMap'));
diff --git a/threads.js b/threads.js
index 8d60447..e2eeae9 100644
--- a/threads.js
+++ b/threads.js
@@ -2642,6 +2642,32 @@ Process.prototype.addMarker = function (pos) {
L.marker(pos.contents).addTo(window.map);
};
+Process.prototype.reportGeocode = function (lon, lat) {
+ var myself = this;
+
+ if (!myself.context.jsonpScript) {
+ window.OSM_JSONP_Callback = function (data) {
+ myself.context.json = data;
+ window.OSM_JSONP_Callback = undefined;
+ };
+ myself.context.jsonpScript = document.createElement('script');
+ myself.context.jsonpScript.src =
+ 'https://nominatim.openstreetmap.org/reverse'
+ + '?format=json&json_callback=OSM_JSONP_Callback'
+ + '&addressdetails=0&limit=1&zoom=18'
+ + '&lon=' + lon + '&lat=' + lat;
+ document.getElementsByTagName('HEAD')[0]
+ .appendChild(myself.context.jsonpScript);
+ } else {
+ if (myself.context.json) {
+ return myself.context.json.display_name;
+ }
+ }
+
+ this.pushContext('doYield');
+ this.pushContext();
+}
+
Process.prototype.findLocation = function (searchString) {
var myself = this;
@@ -2655,7 +2681,7 @@ Process.prototype.findLocation = function (searchString) {
'https://nominatim.openstreetmap.org/search'
+ '?format=json&json_callback=OSM_JSONP_Callback'
+ '&addressdetails=0&limit=1'
- + '&q=' + myself.inputOption(searchString);
+ + '&q=' + searchString;
document.getElementsByTagName('HEAD')[0]
.appendChild(myself.context.jsonpScript);
} else {