diff options
| author | Code WvS <code-wvs@quantentunnel.de> | 2015-02-28 17:51:52 +0100 |
|---|---|---|
| committer | Code WvS <code-wvs@quantentunnel.de> | 2015-02-28 17:51:52 +0100 |
| commit | 6c76ce64d7fb274eb70f4feef17a9bf6dd2093ca (patch) | |
| tree | f23ed25c6fe53c6ec4f92c6599df9c4eacedb7ba | |
| parent | 881165be429151d8f2593c6893dd23da90a5288b (diff) | |
| download | snap-yow-6c76ce64d7fb274eb70f4feef17a9bf6dd2093ca.tar.gz snap-yow-6c76ce64d7fb274eb70f4feef17a9bf6dd2093ca.zip | |
add geocoding block
| -rw-r--r-- | objects.js | 7 | ||||
| -rw-r--r-- | threads.js | 28 |
2 files changed, 34 insertions, 1 deletions
@@ -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')); @@ -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 { |
