From f668d781040d5faf1afff021246a2d86ea6b7ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-=C3=89tienne=20Lord?= <7397743+pelord@users.noreply.github.com> Date: Tue, 15 May 2018 14:47:11 -0400 Subject: [PATCH] feat(feature): Make features clickable (#149) * Ajustements into the lib to fit with the igo-api structure. * Make features clickable * Remove console.log(...) * Local for clicked features. * use arrow notation --- .../shared/datasources/wfs-datasource.ts | 9 +- .../shared/datasources/wms-datasource.ts | 13 +- src/lib/download/shared/download.service.ts | 59 ++++----- src/lib/feature/shared/feature.service.ts | 4 +- .../ogc-filter-form.component.html | 2 +- .../ogc-filterable-item.component.ts | 3 +- .../layer-item/layer-item.component.html | 2 +- src/lib/query/shared/query.directive.ts | 113 ++++++++++++++---- src/locale/en.json | 3 + src/locale/fr.json | 3 + 10 files changed, 145 insertions(+), 66 deletions(-) diff --git a/src/lib/datasource/shared/datasources/wfs-datasource.ts b/src/lib/datasource/shared/datasources/wfs-datasource.ts index 58b23a85da..9b8f56109f 100644 --- a/src/lib/datasource/shared/datasources/wfs-datasource.ts +++ b/src/lib/datasource/shared/datasources/wfs-datasource.ts @@ -2,9 +2,9 @@ import { HttpClient } from '@angular/common/http'; import * as ol from 'openlayers'; import { uuid } from '../../../utils'; -import { +import { IgoOgcFilterObject, OgcFilter, WFSWriteGetFeatureOptions, - AnyBaseOgcFilterOptions, OgcFilterWriter + AnyBaseOgcFilterOptions, OgcFilterWriter } from '../../../filter/shared'; import { DataSource } from './datasource'; @@ -32,12 +32,13 @@ export class WFSDataSource extends DataSource implements OgcFilterableDataSource this.ogcFilterWriter = new OgcFilterWriter; this.dataSourceService.checkWfsOptions(options); - if (options['sourceFields'] === undefined) { + if (options['sourceFields'] === undefined || + Object.keys(options['sourceFields']).length === 0) { options['sourceFields'] = [] this.dataSourceService.wfsGetCapabilities(options) .map(wfsCapabilities => options['wfsCapabilities'] = { 'xml': wfsCapabilities.body, - 'GetPropertyValue': /GetPropertyValue/gi.test(wfsCapabilities.body) ? true : false + 'GetPropertyValue': /GetPropertyValue/gi.test(wfsCapabilities.body) ? true : false }) .subscribe(val => options['sourceFields'] = this.dataSourceService.defineFieldAndValuefromWFS(options)); diff --git a/src/lib/datasource/shared/datasources/wms-datasource.ts b/src/lib/datasource/shared/datasources/wms-datasource.ts index 09536e3091..62b6ccea00 100644 --- a/src/lib/datasource/shared/datasources/wms-datasource.ts +++ b/src/lib/datasource/shared/datasources/wms-datasource.ts @@ -4,9 +4,9 @@ import { Md5 } from 'ts-md5/dist/md5'; import { QueryFormat, QueryOptions } from '../../../query'; import { DataSource } from './datasource'; -import { +import { DataSourceLegendOptions, TimeFilterableDataSource, - QueryableDataSource, OgcFilterableDataSource + QueryableDataSource, OgcFilterableDataSource } from './datasource.interface'; import { WMSDataSourceOptions } from './wms-datasource.interface'; import { OgcFilterWriter, IgoOgcFilterObject, OgcFiltersOptions } from '../../../filter/shared'; @@ -55,11 +55,12 @@ export class WMSDataSource extends DataSource implements sourceParams.VERSION = sourceParams.version; } - if (options['sourceFields'] === undefined) { + if (options['sourceFields'] === undefined || + Object.keys(options['sourceFields']).length === 0) { options['sourceFields'] = [{ 'name': '', 'alias': '' }] } // WMS With linked wfs - if (options.wfsSource) { + if (options.wfsSource && Object.keys(options.wfsSource).length > 0) { options.wfsSource = this.dataSourceService.checkWfsOptions(options.wfsSource); delete options.wfsSource.ogcFilters; options['fieldNameGeometry'] = options.wfsSource['fieldNameGeometry']; @@ -68,7 +69,7 @@ export class WMSDataSource extends DataSource implements this.dataSourceService.wfsGetCapabilities(options) .map(wfsCapabilities => options.wfsSource['wfsCapabilities'] = { 'xml': wfsCapabilities.body, - 'GetPropertyValue': /GetPropertyValue/gi.test(wfsCapabilities.body) ? true : false + 'GetPropertyValue': /GetPropertyValue/gi.test(wfsCapabilities.body) ? true : false }) .subscribe(val => options['sourceFields'] = this.dataSourceService.defineFieldAndValuefromWFS(options.wfsSource)); @@ -94,7 +95,7 @@ export class WMSDataSource extends DataSource implements 'srsname=' + options.wfsSource.srsname : 'srsname=EPSG:3857'; const baseWfsQuery = this.dataSourceService.buildBaseWfsUrl(options.wfsSource, 'GetFeature'); this.options.download = Object.assign({}, this.options.download, { - 'dynamicUrl': `${baseWfsQuery}&${outputFormat}&${srsname}&${maxFeatures}` + 'dynamicUrl': `${baseWfsQuery}&${outputFormat}&${srsname}&${maxFeatures}` }); } diff --git a/src/lib/download/shared/download.service.ts b/src/lib/download/shared/download.service.ts index bd8a1732d9..ff82c90bc3 100644 --- a/src/lib/download/shared/download.service.ts +++ b/src/lib/download/shared/download.service.ts @@ -20,35 +20,36 @@ export class DownloadService { const translate = this.languageService.translate; const title = translate.instant('igo.download.title'); this.messageService.success(translate.instant('igo.download.start'), title); - - if ( - layer.dataSource.options.download['dynamicUrl'] && - layer.dataSource.options.download.url === undefined) { - let wfsOptions; - if (layer.dataSource.options['wfsSource']) { - wfsOptions = layer.dataSource.options['wfsSource']; - } else { - wfsOptions = layer.dataSource.options; - } - - const outputFormatDownload = - wfsOptions['outputFormatDownload'] === undefined ? - 'outputformat=' + wfsOptions['outputFormat'] : - 'outputformat=' + wfsOptions['outputFormatDownload']; - - const baseurl = layer.dataSource.options.download['dynamicUrl'] - .replace(/&?outputformat=[^&]*/gi, '') - .replace(/&?filter=[^&]*/gi, '') - .replace(/&?bbox=[^&]*/gi, ''); - - const rebuildFilter = this.ogcFilterWriter.buildFilter( - layer.dataSource.options['ogcFilters']['filters'], - layer.map.getExtent(), - new ol.proj.Projection({ code: layer.map.projection }), - wfsOptions['fieldNameGeometry']); - window.open(`${baseurl}&${rebuildFilter}&${outputFormatDownload}`, '_blank'); - } else if (layer.dataSource.options.download) { - window.open(layer.dataSource.options.download.url, '_blank'); + if (Object.keys(layer.dataSource.options.download).length > 0 ) { + if ( + layer.dataSource.options.download['dynamicUrl'] && + layer.dataSource.options.download.url === undefined) { + let wfsOptions; + if (Object.keys(layer.dataSource.options['wfsSource']).length > 0) { + wfsOptions = layer.dataSource.options['wfsSource']; + } else { + wfsOptions = layer.dataSource.options; + } + + const outputFormatDownload = + wfsOptions['outputFormatDownload'] === undefined ? + 'outputformat=' + wfsOptions['outputFormat'] : + 'outputformat=' + wfsOptions['outputFormatDownload']; + + const baseurl = layer.dataSource.options.download['dynamicUrl'] + .replace(/&?outputformat=[^&]*/gi, '') + .replace(/&?filter=[^&]*/gi, '') + .replace(/&?bbox=[^&]*/gi, ''); + + const rebuildFilter = this.ogcFilterWriter.buildFilter( + layer.dataSource.options['ogcFilters']['filters'], + layer.map.getExtent(), + new ol.proj.Projection({ code: layer.map.projection }), + wfsOptions['fieldNameGeometry']); + window.open(`${baseurl}&${rebuildFilter}&${outputFormatDownload}`, '_blank'); + } else if (layer.dataSource.options.download) { + window.open(layer.dataSource.options.download.url, '_blank'); } } + } } diff --git a/src/lib/feature/shared/feature.service.ts b/src/lib/feature/shared/feature.service.ts index 160d4e1e41..a542293a29 100644 --- a/src/lib/feature/shared/feature.service.ts +++ b/src/lib/feature/shared/feature.service.ts @@ -59,7 +59,9 @@ export class FeatureService { featuresAreTheSame(feature1, feature2) { if (feature1 === undefined || feature2 === undefined) { return false; } - return feature1.id === feature2.id && feature1.source === feature2.source; + return feature1.id === feature2.id + && feature1.source === feature2.source + && feature1.properties === feature2.properties; } private sortFeatures(feature1, feature2) { diff --git a/src/lib/filter/ogc-filter-form/ogc-filter-form.component.html b/src/lib/filter/ogc-filter-form/ogc-filter-form.component.html index 603d46335a..a5a5f1de64 100644 --- a/src/lib/filter/ogc-filter-form/ogc-filter-form.component.html +++ b/src/lib/filter/ogc-filter-form/ogc-filter-form.component.html @@ -175,7 +175,7 @@
-