Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGCFilters - applied projection and change field on typing #760

Merged
merged 5 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import olSourceVector from 'ol/source/Vector';
import * as OlLoadingStrategy from 'ol/loadingstrategy';
import olProjection from 'ol/proj/Projection';
import * as olproj from 'ol/proj';

import { DataSource } from './datasource';
import { WFSDataSourceOptions } from './wfs-datasource.interface';
Expand Down Expand Up @@ -45,26 +46,33 @@ export class WFSDataSource extends DataSource {
format: getFormatFromOptions(this.options),
loader: (extent, resolution, proj: olProjection) => {
vectorSource.dispatchEvent({ type: 'vectorloading' });
this.options.paramsWFS.srsName = this.options.paramsWFS.srsName || proj.getCode();
const url = this.buildUrl(
const paramsWFS = this.options.paramsWFS;
const wfsProj = paramsWFS.srsName ? new olProjection({ code: paramsWFS.srsName }) : proj;

const currentExtent = olproj.transformExtent(
extent,
proj,
wfsProj
);

paramsWFS.srsName = paramsWFS.srsName || proj.getCode();
const url = this.buildUrl(
currentExtent,
wfsProj,
(this.options as OgcFilterableDataSourceOptions).ogcFilters);
let startIndex = 0;
if (
this.options.paramsWFS.version === '2.0.0' &&
this.options.paramsWFS.maxFeatures > defaultMaxFeatures) {
if (paramsWFS.version === '2.0.0' && paramsWFS.maxFeatures > defaultMaxFeatures) {
const nbOfFeature = 1000;
while (startIndex < this.options.paramsWFS.maxFeatures) {
let alteredUrl = url.replace('count=' + this.options.paramsWFS.maxFeatures, 'count=' + nbOfFeature);
while (startIndex < paramsWFS.maxFeatures) {
let alteredUrl = url.replace('count=' + paramsWFS.maxFeatures, 'count=' + nbOfFeature);
alteredUrl = alteredUrl.replace('startIndex=0', '0');
alteredUrl += '&startIndex=' + startIndex;
alteredUrl.replace(/&&/g, '&');
this.getFeatures(vectorSource, extent, alteredUrl, nbOfFeature);
this.getFeatures(vectorSource, currentExtent, wfsProj, proj, alteredUrl, nbOfFeature);
startIndex += nbOfFeature;
}
} else {
this.getFeatures(vectorSource, extent, url, this.options.paramsWFS.maxFeatures);
this.getFeatures(vectorSource, currentExtent, wfsProj, proj, url, paramsWFS.maxFeatures);
}


Expand All @@ -77,7 +85,7 @@ export class WFSDataSource extends DataSource {
return vectorSource;
}

private getFeatures(vectorSource: olSourceVector, extent, url: string, threshold: number) {
private getFeatures(vectorSource: olSourceVector, extent, dataProjection, featureProjection, url: string, threshold: number) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
if (this.authInterceptor) {
Expand All @@ -89,8 +97,8 @@ export class WFSDataSource extends DataSource {
};
xhr.onerror = onError;
xhr.onload = () => {
if (xhr.status === 200) {
const features = vectorSource.getFormat().readFeatures(xhr.responseText);
if (xhr.status === 200 && xhr.responseText.length > 0) {
const features = vectorSource.getFormat().readFeatures(xhr.responseText, {dataProjection, featureProjection});
// TODO Manage "More feature"
/*if (features.length === 0 || features.length < threshold ) {
console.log('No more data to download at this resolution');
Expand Down
21 changes: 14 additions & 7 deletions packages/geo/src/lib/download/shared/download.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@angular/core';

import olProjection from 'ol/proj/Projection';
import * as olproj from 'ol/proj';

import { MessageService, LanguageService } from '@igo2/core';

Expand Down Expand Up @@ -34,15 +35,21 @@ export class DownloadService {
DSOptions.download.url === undefined
) {
let wfsOptions;
if (
(layer.dataSource.options as any).paramsWFS &&
Object.keys((layer.dataSource.options as any).paramsWFS).length > 0
let currentProj = new olProjection({ code: layer.map.projection });
const paramsWFS = (layer.dataSource.options as any).paramsWFS;
if (paramsWFS && Object.keys(paramsWFS).length > 0
) {
currentProj = paramsWFS.srsName ? new olProjection({ code: paramsWFS.srsName }) : currentProj;
wfsOptions = (layer.dataSource.options as any).paramsWFS;
} else {
wfsOptions = (layer.dataSource.options as any).params;
}

const currentExtent = olproj.transformExtent(
layer.map.viewController.getExtent(),
new olProjection({ code: layer.map.projection }),
currentProj
);
const outputFormatDownload =
wfsOptions.outputFormatDownload === undefined
? 'outputformat=' + wfsOptions.outputFormat
Expand All @@ -60,14 +67,14 @@ export class DownloadService {
.handleOgcFiltersAppliedValue(
layer.dataSource.options,
ogcFilters.geometryName,
layer.map.viewController.getExtent(),
new olProjection({ code: layer.map.projection }));
currentExtent,
currentProj);
if (!filterQueryString) {
// Prevent getting all the features for empty filter
filterQueryString = new OgcFilterWriter().buildFilter(
undefined,
layer.map.viewController.getExtent(),
new olProjection({ code: layer.map.projection }),
currentExtent,
currentProj,
ogcFilters.geometryName
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export class OgcFilterFormComponent implements OnInit {
updateFieldsList(value?: string) {
this.filteredFields$ =
value && value.length > 0 ? of(this._filterFields(value)) : this.fields$;
if (this.fields$.value.find((f) => f.name === value)) {
this.changeField(value);
}
}

updateValuesList(value?: string, pos?: number) {
Expand All @@ -143,7 +146,7 @@ export class OgcFilterFormComponent implements OnInit {
: this.selectedField$.value
? of(this.selectedField$.value.values)
: of([]);
if (value && value.length >= 2) {
if (value && value.length >= 1) {
this.changeProperty(value, pos);
}
}
Expand All @@ -169,7 +172,7 @@ export class OgcFilterFormComponent implements OnInit {
'gi'
);
return this.selectedField$.value.values.filter((val) =>
keywordRegex.test(
val && keywordRegex.test(
val
.toString()
.normalize('NFD')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
svgIcon="chevron-up">
</mat-icon>
<h4 (click)="toggleLegendOnClick()" *ngIf="header" [ngStyle]="{'cursor': filtersCollapsed ? 'default' : 'pointer'}" matLine [matTooltip]="layer.title" matTooltipShowDelay="500">{{layer.title}}</h4>

<span *ngIf="downloadable && header">
<button mat-icon-button tooltip-position="below" matTooltipShowDelay="500" [matTooltip]="'igo.geo.download.action' | translate"
[color]="color" (click)="openDownload()">
<mat-icon svgIcon="download"></mat-icon>
</button>
</span>
<button *ngIf="isAdvancedOgcFilters() && filtersAreEditable" [disabled]="addFilterDisabled()" mat-icon-button tooltip-position="below" matTooltipShowDelay="500"
[matTooltip]="'igo.geo.filter.addFilter' | translate" [color]="color" (click)="addFilterToSequence()">
<mat-icon svgIcon="plus"></mat-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';

import { Layer } from '../../layer/shared/layers/layer';
import { DownloadService } from '../../download/shared/download.service';
import { WMSDataSource } from '../../datasource/shared/datasources/wms-datasource';
import { WFSDataSourceOptionsParams } from '../../datasource/shared/datasources/wfs-datasource.interface';
import { OgcFilterOperator } from '../../filter/shared/ogc-filter.enum';
Expand Down Expand Up @@ -47,14 +46,7 @@ export class OgcFilterableItemComponent implements OnInit {
return this.layer.dataSource as OgcFilterableDataSource;
}

get downloadable() {
return (this.datasource.options as any).download;
}

constructor(
private ogcFilterService: OGCFilterService,
private downloadService: DownloadService
) {
constructor(private ogcFilterService: OGCFilterService) {
this.ogcFilterWriter = new OgcFilterWriter();
}

Expand Down Expand Up @@ -143,10 +135,6 @@ export class OgcFilterableItemComponent implements OnInit {
this.datasource.options.ogcFilters.interfaceOgcFilters = arr;
}

openDownload() {
this.downloadService.open(this.layer);
}

refreshFilters(force?: boolean) {
if (force === true) {
this.lastRunOgcFilter = undefined;
Expand Down