diff options
| -rw-r--r-- | objects.js | 11 | ||||
| -rw-r--r-- | threads.js | 28 |
2 files changed, 36 insertions, 3 deletions
@@ -219,12 +219,16 @@ 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' }, + overpassQuerySucceeds: { + type: 'predicate', + category: 'motion', + spec: 'overpass query %s returns elements' + }, focusMap: { type: 'command', category: 'motion', @@ -1778,9 +1782,14 @@ SpriteMorph.prototype.blockTemplates = function (category) { if (cat === 'motion') { blocks.push(block('userLon')); blocks.push(block('userLat')); + blocks.push('-'); + blocks.push(block('overpassQuerySucceeds')); + blocks.push('-'); blocks.push(block('reportGeocode')); blocks.push(block('findLocation')); + blocks.push('-'); blocks.push(block('focusMap')); + blocks.push('-'); //if (this.world().isDevMode) { blocks.push(block('addMarker')); @@ -2642,6 +2642,30 @@ Process.prototype.addMarker = function (pos) { L.marker(pos.contents).addTo(window.map); }; +// Nesting reporters that 'doYield' sucks; as a workaround, +// there is a library imported that uses this function. +// TODO: Improve this :) +// +// returns true if there are elements returned by the overpass query +Process.prototype.overpassQuerySucceeds = function (query) { + var url = 'overpass-api.de/api/interpreter?data=[out:json];' + + query; + + var response; + if (!this.httpRequest) { + this.httpRequest = new XMLHttpRequest(); + this.httpRequest.open("GET", 'http://' + url, true); + this.httpRequest.send(null); + } else if (this.httpRequest.readyState === 4) { + response = this.httpRequest.responseText; + this.httpRequest = null; + console.log(response); // DEBUG + return JSON.parse(response).elements.length > 0; + } + this.pushContext('doYield'); + this.pushContext(); +}; + Process.prototype.reportGeocode = function (lon, lat) { var myself = this; @@ -2666,7 +2690,7 @@ Process.prototype.reportGeocode = function (lon, lat) { this.pushContext('doYield'); this.pushContext(); -} +}; Process.prototype.findLocation = function (searchString) { var myself = this; @@ -2693,7 +2717,7 @@ Process.prototype.findLocation = function (searchString) { this.pushContext('doYield'); this.pushContext(); -} +}; // Process Dates and times in Snap // Map block options to built-in functions |
