diff options
| -rw-r--r-- | objects.js | 12 | ||||
| -rw-r--r-- | threads.js | 27 |
2 files changed, 39 insertions, 0 deletions
@@ -213,6 +213,12 @@ SpriteMorph.prototype.initBlocks = function () { category: 'map', spec: 'my location' }, + findLocation: { + type: 'reporter', + category: 'map', + spec: 'location of %s', + defaults: ['Tiergarten Berlin'] + }, focusMap: { type: 'command', category: 'map', @@ -1770,6 +1776,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { if (cat === 'map') { blocks.push(block('reportUserLocation')); + blocks.push(block('reportMyLocation')); + blocks.push(block('findLocation')); blocks.push(block('focusMap')); blocks.push(block('moveTo')); @@ -3355,6 +3363,10 @@ SpriteMorph.prototype.moveTo = function (pos) { this.updateMarker(); }; +SpriteMorph.prototype.reportMyLocation = function () { + return new List([this.geoposition.lat, this.geoposition.lng]); +}; + // SpriteMorph motion primitives Morph.prototype.setPosition = function (aPoint, justMe) { @@ -2638,6 +2638,33 @@ Process.prototype.addMarker = function (pos) { L.marker(pos.contents).addTo(window.map); }; +Process.prototype.findLocation = function (searchString) { + 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/search' + + '?format=json&json_callback=OSM_JSONP_Callback' + + '&addressdetails=0&limit=1' + + '&q=' + myself.inputOption(searchString); + document.getElementsByTagName('HEAD')[0] + .appendChild(myself.context.jsonpScript); + } else { + if (myself.context.json) { + return new List([myself.context.json[0].lat, + myself.context.json[0].lon]); + } + } + + this.pushContext('doYield'); + this.pushContext(); +} + // Process Dates and times in Snap // Map block options to built-in functions var dateMap = { |
