Revert "Improve typing"

This reverts commit 4d783aae45.
This commit is contained in:
pietervdvn 2022-08-24 02:28:41 +02:00
parent 4d783aae45
commit aac736eba8
4 changed files with 8 additions and 19 deletions

View file

@ -3,7 +3,6 @@ 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, OsmId, OsmTags, RelationId, WayId} from "../../Models/OsmFeature";
export abstract class OsmObject { export abstract class OsmObject {
@ -39,12 +38,10 @@ export abstract class OsmObject {
throw "Backend URL must begin with http" throw "Backend URL must begin with http"
} }
this.backendURL = url; this.backendURL = url;
this.DownloadObject("id/5")
} }
public static DownloadObject(id: NodeId, forceRefresh?: boolean ): Store<OsmNode> ; public static DownloadObject(id: string, forceRefresh: boolean = false): Store<OsmObject> {
public static DownloadObject(id: WayId, forceRefresh?: boolean ): Store<OsmWay> ;
public static DownloadObject(id: RelationId, forceRefresh?: boolean ): Store<OsmRelation> ;
public static DownloadObject(id: OsmId, forceRefresh: boolean = false): Store<OsmObject> {
let src: UIEventSource<OsmObject>; let src: UIEventSource<OsmObject>;
if (OsmObject.objectCache.has(id)) { if (OsmObject.objectCache.has(id)) {
src = OsmObject.objectCache.get(id) src = OsmObject.objectCache.get(id)
@ -54,14 +51,14 @@ export abstract class OsmObject {
return src; return src;
} }
} else { } else {
src = UIEventSource.FromPromise(OsmObject.DownloadObjectAsync(<any> id)) src = UIEventSource.FromPromise(OsmObject.DownloadObjectAsync(id))
} }
OsmObject.objectCache.set(id, src); OsmObject.objectCache.set(id, src);
return src; return src;
} }
static async DownloadPropertiesOf(id: OsmId): Promise<OsmTags> { static async DownloadPropertiesOf(id: string): Promise<any> {
const splitted = id.split("/"); const splitted = id.split("/");
const idN = Number(splitted[1]); const idN = Number(splitted[1]);
if (idN < 0) { if (idN < 0) {
@ -73,10 +70,7 @@ export abstract class OsmObject {
return rawData.elements[0].tags return rawData.elements[0].tags
} }
static async DownloadObjectAsync(id: NodeId): Promise<OsmNode | undefined>; static async DownloadObjectAsync(id: string): Promise<OsmObject | 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>{
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]);

View file

@ -1,9 +1,4 @@
import {Feature, Geometry} from "@turf/turf"; import {Feature, Geometry} from "@turf/turf";
export type RelationId = `relation/${number}` export type OsmTags = Record<string, string> & {id: string}
export type WayId = `way/${number}`
export type NodeId = `node/${number}`
export type OsmId = NodeId | WayId | RelationId
export type OsmTags = Record<string, string> & {id: OsmId}
export type OsmFeature = Feature<Geometry, OsmTags> export type OsmFeature = Feature<Geometry, OsmTags>

View file

@ -41,7 +41,7 @@
"maxZoom": 14, "maxZoom": 14,
"minNeededElements": 100 "minNeededElements": 100
}, },
"credits": "nicolelaine", "credits": "nicolelaine"
"layers": [ "layers": [
"postboxes", "postboxes",
"postoffices", "postoffices",

View file

@ -604,7 +604,7 @@ describe("RelationSplitHandler", () => {
"should split turn restrictions (split of https://www.openstreetmap.org/way/143298912)", "should split turn restrictions (split of https://www.openstreetmap.org/way/143298912)",
async () => { async () => {
const relation: OsmRelation = await OsmObject.DownloadObjectAsync("relation/4374576") const relation: OsmRelation = <OsmRelation>await OsmObject.DownloadObjectAsync("relation/4374576")
const originalNodeIds = const originalNodeIds =
[ [
1407529979, 1407529979,