From 3a01d26fa564fce9448611316bae4a83b1ef3694 Mon Sep 17 00:00:00 2001 From: Daniel Kastl Date: Tue, 19 Dec 2023 16:58:54 +0900 Subject: [PATCH] Fixes TypeScript errors Signed-off-by: Daniel Kastl --- src/components/gtt-client/GttClient.ts | 5 +++-- src/components/gtt-client/init/layers.ts | 27 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/components/gtt-client/GttClient.ts b/src/components/gtt-client/GttClient.ts index 184ed5f5..0336589d 100644 --- a/src/components/gtt-client/GttClient.ts +++ b/src/components/gtt-client/GttClient.ts @@ -2,6 +2,7 @@ import { Map, Geolocation } from 'ol'; import { Geometry } from 'ol/geom'; import { Vector as VectorLayer } from 'ol/layer'; import { Vector as VectorSource } from 'ol/source'; +import Feature from 'ol/Feature'; import { IGttClientOption, IFilterOption } from './interfaces'; @@ -24,8 +25,8 @@ export default class GttClient { contents: DOMStringMap; i18n: any; filters: IFilterOption; - vector: VectorLayer>; - bounds: VectorLayer>; + vector: VectorLayer>>; + bounds: VectorLayer>>; geolocations: Array; /** diff --git a/src/components/gtt-client/init/layers.ts b/src/components/gtt-client/init/layers.ts index 842cae7c..7ff11eb0 100644 --- a/src/components/gtt-client/init/layers.ts +++ b/src/components/gtt-client/init/layers.ts @@ -50,11 +50,14 @@ export function initLayers(this: any): Layer[] { */ function readGeoJSONFeatures(this: any): Feature[] | null { if (this.contents.geom && this.contents.geom !== null && this.contents.geom !== 'null') { - return new GeoJSON().readFeatures( + const features = new GeoJSON().readFeatures( JSON.parse(this.contents.geom), { featureProjection: 'EPSG:3857' } ); + + // Filter out non-standard features and cast the rest to Feature + return features.filter(feature => feature instanceof Feature) as Feature[]; } return null; } @@ -171,15 +174,24 @@ function addBoundsLayer(this: any): void { */ function addVectorLayer(this: any, features: Feature[] | null): void { const yOrdering: unknown = Ordering.yOrdering(); - this.vector = new VectorLayer>({ - source: new VectorSource({ - 'features': features, - 'useSpatialIndex': false - }), + + // Initialize the VectorSource with the appropriate type and options + const vectorSource = new VectorSource>({ + useSpatialIndex: false + }); + + // Add features to the source if they are not null + if (features !== null) { + vectorSource.addFeatures(features); + } + + this.vector = new VectorLayer({ + source: vectorSource, renderOrder: yOrdering as OrderFunction, style: getStyle.bind(this), minZoom: this.defaults.vectorMinzoom || 0 }); + this.vector.set('title', 'Features'); this.vector.set('displayInLayerSwitcher', false); this.vector.on('prerender', () => this.map.flushDeclutterItems()); @@ -223,7 +235,8 @@ function renderProjectBoundary(this: any): void { this.contents.bounds, { featureProjection: 'EPSG:3857' } - ); + ) as Feature; + this.bounds.getSource().addFeature(boundary); if (this.contents.bounds === this.contents.geom) { this.vector.setVisible(false);