forked from MapComplete/MapComplete
Various fixes for bot
This commit is contained in:
parent
25c33d557d
commit
bd03a5a76a
3 changed files with 84 additions and 39 deletions
|
@ -17,14 +17,16 @@ export class AllKnownLayouts {
|
||||||
// Must be below the list...
|
// Must be below the list...
|
||||||
private static sharedLayers: Map<string, LayerConfig> = AllKnownLayouts.getSharedLayers();
|
private static sharedLayers: Map<string, LayerConfig> = AllKnownLayouts.getSharedLayers();
|
||||||
|
|
||||||
public static AllPublicLayers() {
|
public static AllPublicLayers(options?: {
|
||||||
|
includeInlineLayers:true | boolean
|
||||||
|
}) {
|
||||||
const allLayers: LayerConfig[] = []
|
const allLayers: LayerConfig[] = []
|
||||||
const seendIds = new Set<string>()
|
const seendIds = new Set<string>()
|
||||||
AllKnownLayouts.sharedLayers.forEach((layer, key) => {
|
AllKnownLayouts.sharedLayers.forEach((layer, key) => {
|
||||||
seendIds.add(key)
|
seendIds.add(key)
|
||||||
allLayers.push(layer)
|
allLayers.push(layer)
|
||||||
})
|
})
|
||||||
|
if (options?.includeInlineLayers ?? true) {
|
||||||
const publicLayouts = AllKnownLayouts.layoutsList.filter(l => !l.hideFromOverview)
|
const publicLayouts = AllKnownLayouts.layoutsList.filter(l => !l.hideFromOverview)
|
||||||
for (const layout of publicLayouts) {
|
for (const layout of publicLayouts) {
|
||||||
if (layout.hideFromOverview) {
|
if (layout.hideFromOverview) {
|
||||||
|
@ -39,11 +41,15 @@ export class AllKnownLayouts {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allLayers
|
return allLayers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static themesUsingLayer(id: string, publicOnly = true): LayoutConfig[] {
|
||||||
|
return AllKnownLayouts.layoutsList.filter(l => !(publicOnly && l.hideFromOverview) && l.id !== "personal" && l.layers.some(layer => layer.id === id))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates documentation for the layers.
|
* Generates documentation for the layers.
|
||||||
* Inline layers are included (if the theme is public)
|
* Inline layers are included (if the theme is public)
|
||||||
|
@ -70,7 +76,7 @@ export class AllKnownLayouts {
|
||||||
if (builtinLayerIds.has(layer.id)) {
|
if (builtinLayerIds.has(layer.id)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if(layer.source.geojsonSource !== undefined){
|
if (layer.source.geojsonSource !== undefined) {
|
||||||
// Not an OSM-source
|
// Not an OSM-source
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -184,6 +190,17 @@ export class AllKnownLayouts {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GenerateDocumentationForTheme(theme: LayoutConfig): BaseUIElement {
|
||||||
|
return new Combine([
|
||||||
|
new Title(new Combine([theme.title, "(", theme.id + ")"]), 2),
|
||||||
|
theme.description,
|
||||||
|
"This theme contains the following layers:",
|
||||||
|
new List(theme.layers.map(l => l.id)),
|
||||||
|
"Available languages:",
|
||||||
|
new List(theme.language)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
private static getSharedLayers(): Map<string, LayerConfig> {
|
private static getSharedLayers(): Map<string, LayerConfig> {
|
||||||
const sharedLayers = new Map<string, LayerConfig>();
|
const sharedLayers = new Map<string, LayerConfig>();
|
||||||
for (const layer of known_themes.layers) {
|
for (const layer of known_themes.layers) {
|
||||||
|
@ -230,15 +247,4 @@ export class AllKnownLayouts {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GenerateDocumentationForTheme(theme: LayoutConfig): BaseUIElement{
|
|
||||||
return new Combine([
|
|
||||||
new Title(new Combine([theme.title, "(",theme.id+")"]), 2),
|
|
||||||
theme.description,
|
|
||||||
"This theme contains the following layers:",
|
|
||||||
new List(theme.layers.map(l => l.id)),
|
|
||||||
"Available languages:",
|
|
||||||
new List(theme.language)
|
|
||||||
])
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import {BBox} from "../BBox";
|
||||||
export interface GeoCodeResult {
|
export interface GeoCodeResult {
|
||||||
display_name: string,
|
display_name: string,
|
||||||
lat: number, lon: number, boundingbox: number[],
|
lat: number, lon: number, boundingbox: number[],
|
||||||
osm_type: string, osm_id: string
|
osm_type: "node" | "way" | "relation",
|
||||||
|
osm_id: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Geocoding {
|
export class Geocoding {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {Utils} from "../../Utils";
|
||||||
import {UIEventSource} from "../UIEventSource";
|
import {UIEventSource} from "../UIEventSource";
|
||||||
import {BBox} from "../BBox";
|
import {BBox} from "../BBox";
|
||||||
import * as osmtogeojson from "osmtogeojson";
|
import * as osmtogeojson from "osmtogeojson";
|
||||||
|
import {FeatureCollection} from "@turf/turf";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interfaces overpass to get all the latest data
|
* Interfaces overpass to get all the latest data
|
||||||
|
@ -34,12 +35,19 @@ export class Overpass {
|
||||||
this._relationTracker = relationTracker
|
this._relationTracker = relationTracker
|
||||||
}
|
}
|
||||||
|
|
||||||
public async queryGeoJson(bounds: BBox): Promise<[any, Date]> {
|
public async queryGeoJson(bounds: BBox, ): Promise<[FeatureCollection, Date]> {
|
||||||
|
const bbox = "[bbox:" + bounds.getSouth() + "," + bounds.getWest() + "," + bounds.getNorth() + "," + bounds.getEast() + "]";
|
||||||
|
const query = this.buildScript(bbox)
|
||||||
|
return this.ExecuteQuery(query);
|
||||||
|
}
|
||||||
|
|
||||||
let query = this.buildQuery("[bbox:" + bounds.getSouth() + "," + bounds.getWest() + "," + bounds.getNorth() + "," + bounds.getEast() + "]")
|
public buildUrl(query: string){
|
||||||
|
return `${this._interpreterUrl}?data=${encodeURIComponent(query)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ExecuteQuery(query: string):Promise<[FeatureCollection, Date]> {
|
||||||
const self = this;
|
const self = this;
|
||||||
const json = await Utils.downloadJson(query)
|
const json = await Utils.downloadJson(this.buildUrl(query))
|
||||||
|
|
||||||
if (json.elements.length === 0 && json.remark !== undefined) {
|
if (json.elements.length === 0 && json.remark !== undefined) {
|
||||||
console.warn("Timeout or other runtime error while querying overpass", json.remark);
|
console.warn("Timeout or other runtime error while querying overpass", json.remark);
|
||||||
|
@ -52,11 +60,12 @@ export class Overpass {
|
||||||
self._relationTracker?.RegisterRelations(json)
|
self._relationTracker?.RegisterRelations(json)
|
||||||
const geojson = osmtogeojson.default(json);
|
const geojson = osmtogeojson.default(json);
|
||||||
const osmTime = new Date(json.osm3s.timestamp_osm_base);
|
const osmTime = new Date(json.osm3s.timestamp_osm_base);
|
||||||
return [geojson, osmTime];
|
return [<any> geojson, osmTime];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the actual script
|
* Constructs the actual script to execute on Overpass
|
||||||
|
* 'PostCall' can be used to set an extra range, see 'AsOverpassTurboLink'
|
||||||
*
|
*
|
||||||
* import {Tag} from "../Tags/Tag";
|
* import {Tag} from "../Tags/Tag";
|
||||||
*
|
*
|
||||||
|
@ -79,10 +88,39 @@ export class Overpass {
|
||||||
}
|
}
|
||||||
return`[out:json][timeout:${this._timeout.data}]${bbox};(${filter});out body;${this._includeMeta ? 'out meta;' : ''}>;out skel qt;`
|
return`[out:json][timeout:${this._timeout.data}]${bbox};(${filter});out body;${this._includeMeta ? 'out meta;' : ''}>;out skel qt;`
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Constructs the actual script to execute on Overpass with geocoding
|
||||||
|
* 'PostCall' can be used to set an extra range, see 'AsOverpassTurboLink'
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public buildScriptInArea(area: {osm_type: "way" | "relation", osm_id: number}, pretty = false): string {
|
||||||
|
const filters = this._filter.asOverpass()
|
||||||
|
let filter = ""
|
||||||
|
for (const filterOr of filters) {
|
||||||
|
if(pretty){
|
||||||
|
filter += " "
|
||||||
|
}
|
||||||
|
filter += 'nwr' + filterOr + '(area.searchArea);'
|
||||||
|
if(pretty){
|
||||||
|
filter+="\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const extraScript of this._extraScripts) {
|
||||||
|
filter += '(' + extraScript + ');';
|
||||||
|
}
|
||||||
|
let id = area.osm_id;
|
||||||
|
if(area.osm_type === "relation"){
|
||||||
|
id += 3600000000
|
||||||
|
}
|
||||||
|
return`[out:json][timeout:${this._timeout.data}];
|
||||||
|
area(id:${id})->.searchArea;
|
||||||
|
(${filter});
|
||||||
|
out body;${this._includeMeta ? 'out meta;' : ''}>;out skel qt;`
|
||||||
|
}
|
||||||
|
|
||||||
public buildQuery(bbox: string): string {
|
|
||||||
const query = this.buildScript(bbox)
|
public buildQuery(bbox: string) {
|
||||||
return `${this._interpreterUrl}?data=${encodeURIComponent(query)}`
|
return this.buildUrl(this.buildScript(bbox))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue