Docs: improve typing of FeatureSources

This commit is contained in:
Pieter Vander Vennet 2025-08-20 01:12:09 +02:00
parent c71036d6c6
commit 34924fd4b1
21 changed files with 140 additions and 127 deletions

View file

@ -3,9 +3,9 @@ import { Utils } from "../../Utils"
import { ImmutableStore, Store } from "../UIEventSource"
import { BBox } from "../BBox"
import osmtogeojson from "osmtogeojson"
import { FeatureCollection, Geometry } from "geojson"
import { OsmTags } from "../../Models/OsmFeature"
;("use strict")
import { Feature } from "geojson"
("use strict")
/**
* Interfaces overpass to get all the latest data
*/
@ -37,7 +37,7 @@ export class Overpass {
this._includeMeta = includeMeta
}
public async queryGeoJson(bounds: BBox): Promise<[FeatureCollection<Geometry, OsmTags>, Date]> {
public async queryGeoJson<T extends Feature>(bounds: BBox): Promise<[{features: T[]}, Date]> {
const bbox =
"[bbox:" +
bounds.getSouth() +
@ -49,16 +49,16 @@ export class Overpass {
bounds.getEast() +
"]"
const query = this.buildScript(bbox)
return await this.ExecuteQuery(query)
return await this.ExecuteQuery<T>(query)
}
public buildUrl(query: string) {
return `${this._interpreterUrl}?data=${encodeURIComponent(query)}`
}
private async ExecuteQuery(
private async ExecuteQuery<T extends Feature>(
query: string
): Promise<[FeatureCollection<Geometry, OsmTags>, Date]> {
): Promise<[{features: T[]}, Date]> {
const json = await Utils.downloadJson<{
elements: []
remark
@ -73,7 +73,7 @@ export class Overpass {
console.warn("No features for", this.buildUrl(query))
}
const geojson = <FeatureCollection<Geometry, OsmTags>>osmtogeojson(json)
const geojson = <{features: T[]}> <any> osmtogeojson(json)
const osmTime = new Date(json.osm3s.timestamp_osm_base)
return [geojson, osmTime]
}