diff options
Diffstat (limited to 'threads.js')
| -rw-r--r-- | threads.js | 89 |
1 files changed, 89 insertions, 0 deletions
@@ -2676,6 +2676,95 @@ Process.prototype.reportTimer = function () { return 0; }; +Process.prototype.userLon = function () { + return window.geoposition.lng; +}; + +Process.prototype.userLat = function () { + return window.geoposition.lat; +}; + +Process.prototype.focusMap = function (lon, lat, zoom) { + window.map.setView([lat, lon], zoom); +}; + +// 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; + + 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; + + 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=' + 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 = { |
