From d79eb9d8b29ef777faa2e16447e915cd3f5a20bb Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Tue, 24 Nov 2020 16:16:44 -0500 Subject: [PATCH 1/7] WIP --- .../spatial-filter.component.ts | 3 +- .../filter/shared/spatial-filter.service.ts | 51 ++++++++--- .../spatial-filter-item.component.html | 4 +- .../spatial-filter-item.component.ts | 22 +++-- .../spatial-filter-list.component.html | 4 +- .../spatial-filter-list.component.ts | 85 +++++-------------- .../spatial-filter-tool.component.ts | 5 +- 7 files changed, 85 insertions(+), 89 deletions(-) diff --git a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts index d556d8227b..51db3a070a 100644 --- a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts +++ b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts @@ -146,8 +146,7 @@ export class AppSpatialFilterComponent { this.zone, this.itemType, this.queryType, - thematic, - this.radius + thematic ) .subscribe((features: Feature[]) => { this.store.insertMany(features); diff --git a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts index c46dbeac6c..43bcd9681d 100644 --- a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts +++ b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts @@ -7,7 +7,8 @@ import { Observable } from 'rxjs'; import { Feature } from '../../feature/shared'; import { SpatialFilterQueryType, - SpatialFilterItemType + SpatialFilterItemType, + SpatialFilterType } from './spatial-filter.enum'; import { SpatialFilterThematic } from './spatial-filter.interface'; @@ -15,7 +16,7 @@ import { SpatialFilterThematic } from './spatial-filter.interface'; providedIn: 'root' }) export class SpatialFilterService { - public baseUrl: string = 'https://geoegl.msp.gouv.qc.ca/apis/terrapi/'; + public baseUrl: string = 'https://testgeoegl.msp.gouv.qc.ca/apis/terrapi/'; /* * Type association with URL @@ -140,8 +141,7 @@ export class SpatialFilterService { feature, itemType: SpatialFilterItemType, type?: SpatialFilterQueryType, - thematic?: SpatialFilterThematic, - buffer?: number + thematic?: SpatialFilterThematic ) { if (type) { // Predefined type @@ -156,8 +156,7 @@ export class SpatialFilterService { { params: { geometry: 'true', - icon: 'true', - buffer: buffer.toString() + icon: 'true' } } ) @@ -184,8 +183,7 @@ export class SpatialFilterService { { params: { geometry: 'true', - icon: 'true', - buffer: buffer.toString() + icon: 'true' } } ) @@ -211,7 +209,6 @@ export class SpatialFilterService { .post<{ features: Feature[] }>(url + urlItem, { geometry: 'true', icon: 'true', - buffer, loc: JSON.stringify(feature) }) .pipe( @@ -235,7 +232,6 @@ export class SpatialFilterService { .post<{ features: Feature[] }>(url + urlItem, { geometry: 'true', icon: 'true', - buffer, loc: JSON.stringify(feature) }) .pipe( @@ -282,4 +278,39 @@ export class SpatialFilterService { ); } } + + /* + * Get buffer geometry + */ + loadBufferGeometry( + feature: Feature, + filterType: SpatialFilterType, + buffer?: number, + type?: SpatialFilterQueryType, + ): Observable { + if (filterType === SpatialFilterType.Predefined) { + const featureType = this.urlFilterList[type]; + const featureCode = '/' + feature.properties.code; + if (featureType && featureCode) { + return this.http + .get(this.baseUrl + featureType + featureCode + '?geometry=1&buffer=' + buffer) + .pipe( + map(f => { + f.meta = { + id: f.properties.code, + alias: f.properties.nom, + title: f.properties.nom + }; + return f; + }) + ); + } + } else { + return this.http + .post(this.baseUrl + 'geospatial/buffer?loc=' + JSON.stringify(feature) + '&buffer=' + buffer, { + buffer, + loc: JSON.stringify(feature) + }); + } + } } diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html index 82d52eb296..a8ea712c38 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html @@ -26,7 +26,7 @@ - +
diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index e5409455b1..ae1167d8d7 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -29,9 +29,7 @@ import { Layer } from '../../../layer/shared'; import { NestedTreeControl } from '@angular/cdk/tree'; import { SpatialFilterThematic } from './../../shared/spatial-filter.interface'; import { MessageService, LanguageService } from '@igo2/core'; -import buffer from '@turf/buffer'; -import * as turf from '@turf/helpers'; -import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; +import { debounceTime } from 'rxjs/operators'; /** * Spatial-Filter-Item (search parameters) @@ -296,13 +294,25 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { if (this.measureUnit === MeasureLengthUnit.Meters && value > 0 && value <= 100000) { this.buffer = value; this.bufferEvent.emit(value); - this.zoneWithBuffer = buffer(turf.polygon(this.drawZone.coordinates), this.bufferFormControl.value / 1000, {units: 'kilometers'}); - this.zoneWithBufferChange.emit(this.zoneWithBuffer); + this.spatialFilterService.loadBufferGeometry( + this.drawZone, + SpatialFilterType.Polygon, + value + ).subscribe((featureGeom: Feature) => { + this.zoneWithBuffer = featureGeom; + this.zoneWithBufferChange.emit(this.zoneWithBuffer); + }); } else if (this.measureUnit === MeasureLengthUnit.Kilometers && value > 0 && value <= 100) { this.buffer = value; this.bufferEvent.emit(value); - this.zoneWithBuffer = buffer(turf.polygon(this.drawZone.coordinates), this.bufferFormControl.value, {units: 'kilometers'}); + this.spatialFilterService.loadBufferGeometry( + this.drawZone, + SpatialFilterType.Polygon, + value * 1000 + ).subscribe((featureGeom: Feature) => { + this.zoneWithBuffer = featureGeom; this.zoneWithBufferChange.emit(this.zoneWithBuffer); + }); } else if (value === 0) { this.buffer = value; this.bufferEvent.emit(value); diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.html b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.html index 27080f45b7..fcd6e76b6c 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.html +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.html @@ -11,7 +11,7 @@ - +
diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts index 721f82584b..0dd29d592f 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts @@ -1,7 +1,7 @@ import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { EntityStore } from '@igo2/common'; import { SpatialFilterService } from './../../shared/spatial-filter.service'; -import { SpatialFilterQueryType } from './../../shared/spatial-filter.enum'; +import { SpatialFilterQueryType, SpatialFilterType } from './../../shared/spatial-filter.enum'; import { Component, Input, @@ -16,23 +16,7 @@ import { FormControl } from '@angular/forms'; import { Feature } from '../../../feature'; import { MeasureLengthUnit } from '../../../measure/shared'; import { LanguageService, MessageService } from '@igo2/core'; -// import buffer from '@turf/buffer'; -// import * as TurfProj from '@turf/projection'; import { Layer } from '../../../layer'; -import { - LineString, - MultiLineString, - MultiPoint, - MultiPolygon, - Point, - Polygon, -} from 'ol/geom'; -import LinearRing from 'ol/geom/LinearRing'; -import GeoJSON from 'ol/format/GeoJSON'; -// import GeoJSONReader from 'jsts/org/locationtech/jts/io/GeoJSONReader'; -// import GeoJSONWriter from 'jsts/org/locationtech/jts/io/GeoJSONWriter'; -// import { BufferOp } from 'jsts/org/locationtech/jts/operation/buffer'; -// import Parser from 'jsts/org/locationtech/jts/io/OL3Parser'; @Component({ selector: 'igo-spatial-filter-list', @@ -85,9 +69,6 @@ export class SpatialFilterListComponent implements OnInit, OnDestroy { public bufferFormControl = new FormControl(); - // private reader = new GeoJSONReader(); - // private writer = new GeoJSONWriter(); - /** * Available measure units for the measure type given * @internal @@ -127,51 +108,27 @@ export class SpatialFilterListComponent implements OnInit, OnDestroy { ) .subscribe((value) => { if (this.measureUnit === MeasureLengthUnit.Meters && value > 0 && value <= 100000) { - // this.bufferChange.emit(value); - // // const bufferFeature = {...this.selectedZone}; - // const format = new GeoJSON(); - // const bufferFeature = format.readFeature(this.selectedZone, { - // featureProjection: 'EPSG:4326', - // }); - // const parser = new Parser(); - // parser.inject( - // Point, - // LineString, - // LinearRing, - // Polygon, - // MultiPoint, - // MultiLineString, - // MultiPolygon - // ); - // - // // let bufferFeature = TurfProj.toMercator(this.selectedZone); - // // console.log(bufferFeature); - // // let jstsGeom = this.reader.read(bufferFeature.geometry); - // // console.log(jstsGeom); - // // console.log(bufferFeature); - // // for (let coordinate of bufferFeature.geometry.coordinates[0][0]) { - // // coordinate = olproj.transform(coordinate, 'EPSG:4326', 'EPSG:3857'); - // // } - // // bufferFeature.geometry = OlPolygon.transform('EPSG:4326', 'EPSG:3857'); - // // bufferFeature = jstsGeom.buffer(this.bufferFormControl.value / 1000); - // // for (let coordinate of this.zoneWithBuffer.geometry.coordinates[0][0]) { - // // coordinate = olproj.transform(coordinate, 'EPSG:3857', 'EPSG:4326'); - // // } - // - // // convert the OpenLayers geometry to a JSTS geometry - // const jstsGeom = parser.read(bufferFeature.geometry); - // // create a buffer of 40 meters around each line - // const buffered = jstsGeom.buffer(this.bufferFormControl.value); - // - // this.zoneWithBuffer = {...this.selectedZone}; - // this.zoneWithBuffer.geometry = parser.write(buffered); - // // this.zoneWithBuffer.geometry = this.writer.write(bufferFeature); - // // this.zoneWithBuffer = TurfProj.toWgs84(this.zoneWithBuffer); - // this.zoneWithBufferChange.emit(this.zoneWithBuffer); - // } else if (this.measureUnit === MeasureLengthUnit.Kilometers && value > 0 && value <= 100) { - // this.bufferChange.emit(value); - // this.zoneWithBuffer = buffer(this.selectedZone, this.bufferFormControl.value, {units: 'kilometers'}); + this.bufferChange.emit(value); + this.spatialFilterService.loadBufferGeometry( + this.selectedZone, + SpatialFilterType.Predefined, + value, + this.queryType + ).subscribe((featureGeom: Feature) => { + this.zoneWithBuffer = featureGeom; + this.zoneWithBufferChange.emit(this.zoneWithBuffer); + }); + } else if (this.measureUnit === MeasureLengthUnit.Kilometers && value > 0 && value <= 100) { + this.bufferChange.emit(value); + this.spatialFilterService.loadBufferGeometry( + this.selectedZone, + SpatialFilterType.Predefined, + value * 1000, + this.queryType + ).subscribe((featureGeom: Feature) => { + this.zoneWithBuffer = featureGeom; this.zoneWithBufferChange.emit(this.zoneWithBuffer); + }); } else if (value === 0 && this.layers.length > 0) { this.bufferChange.emit(value); this.zoneWithBufferChange.emit(this.selectedZone); diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index e504b6adda..f7b43da288 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -191,7 +191,7 @@ export class SpatialFilterToolComponent implements OnDestroy { this.activeLayers = []; this.thematicLength = 0; this.iterator = 1; - if (this.type !== SpatialFilterType.Predefined) { + if (this.type === SpatialFilterType.Predefined) { this.zone = undefined; this.queryType = undefined; } @@ -222,8 +222,7 @@ export class SpatialFilterToolComponent implements OnDestroy { this.zone, this.itemType, this.queryType, - thematic, - this.buffer + thematic ) .pipe( tap((features: Feature[]) => { From 3716c1020c1f2cd86aa70a19a288d689b6c6773a Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Wed, 25 Nov 2020 07:58:07 -0500 Subject: [PATCH 2/7] lint --- .../spatial-filter-item/spatial-filter-item.component.ts | 2 +- .../spatial-filter-list/spatial-filter-list.component.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index ae1167d8d7..77c371b4df 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -311,7 +311,7 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { value * 1000 ).subscribe((featureGeom: Feature) => { this.zoneWithBuffer = featureGeom; - this.zoneWithBufferChange.emit(this.zoneWithBuffer); + this.zoneWithBufferChange.emit(this.zoneWithBuffer); }); } else if (value === 0) { this.buffer = value; diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts index 0dd29d592f..0c2cfd5fcf 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts @@ -127,7 +127,7 @@ export class SpatialFilterListComponent implements OnInit, OnDestroy { this.queryType ).subscribe((featureGeom: Feature) => { this.zoneWithBuffer = featureGeom; - this.zoneWithBufferChange.emit(this.zoneWithBuffer); + this.zoneWithBufferChange.emit(this.zoneWithBuffer); }); } else if (value === 0 && this.layers.length > 0) { this.bufferChange.emit(value); From 16ed228616c4264b44f06e62fd5939cecc9f2562 Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Wed, 25 Nov 2020 16:34:13 -0500 Subject: [PATCH 3/7] WIP --- .../filter/shared/spatial-filter.service.ts | 9 ++++-- .../spatial-filter-item.component.ts | 30 +++++++++++++------ packages/geo/src/locale/en.geo.json | 1 + packages/geo/src/locale/fr.geo.json | 1 + .../spatial-filter-tool.component.ts | 29 ++++++++++++++---- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts index 43bcd9681d..3ee9fbd0d9 100644 --- a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts +++ b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts @@ -307,10 +307,15 @@ export class SpatialFilterService { } } else { return this.http - .post(this.baseUrl + 'geospatial/buffer?loc=' + JSON.stringify(feature) + '&buffer=' + buffer, { + .post(this.baseUrl + 'geospatial/buffer?', { buffer, loc: JSON.stringify(feature) - }); + }) + .pipe( + map(f => { + return f; + }) + ); } } } diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index 77c371b4df..814bf265e9 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -545,15 +545,27 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { */ toggleSearchButton() { if (!this.isPredefined()) { - this.drawZone.meta = { - id: undefined, - title: 'Zone' - }; - this.drawZone.properties = { - nom: 'Zone', - type: this.type as string - }; - this.drawZoneEvent.emit(this.drawZone); + if (this.buffer > 0) { + this.zoneWithBuffer.meta = { + id: undefined, + title: 'Zone' + }; + this.zoneWithBuffer.properties = { + nom: 'Zone', + type: this.type as string + }; + this.drawZoneEvent.emit(this.zoneWithBuffer); + } else { + this.drawZone.meta = { + id: undefined, + title: 'Zone' + }; + this.drawZone.properties = { + nom: 'Zone', + type: this.type as string + }; + this.drawZoneEvent.emit(this.drawZone); + } } if (this.isPoint()) { this.radiusEvent.emit(this.radius); diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index 88c0293747..fd0b2d42fd 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -424,6 +424,7 @@ "minute": "Minute" }, "spatialFilter": { + "spatialFilter": "Spatial filter", "predefined": "Predefined Zone", "draw": "Draw", "polygon": "Polygon", diff --git a/packages/geo/src/locale/fr.geo.json b/packages/geo/src/locale/fr.geo.json index 739a2007ef..4e62caeacd 100644 --- a/packages/geo/src/locale/fr.geo.json +++ b/packages/geo/src/locale/fr.geo.json @@ -423,6 +423,7 @@ "minute": "Minute" }, "spatialFilter": { + "spatialFilter": "Filtre spatial", "predefined": "Zone Prédéfinie", "draw": "Dessin", "polygon": "Polygone", diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index f7b43da288..b50fd04c48 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy } from '@angular/core'; +import { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy, OnInit } from '@angular/core'; import { MatIconRegistry } from '@angular/material/icon'; import { Observable, forkJoin, Subject } from 'rxjs'; import { tap, take, takeUntil } from 'rxjs/operators'; @@ -51,7 +51,7 @@ import { WorkspaceState } from '../../workspace/workspace.state'; styleUrls: ['./spatial-filter-tool.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush }) -export class SpatialFilterToolComponent implements OnDestroy { +export class SpatialFilterToolComponent implements OnInit, OnDestroy { get map(): IgoMap { return this.mapState.map; } @@ -102,6 +102,15 @@ export class SpatialFilterToolComponent implements OnDestroy { private cdRef: ChangeDetectorRef ) {} + ngOnInit() { + for (const layer of this.map.layers) { + if (layer.title.includes(this.languageService.translate.instant('igo.geo.spatialFilter.spatialFilter'))) { + this.layers.push(layer); + } + } + console.log(this.layers); + } + ngOnDestroy() { this.unsubscribe$.next(); this.unsubscribe$.complete(); @@ -201,7 +210,9 @@ export class SpatialFilterToolComponent implements OnDestroy { this.loading = true; let zeroResults = true; let thematics; - this.tryAddFeaturesToMap([this.zone]); + if (this.buffer === 0) { + this.tryAddFeaturesToMap([this.zone]); + } if (this.itemType !== SpatialFilterItemType.Thematics) { const theme: SpatialFilterThematic = { name: '' @@ -343,7 +354,9 @@ export class SpatialFilterToolComponent implements OnDestroy { .pipe(take(1)) .subscribe((dataSource: DataSource) => { const olLayer = this.layerService.createLayer({ - title: ('Zone ' + i) as string, + title: ('Zone ' + i + ' - ' + this.languageService.translate.instant( + 'igo.geo.spatialFilter.spatialFilter' + )) as string, workspace: { enabled: true }, _internal: { code: @@ -433,7 +446,9 @@ export class SpatialFilterToolComponent implements OnDestroy { } const olLayer = this.layerService.createLayer({ - title: (features[0].meta.title + ' ' + i) as string, + title: (features[0].meta.title + ' ' + i + ' - ' + this.languageService.translate.instant( + 'igo.geo.spatialFilter.spatialFilter' + )) as string, source: dataSource, visible: true, style @@ -513,7 +528,9 @@ export class SpatialFilterToolComponent implements OnDestroy { this.map.layers.find(layer => layer.id === olLayer.id) ); i = i - 1; - olLayer.title = (features[0].meta.title + ' ' + i) as string; + olLayer.title = (features[0].meta.title + ' ' + i + ' - ' + this.languageService.translate.instant( + 'igo.geo.spatialFilter.spatialFilter' + )) as string; olLayer.options.title = olLayer.title; } this.map.addLayer(olLayer); From a7a2894f0e00865bdfce4494c3a9f8d338f27500 Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Thu, 26 Nov 2020 16:28:54 -0500 Subject: [PATCH 4/7] WIP --- .../filter/shared/spatial-filter.service.ts | 20 ++++++++++--- .../spatial-filter-item.component.html | 2 +- .../spatial-filter-item.component.ts | 2 ++ .../spatial-filter-list.component.ts | 1 - .../spatial-filter-tool.component.html | 1 + .../spatial-filter-tool.component.ts | 30 +++++++++++-------- 6 files changed, 37 insertions(+), 19 deletions(-) diff --git a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts index 3ee9fbd0d9..4cb75e1696 100644 --- a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts +++ b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts @@ -141,7 +141,8 @@ export class SpatialFilterService { feature, itemType: SpatialFilterItemType, type?: SpatialFilterQueryType, - thematic?: SpatialFilterThematic + thematic?: SpatialFilterThematic, + buffer?: number ) { if (type) { // Predefined type @@ -156,7 +157,9 @@ export class SpatialFilterService { { params: { geometry: 'true', - icon: 'true' + icon: 'true', + bufferInput: buffer.toString(), + simplified: '0' } } ) @@ -183,7 +186,9 @@ export class SpatialFilterService { { params: { geometry: 'true', - icon: 'true' + icon: 'true', + buffer: buffer.toString(), + simplified: '0' } } ) @@ -293,7 +298,14 @@ export class SpatialFilterService { const featureCode = '/' + feature.properties.code; if (featureType && featureCode) { return this.http - .get(this.baseUrl + featureType + featureCode + '?geometry=1&buffer=' + buffer) + .get(this.baseUrl + featureType + featureCode, + { + params: { + geometry: 'true', + bufferOutput: buffer.toString() + } + } + ) .pipe( map(f => { f.meta = { diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html index a8ea712c38..8abf223b4d 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.html @@ -147,7 +147,7 @@ {{'igo.geo.spatialFilter.goSearch' | translate}} - diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index 814bf265e9..a3903ef9bb 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -133,6 +133,8 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { @Input() layers: Layer[] = []; + @Input() allLayers: Layer[] = []; + @Input() get thematicLength(): number { return this._thematicLength; diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts index 0c2cfd5fcf..f6f66438e8 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-list/spatial-filter-list.component.ts @@ -152,7 +152,6 @@ export class SpatialFilterListComponent implements OnInit, OnDestroy { } onZoneChange(feature) { - this.bufferFormControl.setValue(0); if (feature && this.queryType) { this.spatialFilterService.loadItemById(feature, this.queryType) .subscribe((featureGeom: Feature) => { diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.html b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.html index 2fc23822e3..b26908ed1e 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.html +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.html @@ -20,6 +20,7 @@ [loading]="loading" [store]="store" [layers]="activeLayers" + [allLayers]="layers" [thematicLength]="thematicLength" (radiusEvent)="buffer = $event" (bufferEvent)="buffer = $event" diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index b50fd04c48..a7fba278a3 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -104,11 +104,10 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { ngOnInit() { for (const layer of this.map.layers) { - if (layer.title.includes(this.languageService.translate.instant('igo.geo.spatialFilter.spatialFilter'))) { + if (layer.title && layer.title.includes(this.languageService.translate.instant('igo.geo.spatialFilter.spatialFilter'))) { this.layers.push(layer); } } - console.log(this.layers); } ngOnDestroy() { @@ -233,7 +232,8 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { this.zone, this.itemType, this.queryType, - thematic + thematic, + this.buffer ) .pipe( tap((features: Feature[]) => { @@ -264,7 +264,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { } if (features.length >= 10000) { - this.messageService.alert( + this.messageService.error( this.languageService.translate.instant( 'igo.geo.spatialFilter.maxSizeAlert' ), @@ -310,7 +310,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { let i = 1; for (const feature of features) { if (this.type === SpatialFilterType.Predefined) { - for (const layer of this.map.layers) { + for (const layer of this.layers) { if ( layer.options._internal && layer.options._internal.code === feature.properties.code && @@ -411,7 +411,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { } /** - * Try to point features to the map + * Try to add point features to the map * Necessary to create clusters */ private tryAddPointToMap(features: Feature[], id) { @@ -458,12 +458,14 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { return featureToOl(feature, this.map.projection); }); dataSource.ol.source.addFeatures(featuresOl); - if (this.map.layers.find(layer => layer.id === olLayer.id)) { + if (this.layers.find(layer => layer.id === olLayer.id)) { this.map.removeLayer( - this.map.layers.find(layer => layer.id === olLayer.id) + this.layers.find(layer => layer.id === olLayer.id) ); i = i - 1; - olLayer.title = (features[0].meta.title + ' ' + i) as string; + olLayer.title = (features[0].meta.title + ' ' + i + ' - ' + this.languageService.translate.instant( + 'igo.geo.spatialFilter.spatialFilter' + )) as string; olLayer.options.title = olLayer.title; } this.iterator = i; @@ -501,7 +503,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { if (this.map === undefined) { return; } - for (const layer of this.map.layers) { + for (const layer of this.layers) { if (layer.title?.startsWith(features[0].meta.title)) { i++; } @@ -515,7 +517,9 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { .pipe(take(1)) .subscribe((dataSource: DataSource) => { const olLayer = this.layerService.createLayer({ - title: (features[0].meta.title + ' ' + i) as string, + title: (features[0].meta.title + ' ' + i + ' - ' + this.languageService.translate.instant( + 'igo.geo.spatialFilter.spatialFilter' + )) as string, source: dataSource, visible: true }); @@ -523,9 +527,9 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { return featureToOl(feature, this.map.projection); }); dataSource.ol.addFeatures(featuresOl); - if (this.map.layers.find(layer => layer.id === olLayer.id)) { + if (this.layers.find(layer => layer.id === olLayer.id)) { this.map.removeLayer( - this.map.layers.find(layer => layer.id === olLayer.id) + this.layers.find(layer => layer.id === olLayer.id) ); i = i - 1; olLayer.title = (features[0].meta.title + ' ' + i + ' - ' + this.languageService.translate.instant( From ba6243f3efa1c381e2bda1a4b4b427aa7713d732 Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Fri, 27 Nov 2020 15:20:44 -0500 Subject: [PATCH 5/7] WIP --- .../filter/shared/spatial-filter.service.ts | 6 +- .../spatial-filter-item.component.scss | 59 ++++++++++++++++--- .../spatial-filter-item.component.ts | 1 + packages/geo/src/locale/en.geo.json | 2 +- packages/geo/src/locale/fr.geo.json | 2 +- .../spatial-filter-tool.component.ts | 6 +- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts index 4cb75e1696..1dab52b765 100644 --- a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts +++ b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts @@ -159,7 +159,7 @@ export class SpatialFilterService { geometry: 'true', icon: 'true', bufferInput: buffer.toString(), - simplified: '0' + simplified: '100' } } ) @@ -188,7 +188,7 @@ export class SpatialFilterService { geometry: 'true', icon: 'true', buffer: buffer.toString(), - simplified: '0' + simplified: '100' } } ) @@ -301,7 +301,7 @@ export class SpatialFilterService { .get(this.baseUrl + featureType + featureCode, { params: { - geometry: 'true', + geometry: '100', bufferOutput: buffer.toString() } } diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss index 24b10b8ecb..183ac2b1b4 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss @@ -1,3 +1,5 @@ +@import '../../../../../../core/src/style/partial/media'; + .header { margin-top: 5px; width: 100%; @@ -44,23 +46,66 @@ } .search-button { - left: 25px; - width: 150px; + left: 10px; + width: 165px; + + @include mobile { + width: 45%; + min-height: 35px; + white-space: normal; + line-height: normal; + } +} + +.export-button { + left: 10px; + width: 165px; + + @include mobile { + margin-top: 10px; + width: 45%; + min-height: 35px; + white-space: normal; + line-height: normal; + } } .remove-button { - margin: 12px; - width: 150px; + margin-top: 12px; + left: 5px; + width: 165px; + + @include mobile { + margin: 0px; + width: 45%; + min-height: 35px; + white-space: normal; + line-height: normal; + } } .clear-form-button { left: 10px; - width: 150px; + width: 165px; + + @include mobile { + width: 45%; + min-height: 35px; + white-space: normal; + line-height: normal; + } } .clear-search-button { - left: 10px; - width: 150px; + left: 5px; + width: 165px; + + @include mobile { + width: 45%; + min-height: 35px; + white-space: normal; + line-height: normal; + } } .thematics { diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index a3903ef9bb..53360e5ed1 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -259,6 +259,7 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { } }); }); + console.log(this.thematics); this.dataSource.data = this.thematics; diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index fd0b2d42fd..f336830a19 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -441,7 +441,7 @@ "removeLayer": "Remove results", "exportLayer": "Export results", "clearForm": "Remove draw", - "clearSearch": "Reset", + "clearSearch": "Reset field", "Address": "Addresses", "Thematics": "Thematics", "searchResults": "Search Results", diff --git a/packages/geo/src/locale/fr.geo.json b/packages/geo/src/locale/fr.geo.json index 4e62caeacd..30bbc8e300 100644 --- a/packages/geo/src/locale/fr.geo.json +++ b/packages/geo/src/locale/fr.geo.json @@ -441,7 +441,7 @@ "removeLayer": "Retirer les résultats", "exportLayer": "Exporter les résultats", "clearForm": "Retirer le dessin", - "clearSearch": "Réinitialiser", + "clearSearch": "Réinitialiser les champs", "Address": "Adresses", "Thematics": "Thématiques", "searchResults": "Résultats de la recherche", diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index a7fba278a3..baec5eeeff 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -263,15 +263,15 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { thematic.zeroResults = true; } - if (features.length >= 10000) { - this.messageService.error( + if (features.length >= 20000) { + this.messageService.alert( this.languageService.translate.instant( 'igo.geo.spatialFilter.maxSizeAlert' ), this.languageService.translate.instant( 'igo.geo.spatialFilter.warning' ), - { timeOut: 10000 } + { timeOut: 10000, icon: 'alert-circle-outline' } ); } }) From 1eb22402195e207735b2e309adeeb906bd2721b8 Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Mon, 30 Nov 2020 14:36:38 -0500 Subject: [PATCH 6/7] WIP --- .../spatial-filter-item.component.scss | 8 +++-- .../spatial-filter-item.component.ts | 34 +++++++++++++++---- packages/geo/src/locale/en.geo.json | 1 + packages/geo/src/locale/fr.geo.json | 1 + .../spatial-filter-tool.component.ts | 2 ++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss index 183ac2b1b4..cf2b2d42b4 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.scss @@ -46,10 +46,11 @@ } .search-button { - left: 10px; + left: 15px; width: 165px; @include mobile { + left: 10px; width: 45%; min-height: 35px; white-space: normal; @@ -58,10 +59,11 @@ } .export-button { - left: 10px; + left: 15px; width: 165px; @include mobile { + left: 10px; margin-top: 10px; width: 45%; min-height: 35px; @@ -109,7 +111,7 @@ } .thematics { - max-height: 30%; + max-height: 35%; overflow: auto; margin-top: 5px; width: 98%; diff --git a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts index 53360e5ed1..1c2a73e1c3 100644 --- a/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts +++ b/packages/geo/src/lib/filter/spatial-filter/spatial-filter-item/spatial-filter-item.component.ts @@ -230,6 +230,12 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { return a.name.localeCompare(b.name); }); } + this.groups.push(this.languageService.translate.instant('igo.geo.terrapi.limites')); + const limits: SpatialFilterThematic = { + name: this.groups[0], + children: [] + }; + this.thematics.push(limits); this.childrens.forEach(child => { if (child.group && (this.groups.indexOf(child.group) === -1)) { this.groups.push(child.group); @@ -239,13 +245,28 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { }; this.thematics.push(thematic); } + if (!child.group) { - const thematic: SpatialFilterThematic = { - name: child.name, - children: [], - source: child.source - }; - this.thematics.push(thematic); + if ( + child.name === this.languageService.translate.instant('igo.geo.terrapi.AdmRegion') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.Mun') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.Arrond') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.CircFed') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.CircProv') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.DirReg') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.MRC') || + child.name === this.languageService.translate.instant('igo.geo.terrapi.RegTour')) { + child.group = limits.name; + } else if (child.name === this.languageService.translate.instant('igo.geo.terrapi.routes')) { + child.group = this.languageService.translate.instant('igo.geo.spatialFilter.group.transport'); + } else { + const thematic: SpatialFilterThematic = { + name: child.name, + children: [], + source: child.source + }; + this.thematics.push(thematic); + } } this.thematics.sort((a, b) => { return a.name.localeCompare(b.name); @@ -259,7 +280,6 @@ export class SpatialFilterItemComponent implements OnDestroy, OnInit { } }); }); - console.log(this.thematics); this.dataSource.data = this.thematics; diff --git a/packages/geo/src/locale/en.geo.json b/packages/geo/src/locale/en.geo.json index f336830a19..8827d0f10b 100644 --- a/packages/geo/src/locale/en.geo.json +++ b/packages/geo/src/locale/en.geo.json @@ -472,6 +472,7 @@ "DirReg": "Regionals directorates", "MRC": "RCM", "RegTour": "Touristics regions", + "limites": "Administrative boundaries", "bornes": "Landmarks", "hydro": "Hydrography", "routes": "Roads", diff --git a/packages/geo/src/locale/fr.geo.json b/packages/geo/src/locale/fr.geo.json index 30bbc8e300..33e64f74d4 100644 --- a/packages/geo/src/locale/fr.geo.json +++ b/packages/geo/src/locale/fr.geo.json @@ -472,6 +472,7 @@ "DirReg": "Directions régionales", "MRC": "MRC", "RegTour": "Régions touristiques", + "limites": "Limites administratives", "bornes": "Bornes sumi", "hydro": "Hydrographie", "routes": "Routes", diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index baec5eeeff..7ecfb0a94a 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -244,6 +244,8 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { let idLinePoly; features.forEach(feature => { if (feature.geometry.type === 'Point') { + feature.properties.longitude = feature.geometry.coordinates[0]; + feature.properties.latitude = feature.geometry.coordinates[1]; featuresPoint.push(feature); idPoint = feature.meta.id; } else { From 7e8f289b71da0ede60832bd821fbc9a51c989ee0 Mon Sep 17 00:00:00 2001 From: Philippe Lafreniere Date: Mon, 30 Nov 2020 15:42:38 -0500 Subject: [PATCH 7/7] WIP --- demo/src/app/geo/spatial-filter/spatial-filter.component.ts | 3 ++- packages/geo/src/lib/filter/shared/spatial-filter.service.ts | 2 +- .../spatial-filter-tool/spatial-filter-tool.component.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts index 51db3a070a..d556d8227b 100644 --- a/demo/src/app/geo/spatial-filter/spatial-filter.component.ts +++ b/demo/src/app/geo/spatial-filter/spatial-filter.component.ts @@ -146,7 +146,8 @@ export class AppSpatialFilterComponent { this.zone, this.itemType, this.queryType, - thematic + thematic, + this.radius ) .subscribe((features: Feature[]) => { this.store.insertMany(features); diff --git a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts index 1dab52b765..7a642a21c8 100644 --- a/packages/geo/src/lib/filter/shared/spatial-filter.service.ts +++ b/packages/geo/src/lib/filter/shared/spatial-filter.service.ts @@ -16,7 +16,7 @@ import { SpatialFilterThematic } from './spatial-filter.interface'; providedIn: 'root' }) export class SpatialFilterService { - public baseUrl: string = 'https://testgeoegl.msp.gouv.qc.ca/apis/terrapi/'; + public baseUrl: string = 'https://geoegl.msp.gouv.qc.ca/apis/terrapi/'; /* * Type association with URL diff --git a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts index 7ecfb0a94a..554c730ce4 100644 --- a/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts +++ b/packages/integration/src/lib/filter/spatial-filter-tool/spatial-filter-tool.component.ts @@ -265,7 +265,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { thematic.zeroResults = true; } - if (features.length >= 20000) { + if (features.length >= 10000) { this.messageService.alert( this.languageService.translate.instant( 'igo.geo.spatialFilter.maxSizeAlert' @@ -273,7 +273,7 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy { this.languageService.translate.instant( 'igo.geo.spatialFilter.warning' ), - { timeOut: 10000, icon: 'alert-circle-outline' } + { timeOut: 10000 } ); } })