Skip to content

Commit

Permalink
fix: WFS services with high number of features not loading
Browse files Browse the repository at this point in the history
Dont consider extent as loaded when feature request fails
  • Loading branch information
FilipLeitner committed Feb 13, 2024
1 parent 062c75c commit 15008cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
47 changes: 25 additions & 22 deletions projects/hslayers/src/common/layers/hs.source.WfsSource.ts
@@ -1,11 +1,10 @@
import {HttpClient} from '@angular/common/http';
import {lastValueFrom} from 'rxjs';

import {Geometry} from 'ol/geom';
import {ObjectEvent} from 'ol/Object';
import {Vector as VectorSource} from 'ol/source';
import {WFS} from 'ol/format';
import {bbox} from 'ol/loadingstrategy';
import {bbox, tile} from 'ol/loadingstrategy';
import {createXYZ} from 'ol/tilegrid';
import {transformExtent} from 'ol/proj';

import {HsUtilsService} from '../../components/utils/utils.service';
Expand All @@ -17,6 +16,7 @@ export type WfsOptions = {
provided_url?: string;
layer_name?: string;
map_projection?: any;
layerExtent?: any;
};

/**
Expand All @@ -33,6 +33,7 @@ export class WfsSource extends VectorSource {
provided_url,
layer_name,
map_projection,
layerExtent,
}: WfsOptions,
) {
super({
Expand Down Expand Up @@ -76,26 +77,28 @@ export class WfsSource extends VectorSource {
].join('?');
url = hsUtilsService.proxify(url);
this.dispatchEvent('featuresloadstart');
const response = await lastValueFrom(
http.get(url, {responseType: 'text'}),
);
if (response) {
const features = readFeatures(
response,
map_projection,
data_version,
responseFeatureCRS,
);
(this as VectorSource).addFeatures(features);
this.dispatchEvent(
new ObjectEvent('propertychange', 'loaded', false),
);
this.dispatchEvent('featuresloadend');
} else {
this.dispatchEvent('featuresloaderror');
}
http.get(url, {responseType: 'text'}).subscribe({
next: (response) => {
const features = readFeatures(
response,
map_projection,
data_version,
responseFeatureCRS,
);
(this as VectorSource).addFeatures(features);
this.dispatchEvent(
new ObjectEvent('propertychange', 'loaded', false),
);
this.dispatchEvent('featuresloadend');
},

error: (err: any) => {
this.dispatchEvent('featuresloaderror');
(this as VectorSource).removeLoadedExtent(extent);
},
});
},
strategy: bbox,
strategy: layerExtent ? tile(createXYZ({extent: layerExtent})) : bbox,
});
}
}
Expand Down
Expand Up @@ -482,7 +482,8 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel {
removable: true,
wfsUrl: url,
...options,
// extent: this.getLayerExtent(layer, options.crs),
extent: this.getLayerExtent(layer, options.crs),
cluster: layer.featureCount ? layer.featureCount > 5000 : true, //A lot of features or not set
},
source: new WfsSource(this.hsUtilsService, this.http, {
data_version: this.data.version,
Expand All @@ -491,6 +492,10 @@ export class HsUrlWfsService implements HsUrlTypeServiceModel {
provided_url: url,
layer_name: options.layerName,
map_projection: this.hsMapService.getMap().getView().getProjection(),
layerExtent:
layer.featureCount > 5000 || !layer.featureCount //A lot of features or not set
? this.getLayerExtent(layer, options.crs)
: undefined,
}),
renderOrder: null,
//Used to determine whether its URL WFS service when saving to compositions
Expand Down

0 comments on commit 15008cd

Please sign in to comment.