From 25c53ab7396b47ed7010efdec7cc1cef3cd979d7 Mon Sep 17 00:00:00 2001 From: Filip Leitner Date: Mon, 30 Sep 2024 12:18:57 +0200 Subject: [PATCH] fix(wfs-source): Provide injector to the non angular decoradted wfs class --- .../services/add-data/url/hs.source.WfsSource.ts | 9 ++++++--- projects/hslayers/services/add-data/url/wfs.service.ts | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/projects/hslayers/services/add-data/url/hs.source.WfsSource.ts b/projects/hslayers/services/add-data/url/hs.source.WfsSource.ts index 83b2ddba90..6c762aa58f 100644 --- a/projects/hslayers/services/add-data/url/hs.source.WfsSource.ts +++ b/projects/hslayers/services/add-data/url/hs.source.WfsSource.ts @@ -1,16 +1,17 @@ import {Extent} from 'ol/extent'; import {HsUtilsService} from 'hslayers-ng/services/utils'; import {HttpClient, HttpErrorResponse} from '@angular/common/http'; +import {Injector} from '@angular/core'; import {Projection, transformExtent} from 'ol/proj'; import {Vector as VectorSource} from 'ol/source'; import {and, within} from 'ol/format/filter'; import {bbox, tile} from 'ol/loadingstrategy'; import {createXYZ} from 'ol/tilegrid'; import {fromExtent} from 'ol/geom/Polygon'; -import {inject} from '@angular/core'; import {lastValueFrom} from 'rxjs'; export type WfsOptions = { + injector: Injector; data_version?: string; output_format?: string; crs?: string; @@ -25,8 +26,8 @@ export type WfsOptions = { * Provides a source of features from WFS endpoint */ export class WfsSource extends VectorSource { - private http = inject(HttpClient); - private hsUtilsService = inject(HsUtilsService); + private http: HttpClient; + private hsUtilsService: HsUtilsService; constructor(private options: WfsOptions) { super({ @@ -111,6 +112,8 @@ export class WfsSource extends VectorSource { ? tile(createXYZ({extent: options.layerExtent})) : bbox, }); + this.http = options.injector.get(HttpClient); + this.hsUtilsService = options.injector.get(HsUtilsService); } } diff --git a/projects/hslayers/services/add-data/url/wfs.service.ts b/projects/hslayers/services/add-data/url/wfs.service.ts index 10a3ca2194..58747c89ed 100644 --- a/projects/hslayers/services/add-data/url/wfs.service.ts +++ b/projects/hslayers/services/add-data/url/wfs.service.ts @@ -1,5 +1,5 @@ import {HttpClient} from '@angular/common/http'; -import {Injectable} from '@angular/core'; +import {Injectable, Injector, inject} from '@angular/core'; import {Subject, finalize, takeUntil} from 'rxjs'; import * as xml2Json from 'xml-js'; @@ -52,6 +52,8 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel { private requestCancelSubjects: Map> = new Map(); cancelUrlRequest: Subject = new Subject(); + injector = inject(Injector); + constructor( private http: HttpClient, public hsUtilsService: HsUtilsService, @@ -510,6 +512,7 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel { const layerExtent = manyFeatures ? this.getLayerExtent(layer, options.crs) : undefined; + const new_layer = new VectorLayer({ properties: { name: options.layerName, @@ -521,6 +524,7 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel { cluster: manyFeatures, }, source: new WfsSource({ + injector: this.injector, data_version: this.data.version, output_format: this.data.output_format, crs: options.crs,