2023-04-06 01:33:08 +02:00
|
|
|
import { FeatureSource , FeatureSourceForLayer, Tiled } from "../FeatureSource"
|
2022-10-27 01:50:41 +02:00
|
|
|
import { ImmutableStore, Store } from "../../UIEventSource"
|
2022-06-05 02:24:14 +02:00
|
|
|
import FilteredLayer from "../../../Models/FilteredLayer"
|
2022-10-27 01:50:41 +02:00
|
|
|
import { BBox } from "../../BBox"
|
|
|
|
import { Feature } from "geojson"
|
2021-09-21 01:47:58 +02:00
|
|
|
|
|
|
|
/**
|
2022-06-05 02:24:14 +02:00
|
|
|
* A simple, read only feature store.
|
2021-09-21 01:47:58 +02:00
|
|
|
*/
|
|
|
|
export default class StaticFeatureSource implements FeatureSource {
|
2023-03-23 01:42:47 +01:00
|
|
|
public readonly features: Store<Feature[]>
|
2021-09-21 01:47:58 +02:00
|
|
|
|
2022-07-08 03:14:55 +02:00
|
|
|
constructor(
|
2023-03-23 01:42:47 +01:00
|
|
|
features:
|
|
|
|
| Store<Feature[]>
|
|
|
|
| Feature[]
|
|
|
|
| { features: Feature[] }
|
|
|
|
| { features: Store<Feature[]> }
|
2022-07-08 03:14:55 +02:00
|
|
|
) {
|
2022-06-05 02:24:14 +02:00
|
|
|
if (features === undefined) {
|
2022-02-09 22:37:21 +01:00
|
|
|
throw "Static feature source received undefined as source"
|
|
|
|
}
|
2023-03-23 01:42:47 +01:00
|
|
|
let feats: Feature[] | Store<Feature[]>
|
|
|
|
if (features["features"]) {
|
|
|
|
feats = features["features"]
|
|
|
|
} else {
|
|
|
|
feats = <Feature[] | Store<Feature[]>>features
|
|
|
|
}
|
2022-06-05 02:24:14 +02:00
|
|
|
|
2023-03-23 01:42:47 +01:00
|
|
|
if (Array.isArray(feats)) {
|
|
|
|
this.features = new ImmutableStore(feats)
|
|
|
|
} else {
|
|
|
|
this.features = feats
|
|
|
|
}
|
2022-07-08 03:14:55 +02:00
|
|
|
}
|
|
|
|
|
2023-03-23 01:42:47 +01:00
|
|
|
public static fromGeojson(geojson: Feature[]): StaticFeatureSource {
|
|
|
|
return new StaticFeatureSource(geojson)
|
2022-06-05 02:24:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class TiledStaticFeatureSource
|
|
|
|
extends StaticFeatureSource
|
|
|
|
implements Tiled, FeatureSourceForLayer
|
|
|
|
{
|
|
|
|
public readonly bbox: BBox = BBox.global
|
|
|
|
public readonly tileIndex: number
|
|
|
|
public readonly layer: FilteredLayer
|
|
|
|
|
2023-03-23 01:42:47 +01:00
|
|
|
constructor(features: Store<Feature[]>, layer: FilteredLayer, tileIndex: number = 0) {
|
2022-06-05 02:24:14 +02:00
|
|
|
super(features)
|
|
|
|
this.tileIndex = tileIndex
|
|
|
|
this.layer = layer
|
|
|
|
this.bbox = BBox.fromTileIndex(this.tileIndex)
|
2021-09-21 01:47:58 +02:00
|
|
|
}
|
2022-06-05 02:24:14 +02:00
|
|
|
}
|