forked from MapComplete/MapComplete
Improve typing
This commit is contained in:
parent
234129ad32
commit
e653a76b69
2 changed files with 15 additions and 4 deletions
|
@ -3,6 +3,7 @@ import * as polygon_features from "../../assets/polygon-features.json";
|
||||||
import {Store, UIEventSource} from "../UIEventSource";
|
import {Store, UIEventSource} from "../UIEventSource";
|
||||||
import {BBox} from "../BBox";
|
import {BBox} from "../BBox";
|
||||||
import * as OsmToGeoJson from "osmtogeojson";
|
import * as OsmToGeoJson from "osmtogeojson";
|
||||||
|
import {NodeId, OsmFeature, OsmId, OsmTags, RelationId, WayId} from "../../Models/OsmFeature";
|
||||||
|
|
||||||
export abstract class OsmObject {
|
export abstract class OsmObject {
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ export abstract class OsmObject {
|
||||||
/**
|
/**
|
||||||
* The OSM tags as simple object
|
* The OSM tags as simple object
|
||||||
*/
|
*/
|
||||||
tags: {} = {};
|
tags: OsmTags ;
|
||||||
version: number;
|
version: number;
|
||||||
public changed: boolean = false;
|
public changed: boolean = false;
|
||||||
timestamp: Date;
|
timestamp: Date;
|
||||||
|
@ -69,7 +70,12 @@ export abstract class OsmObject {
|
||||||
return rawData.elements[0].tags
|
return rawData.elements[0].tags
|
||||||
}
|
}
|
||||||
|
|
||||||
static async DownloadObjectAsync(id: string): Promise<OsmObject | undefined> {
|
static async DownloadObjectAsync(id: NodeId): Promise<OsmNode | undefined>;
|
||||||
|
static async DownloadObjectAsync(id: WayId): Promise<OsmWay | undefined>;
|
||||||
|
static async DownloadObjectAsync(id: RelationId): Promise<OsmRelation | undefined>;
|
||||||
|
static async DownloadObjectAsync(id: OsmId): Promise<OsmObject | undefined>;
|
||||||
|
static async DownloadObjectAsync(id: string): Promise<OsmObject | undefined>;
|
||||||
|
static async DownloadObjectAsync(id: string): Promise<OsmObject | undefined>{
|
||||||
const splitted = id.split("/");
|
const splitted = id.split("/");
|
||||||
const type = splitted[0];
|
const type = splitted[0];
|
||||||
const idN = Number(splitted[1]);
|
const idN = Number(splitted[1]);
|
||||||
|
@ -315,7 +321,7 @@ export abstract class OsmObject {
|
||||||
tgs["_last_edit:changeset"] = element.changeset
|
tgs["_last_edit:changeset"] = element.changeset
|
||||||
tgs["_last_edit:timestamp"] = element.timestamp
|
tgs["_last_edit:timestamp"] = element.timestamp
|
||||||
tgs["_version_number"] = element.version
|
tgs["_version_number"] = element.version
|
||||||
tgs["id"] = this.type + "/" + this.id;
|
tgs["id"] =<OsmId> ( this.type + "/" + this.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +353,7 @@ export class OsmNode extends OsmObject {
|
||||||
return [this.lat, this.lon];
|
return [this.lat, this.lon];
|
||||||
}
|
}
|
||||||
|
|
||||||
asGeoJson() {
|
asGeoJson() : OsmFeature{
|
||||||
return {
|
return {
|
||||||
"type": "Feature",
|
"type": "Feature",
|
||||||
"properties": this.tags,
|
"properties": this.tags,
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
import {Feature, Geometry} from "@turf/turf";
|
import {Feature, Geometry} from "@turf/turf";
|
||||||
|
|
||||||
|
export type RelationId = `relation/${number}`
|
||||||
|
export type WayId = `way/${number}`
|
||||||
|
export type NodeId = `node/${number}`
|
||||||
|
export type OsmId = NodeId | WayId | RelationId
|
||||||
|
|
||||||
export type OsmTags = Record<string, string> & {id: string}
|
export type OsmTags = Record<string, string> & {id: string}
|
||||||
export type OsmFeature = Feature<Geometry, OsmTags>
|
export type OsmFeature = Feature<Geometry, OsmTags>
|
Loading…
Add table
Add a link
Reference in a new issue