Skip to content

Commit

Permalink
Fixes TypeScript errors
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <daniel@georepublic.de>
  • Loading branch information
dkastl committed Dec 19, 2023
1 parent 094990b commit 3a01d26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/components/gtt-client/GttClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -24,8 +25,8 @@ export default class GttClient {
contents: DOMStringMap;
i18n: any;
filters: IFilterOption;
vector: VectorLayer<VectorSource<Geometry>>;
bounds: VectorLayer<VectorSource<Geometry>>;
vector: VectorLayer<VectorSource<Feature<Geometry>>>;
bounds: VectorLayer<VectorSource<Feature<Geometry>>>;
geolocations: Array<Geolocation>;

/**
Expand Down
27 changes: 20 additions & 7 deletions src/components/gtt-client/init/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ export function initLayers(this: any): Layer[] {
*/
function readGeoJSONFeatures(this: any): Feature<Geometry>[] | 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<Geometry>
return features.filter(feature => feature instanceof Feature) as Feature<Geometry>[];
}
return null;
}
Expand Down Expand Up @@ -171,15 +174,24 @@ function addBoundsLayer(this: any): void {
*/
function addVectorLayer(this: any, features: Feature<Geometry>[] | null): void {
const yOrdering: unknown = Ordering.yOrdering();
this.vector = new VectorLayer<VectorSource<Geometry>>({
source: new VectorSource({
'features': features,
'useSpatialIndex': false
}),

// Initialize the VectorSource with the appropriate type and options
const vectorSource = new VectorSource<Feature<Geometry>>({
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());
Expand Down Expand Up @@ -223,7 +235,8 @@ function renderProjectBoundary(this: any): void {
this.contents.bounds, {
featureProjection: 'EPSG:3857'
}
);
) as Feature<Geometry>;

this.bounds.getSource().addFeature(boundary);
if (this.contents.bounds === this.contents.geom) {
this.vector.setVisible(false);
Expand Down

0 comments on commit 3a01d26

Please sign in to comment.