summaryrefslogtreecommitdiff
path: root/threads.js
diff options
context:
space:
mode:
Diffstat (limited to 'threads.js')
-rw-r--r--threads.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/threads.js b/threads.js
index 165c7fc..ccefb6f 100644
--- a/threads.js
+++ b/threads.js
@@ -2682,6 +2682,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 elements returned by the overpass query
+Process.prototype.overpassQuery = 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 new List(JSON.parse(response).elements);
+ }
+ 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 = {