forked from MapComplete/MapComplete
Add better relation support
This commit is contained in:
parent
7b47af8978
commit
12afdcab75
18 changed files with 2637 additions and 2386 deletions
58
Logic/Osm/ExtractRelations.ts
Normal file
58
Logic/Osm/ExtractRelations.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import State from "../../State";
|
||||
|
||||
export interface Relation {
|
||||
id: number,
|
||||
type: "relation"
|
||||
members: {
|
||||
type: ("way" | "node" | "relation"),
|
||||
ref: number,
|
||||
role: string
|
||||
}[],
|
||||
tags: any,
|
||||
// Alias for tags; tags == properties
|
||||
properties: any
|
||||
}
|
||||
|
||||
export default class ExtractRelations {
|
||||
|
||||
public static RegisterRelations(overpassJson: any) : void{
|
||||
const memberships = ExtractRelations.BuildMembershipTable(ExtractRelations.GetRelationElements(overpassJson))
|
||||
console.log("Assigned memberships: ", memberships)
|
||||
State.state.knownRelations.setData(memberships)
|
||||
}
|
||||
|
||||
private static GetRelationElements(overpassJson: any): Relation[] {
|
||||
const relations = overpassJson.elements.filter(element => element.type === "relation")
|
||||
for (const relation of relations) {
|
||||
relation.properties = relation.tags
|
||||
}
|
||||
return relations
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a mapping of {memberId --> {role in relation, id of relation} }
|
||||
* @param relations
|
||||
* @constructor
|
||||
*/
|
||||
private static BuildMembershipTable(relations: Relation[]): Map<string, { role: string, relation: Relation, }[]> {
|
||||
const memberships = new Map<string, { role: string, relation: Relation }[]>()
|
||||
|
||||
for (const relation of relations) {
|
||||
for (const member of relation.members) {
|
||||
|
||||
const role = {
|
||||
role: member.role,
|
||||
relation: relation
|
||||
}
|
||||
const key = member.type + "/" + member.ref
|
||||
if (!memberships.has(key)) {
|
||||
memberships.set(key, [])
|
||||
}
|
||||
memberships.get(key).push(role)
|
||||
}
|
||||
}
|
||||
|
||||
return memberships
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
import * as $ from "jquery"
|
||||
import * as OsmToGeoJson from "osmtogeojson";
|
||||
import Bounds from "../../Models/Bounds";
|
||||
import {TagsFilter} from "../TagsFilter";
|
||||
import {TagsFilter} from "../Tags/TagsFilter";
|
||||
import ExtractRelations from "./ExtractRelations";
|
||||
|
||||
/**
|
||||
* Interfaces overpass to get all the latest data
|
||||
|
@ -38,9 +39,9 @@ export class Overpass {
|
|||
return;
|
||||
}
|
||||
|
||||
ExtractRelations.RegisterRelations(json)
|
||||
// @ts-ignore
|
||||
const geojson = OsmToGeoJson.default(json);
|
||||
console.log("Received geojson", geojson)
|
||||
const osmTime = new Date(json.osm3s.timestamp_osm_base);
|
||||
continuation(geojson, osmTime);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue