Skip to content

Commit

Permalink
fix(wfs-source): Provide injector to the non angular decoradted wfs c…
Browse files Browse the repository at this point in the history
…lass
  • Loading branch information
FilipLeitner authored and jmacura committed Oct 3, 2024
1 parent 9c86ba2 commit 25c53ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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({
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 5 additions & 1 deletion projects/hslayers/services/add-data/url/wfs.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -52,6 +52,8 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel {
private requestCancelSubjects: Map<string, Subject<void>> = new Map();
cancelUrlRequest: Subject<void> = new Subject();

injector = inject(Injector);

constructor(
private http: HttpClient,
public hsUtilsService: HsUtilsService,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 25c53ab

Please sign in to comment.