import { FeatureSource, WritableFeatureSource } from "../FeatureSource" import { ImmutableStore, Store, UIEventSource } from "../../UIEventSource" import { Feature } from "geojson" ;("use strict") /** * A simple, read only feature store. */ export default class StaticFeatureSource implements FeatureSource { public readonly features: Store constructor(features: Store | T[] | { features: T[] } | { features: Store }) { if (features === undefined) { throw "Static feature source received undefined as source" } let feats: T[] | Store if (features["features"]) { feats = features["features"] } else { feats = >features } if (Array.isArray(feats)) { this.features = new ImmutableStore(feats) } else { this.features = feats } } public static fromGeojson(geojson: T[]): StaticFeatureSource { return new StaticFeatureSource(geojson) } } export class WritableStaticFeatureSource implements WritableFeatureSource { public readonly features: UIEventSource = undefined constructor(features: UIEventSource | T[] | { features: T[] } | { features: Store }) { if (features === undefined) { throw "Static feature source received undefined as source" } let feats: T[] | UIEventSource if (features["features"]) { feats = features["features"] } else { feats = >features } if (Array.isArray(feats)) { this.features = new UIEventSource(feats) } else { this.features = feats } } }