From dec42962047efbdcf261db9a51d9643fb573bd97 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Fri, 5 May 2023 01:25:12 +0200 Subject: [PATCH] Refactoring: add generics to some featureSources --- Logic/FeatureSource/FeatureSource.ts | 2 +- .../Sources/StaticFeatureSource.ts | 42 ++++++------------- .../Sources/TouchesBboxFeatureSource.ts | 15 +++---- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/Logic/FeatureSource/FeatureSource.ts b/Logic/FeatureSource/FeatureSource.ts index afe0b6092..62600deaa 100644 --- a/Logic/FeatureSource/FeatureSource.ts +++ b/Logic/FeatureSource/FeatureSource.ts @@ -18,7 +18,7 @@ export interface Tiled { /** * A feature source which only contains features for the defined layer */ -export interface FeatureSourceForLayer extends FeatureSource { +export interface FeatureSourceForLayer extends FeatureSource { readonly layer: FilteredLayer } diff --git a/Logic/FeatureSource/Sources/StaticFeatureSource.ts b/Logic/FeatureSource/Sources/StaticFeatureSource.ts index 81af90b91..4811d3612 100644 --- a/Logic/FeatureSource/Sources/StaticFeatureSource.ts +++ b/Logic/FeatureSource/Sources/StaticFeatureSource.ts @@ -1,30 +1,28 @@ -import { FeatureSource , FeatureSourceForLayer, Tiled } from "../FeatureSource" -import { ImmutableStore, Store } from "../../UIEventSource" -import FilteredLayer from "../../../Models/FilteredLayer" -import { BBox } from "../../BBox" -import { Feature } from "geojson" +import {FeatureSource} from "../FeatureSource" +import {ImmutableStore, Store} from "../../UIEventSource" +import {Feature} from "geojson" /** * A simple, read only feature store. */ -export default class StaticFeatureSource implements FeatureSource { - public readonly features: Store +export default class StaticFeatureSource implements FeatureSource { + public readonly features: Store constructor( features: - | Store - | Feature[] - | { features: Feature[] } - | { features: Store } + | Store + | T[] + | { features: T[] } + | { features: Store } ) { if (features === undefined) { throw "Static feature source received undefined as source" } - let feats: Feature[] | Store + let feats: T[] | Store if (features["features"]) { feats = features["features"] } else { - feats = >features + feats = >features } if (Array.isArray(feats)) { @@ -34,23 +32,7 @@ export default class StaticFeatureSource implements FeatureSource { } } - public static fromGeojson(geojson: Feature[]): StaticFeatureSource { + public static fromGeojson(geojson: T[]): StaticFeatureSource { return new StaticFeatureSource(geojson) } } - -export class TiledStaticFeatureSource - extends StaticFeatureSource - implements Tiled, FeatureSourceForLayer -{ - public readonly bbox: BBox = BBox.global - public readonly tileIndex: number - public readonly layer: FilteredLayer - - constructor(features: Store, layer: FilteredLayer, tileIndex: number = 0) { - super(features) - this.tileIndex = tileIndex - this.layer = layer - this.bbox = BBox.fromTileIndex(this.tileIndex) - } -} diff --git a/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts b/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts index ac16be8e8..182187da8 100644 --- a/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts +++ b/Logic/FeatureSource/Sources/TouchesBboxFeatureSource.ts @@ -1,14 +1,15 @@ -import { FeatureSource, FeatureSourceForLayer } from "../FeatureSource" +import {FeatureSource, FeatureSourceForLayer} from "../FeatureSource" import StaticFeatureSource from "./StaticFeatureSource" -import { BBox } from "../../BBox" +import {BBox} from "../../BBox" import FilteredLayer from "../../../Models/FilteredLayer" -import { Store } from "../../UIEventSource" +import {Store} from "../../UIEventSource" +import {Feature} from "geojson"; /** * Results in a feature source which has all the elements that touch the given features */ -export default class BBoxFeatureSource extends StaticFeatureSource { - constructor(features: FeatureSource, mustTouch: Store) { +export default class BBoxFeatureSource extends StaticFeatureSource { + constructor(features: FeatureSource, mustTouch: Store) { super( features.features.mapD( (features) => { @@ -29,10 +30,10 @@ export default class BBoxFeatureSource extends StaticFeatureSource { } } -export class BBoxFeatureSourceForLayer extends BBoxFeatureSource implements FeatureSourceForLayer { +export class BBoxFeatureSourceForLayer extends BBoxFeatureSource implements FeatureSourceForLayer { readonly layer: FilteredLayer - constructor(features: FeatureSourceForLayer, mustTouch: Store) { + constructor(features: FeatureSourceForLayer, mustTouch: Store) { super(features, mustTouch) this.layer = features.layer }