forked from MapComplete/MapComplete
Decrese dependency on jquery
This commit is contained in:
parent
e3f2c56d3e
commit
d0997480c0
8 changed files with 43 additions and 60 deletions
|
@ -1,5 +1,6 @@
|
|||
import $ from "jquery"
|
||||
import State from "../../State";
|
||||
import {Utils} from "../../Utils";
|
||||
|
||||
export class Geocoding {
|
||||
|
||||
private static readonly host = "https://nominatim.openstreetmap.org/search?";
|
||||
|
@ -9,17 +10,12 @@ export class Geocoding {
|
|||
osm_type: string, osm_id: string}[]) => void),
|
||||
onFail: (() => void)) {
|
||||
const b = State.state.leafletMap.data.getBounds();
|
||||
console.log(b);
|
||||
$.getJSON(
|
||||
Geocoding.host + "format=json&limit=1&viewbox=" +
|
||||
const url = Geocoding.host + "format=json&limit=1&viewbox=" +
|
||||
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}`+
|
||||
"&accept-language=nl&q=" + query,
|
||||
function (data) {
|
||||
handleResult(data);
|
||||
}).fail(() => {
|
||||
onFail();
|
||||
});
|
||||
"&accept-language=nl&q=" + query;
|
||||
Utils.downloadJson(
|
||||
url)
|
||||
.then(handleResult)
|
||||
.catch(onFail);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import * as $ from "jquery"
|
||||
import {Utils} from "../../Utils";
|
||||
import * as polygon_features from "../../assets/polygon-features.json";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
@ -151,7 +150,7 @@ export abstract class OsmObject {
|
|||
const minlat = bounds[1][0]
|
||||
const maxlat = bounds[0][0];
|
||||
const url = `${OsmObject.backendURL}api/0.6/map.json?bbox=${minlon},${minlat},${maxlon},${maxlat}`
|
||||
$.getJSON(url, data => {
|
||||
Utils.downloadJson(url).then( data => {
|
||||
const elements: any[] = data.elements;
|
||||
const objects = OsmObject.ParseObjects(elements)
|
||||
callback(objects);
|
||||
|
@ -274,7 +273,7 @@ export abstract class OsmObject {
|
|||
const self = this;
|
||||
const full = this.type !== "way" ? "" : "/full";
|
||||
const url = `${OsmObject.backendURL}api/0.6/${this.type}/${this.id}${full}`;
|
||||
$.getJSON(url, function (data) {
|
||||
Utils.downloadJson(url).then(data => {
|
||||
|
||||
const element = data.elements.pop();
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as $ from "jquery"
|
||||
import * as OsmToGeoJson from "osmtogeojson";
|
||||
import Bounds from "../../Models/Bounds";
|
||||
import {TagsFilter} from "../Tags/TagsFilter";
|
||||
import ExtractRelations from "./ExtractRelations";
|
||||
import {Utils} from "../../Utils";
|
||||
|
||||
/**
|
||||
* Interfaces overpass to get all the latest data
|
||||
|
@ -27,14 +27,8 @@ export class Overpass {
|
|||
console.log("Using testing URL")
|
||||
query = Overpass.testUrl;
|
||||
}
|
||||
$.getJSON(query,
|
||||
function (json, status) {
|
||||
if (status !== "success") {
|
||||
console.log("Query failed")
|
||||
onFail(status);
|
||||
return;
|
||||
}
|
||||
|
||||
Utils.downloadJson(query)
|
||||
.then(json => {
|
||||
if (json.elements === [] && json.remarks.indexOf("runtime error") > 0) {
|
||||
console.log("Timeout or other runtime error");
|
||||
onFail("Runtime error (timeout)")
|
||||
|
@ -47,8 +41,7 @@ export class Overpass {
|
|||
const osmTime = new Date(json.osm3s.timestamp_osm_base);
|
||||
|
||||
continuation(geojson, osmTime);
|
||||
|
||||
}).fail(onFail)
|
||||
}).catch(onFail)
|
||||
}
|
||||
|
||||
buildQuery(bbox: string): string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue