forked from MapComplete/MapComplete
More refactoring, move minimap behind facade
This commit is contained in:
parent
c11ff652b8
commit
d5c1ba4cd1
79 changed files with 1848 additions and 1118 deletions
|
@ -1,15 +1,30 @@
|
|||
/**
|
||||
* Represents a single change to an object
|
||||
*/
|
||||
export interface ChangeDescription {
|
||||
|
||||
/**
|
||||
* Identifier of the object
|
||||
*/
|
||||
type: "node" | "way" | "relation",
|
||||
/**
|
||||
* Negative for a new objects
|
||||
* Identifier of the object
|
||||
* Negative for new objects
|
||||
*/
|
||||
id: number,
|
||||
/*
|
||||
v = "" or v = undefined to erase this tag
|
||||
*/
|
||||
|
||||
/**
|
||||
* All changes to tags
|
||||
* v = "" or v = undefined to erase this tag
|
||||
*/
|
||||
tags?: { k: string, v: string }[],
|
||||
|
||||
/**
|
||||
* A change to the geometry:
|
||||
* 1) Change of node location
|
||||
* 2) Change of way geometry
|
||||
* 3) Change of relation members (untested)
|
||||
*/
|
||||
changes?: {
|
||||
lat: number,
|
||||
lon: number
|
||||
|
|
|
@ -11,7 +11,7 @@ export class Geocoding {
|
|||
osm_type: string, osm_id: string
|
||||
}[]) => void),
|
||||
onFail: (() => void)) {
|
||||
const b = State.state.leafletMap.data.getBounds();
|
||||
const b = State.state.currentBounds.data;
|
||||
const url = Geocoding.host + "format=json&limit=1&viewbox=" +
|
||||
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}` +
|
||||
"&accept-language=nl&q=" + query;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as OsmToGeoJson from "osmtogeojson";
|
||||
import Bounds from "../../Models/Bounds";
|
||||
import {TagsFilter} from "../Tags/TagsFilter";
|
||||
import ExtractRelations from "./ExtractRelations";
|
||||
import RelationsTracker from "./RelationsTracker";
|
||||
import {Utils} from "../../Utils";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
|
@ -15,16 +15,20 @@ export class Overpass {
|
|||
private readonly _timeout: UIEventSource<number>;
|
||||
private readonly _extraScripts: string[];
|
||||
private _includeMeta: boolean;
|
||||
|
||||
private _relationTracker: RelationsTracker;
|
||||
|
||||
|
||||
constructor(filter: TagsFilter, extraScripts: string[],
|
||||
interpreterUrl: UIEventSource<string>,
|
||||
timeout: UIEventSource<number>,
|
||||
relationTracker: RelationsTracker,
|
||||
includeMeta = true) {
|
||||
this._timeout = timeout;
|
||||
this._interpreterUrl = interpreterUrl;
|
||||
this._filter = filter
|
||||
this._extraScripts = extraScripts;
|
||||
this._includeMeta = includeMeta;
|
||||
this._relationTracker = relationTracker
|
||||
}
|
||||
|
||||
queryGeoJson(bounds: Bounds, continuation: ((any, date: Date) => void), onFail: ((reason) => void)): void {
|
||||
|
@ -35,6 +39,7 @@ export class Overpass {
|
|||
console.log("Using testing URL")
|
||||
query = Overpass.testUrl;
|
||||
}
|
||||
const self = this;
|
||||
Utils.downloadJson(query)
|
||||
.then(json => {
|
||||
if (json.elements === [] && ((json.remarks ?? json.remark).indexOf("runtime error") >= 0)) {
|
||||
|
@ -44,13 +49,15 @@ export class Overpass {
|
|||
}
|
||||
|
||||
|
||||
ExtractRelations.RegisterRelations(json)
|
||||
self._relationTracker.RegisterRelations(json)
|
||||
// @ts-ignore
|
||||
const geojson = OsmToGeoJson.default(json);
|
||||
const osmTime = new Date(json.osm3s.timestamp_osm_base);
|
||||
|
||||
continuation(geojson, osmTime);
|
||||
}).catch(onFail)
|
||||
}).catch(e => {
|
||||
onFail(e);
|
||||
})
|
||||
}
|
||||
|
||||
buildQuery(bbox: string): string {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import State from "../../State";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
|
||||
export interface Relation {
|
||||
id: number,
|
||||
|
@ -13,11 +14,15 @@ export interface Relation {
|
|||
properties: any
|
||||
}
|
||||
|
||||
export default class ExtractRelations {
|
||||
export default class RelationsTracker {
|
||||
|
||||
public static RegisterRelations(overpassJson: any): void {
|
||||
const memberships = ExtractRelations.BuildMembershipTable(ExtractRelations.GetRelationElements(overpassJson))
|
||||
State.state.knownRelations.setData(memberships)
|
||||
public knownRelations = new UIEventSource<Map<string, { role: string; relation: Relation }[]>>(new Map(), "Relation memberships");
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
public RegisterRelations(overpassJson: any): void {
|
||||
this.UpdateMembershipTable(RelationsTracker.GetRelationElements(overpassJson))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +30,7 @@ export default class ExtractRelations {
|
|||
* @param overpassJson
|
||||
* @constructor
|
||||
*/
|
||||
public static GetRelationElements(overpassJson: any): Relation[] {
|
||||
private static GetRelationElements(overpassJson: any): Relation[] {
|
||||
const relations = overpassJson.elements
|
||||
.filter(element => element.type === "relation" && element.tags.type !== "multipolygon")
|
||||
for (const relation of relations) {
|
||||
|
@ -39,12 +44,11 @@ export default class ExtractRelations {
|
|||
* @param relations
|
||||
* @constructor
|
||||
*/
|
||||
public static BuildMembershipTable(relations: Relation[]): Map<string, { role: string, relation: Relation }[]> {
|
||||
const memberships = new Map<string, { role: string, relation: Relation }[]>()
|
||||
|
||||
private UpdateMembershipTable(relations: Relation[]): void {
|
||||
const memberships = this.knownRelations.data
|
||||
let changed = false;
|
||||
for (const relation of relations) {
|
||||
for (const member of relation.members) {
|
||||
|
||||
const role = {
|
||||
role: member.role,
|
||||
relation: relation
|
||||
|
@ -53,11 +57,21 @@ export default class ExtractRelations {
|
|||
if (!memberships.has(key)) {
|
||||
memberships.set(key, [])
|
||||
}
|
||||
memberships.get(key).push(role)
|
||||
const knownRelations = memberships.get(key)
|
||||
|
||||
const alreadyExists = knownRelations.some(knownRole => {
|
||||
return knownRole.role === role.role && knownRole.relation === role.relation
|
||||
})
|
||||
if (!alreadyExists) {
|
||||
knownRelations.push(role)
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
this.knownRelations.ping()
|
||||
}
|
||||
|
||||
return memberships
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue