diff --git a/src/app/requete/pages/requete-new/requete-new.component.ts b/src/app/requete/pages/requete-new/requete-new.component.ts index f7bba5b..a41e2b2 100644 --- a/src/app/requete/pages/requete-new/requete-new.component.ts +++ b/src/app/requete/pages/requete-new/requete-new.component.ts @@ -1,5 +1,5 @@ import { AfterViewInit, Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { map } from 'rxjs'; import { MapContextService } from '../../../shared-map/services/map-context.service'; @@ -23,7 +23,8 @@ export class RequeteNewComponent implements OnInit, AfterViewInit { constructor( private breadcrumbTransformerService: BreadcrumbTransformerService, private mapContextService: MapContextService, - private route: ActivatedRoute + private route: ActivatedRoute, + private router: Router ) { } ngOnInit(): void { @@ -33,6 +34,9 @@ export class RequeteNewComponent implements OnInit, AfterViewInit { if (response && response.data) { this.foret = response.data; } + // if (response && !response.data) { + // this.router.navigate(['/', '404']); + // } this.loadPageComponent(); }) ).subscribe(); diff --git a/src/app/shared-map/services/map-context.service.ts b/src/app/shared-map/services/map-context.service.ts index 82e4a7c..a961e33 100644 --- a/src/app/shared-map/services/map-context.service.ts +++ b/src/app/shared-map/services/map-context.service.ts @@ -216,6 +216,7 @@ export class MapContextService { } updateLayersVisibility(event: any) { + console.log('updateLayersVisibility', event); const layersGroup: any = this.map?.getLayers().getArray(); layersGroup?.forEach((layerGroup: any) => { const group = layerGroup.get('group') || 'base-layer'; diff --git a/src/app/shared-thematic/components/thematic-tabs/thematic-tabs.component.ts b/src/app/shared-thematic/components/thematic-tabs/thematic-tabs.component.ts index 4bb1be4..ca4a099 100644 --- a/src/app/shared-thematic/components/thematic-tabs/thematic-tabs.component.ts +++ b/src/app/shared-thematic/components/thematic-tabs/thematic-tabs.component.ts @@ -1,9 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { MapContextService } from '../../../shared-map/services/map-context.service'; -import { THEMATIC_LIST } from '../../models/thematic-list.enum'; import { Thematic } from '../../models/thematic.model'; -import { LayerFiche } from '../../models/layer-fiche.model'; import { ThematicFeatureService } from '../../services/thematic-feature.service'; @Component({ @@ -43,39 +41,6 @@ export class ThematicTabsComponent implements OnInit { this.mapContextService.updateLayersVisibility(event); } - - // private setSelectedTabIndex(tabId: string) { - // let indexModifier = 0; - // for (let i = 0; i < this.thematics.length; i++) { - // if (this.thematics[i].name === tabId) { - // this.selectedTabIndex = i - indexModifier; - // } else if (!this.thematics[i].active) { - // indexModifier++; - // } - // } - // } - - - private updateFicheLayer(layer: LayerFiche) { - layer.displaySituationMap = false; - layer.features = []; - layer.features = this.responseFeatures.filter((feature) => { - if (this.parseLayerFromTechnicalName(layer.technicalName) === feature.layer) { - if ((layer.title === 'Coeurs de parcs nationaux' && feature.zone != 'Coeur') || - (layer.title === 'Zones d\'adhésion de parcs nationaux' && feature.zone != 'Adhesion') || - (layer.title === 'Monuments historiques' && feature.suptype != 'ac1') || - (layer.title === 'Sites inscrits et classés' && feature.suptype != 'ac2') - ) { - return false - } - return true - } - return false; - }); - return layer; - } - - private updateActiveThematicLayersFromFeatures(features: any) { for (let i = 0; i < features.length; i++) { const layer = features[i].layer; @@ -108,9 +73,4 @@ export class ThematicTabsComponent implements OnInit { return res; } - - private parseLayerFromTechnicalName(technicalName: string) { - return technicalName.split(':')[1]; - } - } \ No newline at end of file diff --git a/src/app/shared-thematic/models/layer-fiche.model.ts b/src/app/shared-thematic/models/layer-fiche.model.ts index 8952000..71d1441 100644 --- a/src/app/shared-thematic/models/layer-fiche.model.ts +++ b/src/app/shared-thematic/models/layer-fiche.model.ts @@ -2,14 +2,22 @@ import { Serializable } from '../../core/models/serializable.model'; export class LayerFiche implements Serializable { + id: string = ''; + title: string = ''; - group: string = ''; + // wfs result name + name: string = ''; + // wfs request name technicalName: string = ''; + group: string = ''; + features: any[] = []; + restrictions: any[] = []; + // uniquement a l'execution du front (permet de suivre l'affichage d'une carte de situation) displaySituationMap: boolean = false; @@ -17,22 +25,28 @@ export class LayerFiche implements Serializable { deserialise(input: any) { Object.assign(this, { + id: input.id, title: input.title, - group: input.group, + name: input.name, technicalName: input.technicalName, - displaySituationMap: input.displaySituationMap || false, - features: input.features || [] + group: input.group, + features: input.features || [], + restrictions: input.restrictions || [], + displaySituationMap: input.displaySituationMap || false }); return this; } serialise() { return { + id: this.id, title: this.title, - group: this.group, + name: this.name, technicalName: this.technicalName, - displaySituationMap: this.displaySituationMap, - features: this.features + group: this.group, + features: this.features, + restrictions: this.restrictions, + displaySituationMap: this.displaySituationMap }; } diff --git a/src/app/shared-thematic/models/thematic-list.enum.ts b/src/app/shared-thematic/models/thematic-list.enum.ts index 936188a..ef970b8 100644 --- a/src/app/shared-thematic/models/thematic-list.enum.ts +++ b/src/app/shared-thematic/models/thematic-list.enum.ts @@ -14,81 +14,121 @@ export const THEMATIC_LIST = [ active: true, layers: [ { + id: 'terrains-des-conservatoires-d-espaces-naturels', title: 'Terrains des conservatoires d\'espaces naturels', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.MNHN.CONSERVATOIRES:cen' + technicalName: 'PROTECTEDAREAS.MNHN.CONSERVATOIRES:cen', + name: 'cen' }, { + id: 'conservatoire-du-littoral-sites-sous-responsabilite-du-conservatoire', title: 'Conservatoire du littoral - sites sous responsabilité du conservatoire', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.MNHN.CDL.PARCELS:cdl' + technicalName: 'PROTECTEDAREAS.MNHN.CDL.PARCELS:cdl', + name: 'cdl' }, { + id: 'parcs-naturels-regionaux', title: 'Parcs naturels régionaux', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.PNR:pnr' + technicalName: 'PROTECTEDAREAS.PNR:pnr', + name: 'pnr' }, { + id: 'reserves-nationales-de-chasse-et-de-faune-sauvage', title: 'Réserves nationales de chasse et de faune sauvage', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.RNCF:rncfs' + technicalName: 'PROTECTEDAREAS.RNCF:rncfs', + name: 'rncfs' }, { + id: 'reserves-biologiques', title: 'Réserves Biologiques', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.RB:rb' + technicalName: 'PROTECTEDAREAS.RB:rb', + name: 'rb' }, { + id: 'arretes-listes-de-sites-d-interet-geologique', title: 'Arrêtés listes de sites d\'intérêt géologique', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.APLG:aplg' + technicalName: 'PROTECTEDAREAS.APLG:aplg', + name: 'aplg' }, { + id: 'perimetres-de-protection-de-reserves-naturelles', title: 'Périmètres de protection de réserves naturelles', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.MNHN.RN.PERIMETER:pprnn' + technicalName: 'PROTECTEDAREAS.MNHN.RN.PERIMETER:pprnn', + name: 'pprnn' }, { + id: 'reserves-naturelles-regionales', title: 'Réserves naturelles régionales', group: 'biodiversite', - technicalName: 'PROTECTEDSITES.MNHN.RESERVES-REGIONALES:rnr' + technicalName: 'PROTECTEDSITES.MNHN.RESERVES-REGIONALES:rnr', + name: 'rnr' }, { + id: 'reserves-naturelles-nationales', title: 'Réserves naturelles nationales', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.RNN:rnn' + technicalName: 'PROTECTEDAREAS.RNN:rnn', + name: 'rnn' }, { + id: 'reserves-naturelles-de-corse', title: 'Réserves Naturelles de Corse', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.RNC:rnc' + technicalName: 'PROTECTEDAREAS.RNC:rnc', + name: 'rnc' }, { + id: 'biotopes-d-especes-protegees', title: 'Biotopes d\'espèces protégées', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.APB:apb' + technicalName: 'PROTECTEDAREAS.APB:apb', + name: 'apb' }, { + id: 'arretes-de-protection-d-habitats-naturels', title: 'Arrêtés de protection d\'habitats naturels', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.APHN:aphn' + technicalName: 'PROTECTEDAREAS.APHN:aphn', + name: 'aphn' }, { + id: 'arretes-de-protection-de-geotope', title: 'Arrêtés de protection de géotope', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.APG:apg' + technicalName: 'PROTECTEDAREAS.APG:apg', + name: 'apg' }, { + id: 'coeurs-de-parcs-nationaux', title: 'Coeurs de parcs nationaux', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.PN:pn' + technicalName: 'PROTECTEDAREAS.PN:pn', + name: 'pn', + restrictions: [{ attribute: 'zone', value: 'Coeur' }] }, { + id: 'zones-d-adhesion-de-parcs-nationaux', title: 'Zones d\'adhésion de parcs nationaux', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.PN:pn' + technicalName: 'PROTECTEDAREAS.PN:pn', + name: 'pn', + restrictions: [{ attribute: 'zone', value: 'Adhesion' }] }, { + id: 'natura-deux-milles-habitats', title: 'Natura 2000 Habitats', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.SIC:sic' + technicalName: 'PROTECTEDAREAS.SIC:sic', + name: 'sic' }, { + id: 'natura-deux-milles-oiseaux', title: 'Natura 2000 Oiseaux', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.ZPS:zps' + technicalName: 'PROTECTEDAREAS.ZPS:zps', + name: 'zps' }, { + id: 'znieff-deux', title: 'ZNIEFF2', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.ZNIEFF2:znieff2' + technicalName: 'PROTECTEDAREAS.ZNIEFF2:znieff2', + name: 'znieff2' }, { + id: 'znieff-un', title: 'ZNIEFF1', group: 'biodiversite', - technicalName: 'PROTECTEDAREAS.ZNIEFF1:znieff1' + technicalName: 'PROTECTEDAREAS.ZNIEFF1:znieff1', + name: 'znieff1' } ] }), @@ -99,19 +139,27 @@ export const THEMATIC_LIST = [ active: true, layers: [ { + id: 'monuments-historiques', title: 'Monuments historiques', group: 'patrimoine', - technicalName: 'wfs_sup:assiette_sup_s' + technicalName: 'wfs_sup:assiette_sup_s', + name: 'assiette_sup_s', + restrictions: [{ attribute: 'suptype', value: 'ac1' }] }, { + id: 'sites-inscrits-et-classes', title: 'Sites inscrits et classés', group: 'patrimoine', - technicalName: 'wfs_sup:assiette_sup_s' + technicalName: 'wfs_sup:assiette_sup_s', + name: 'assiette_sup_s', + restrictions: [{ attribute: 'suptype', value: 'ac2' }] }, { + id: 'espaces-boises-classes', title: 'Espaces boisés classés', group: 'patrimoine', - technicalName: 'wfs_du:prescription_surf' + technicalName: 'wfs_du:prescription_surf', + name: 'prescription_surf' } ] }) diff --git a/src/app/shared-thematic/services/thematic-feature.service.ts b/src/app/shared-thematic/services/thematic-feature.service.ts index f30f580..0c01572 100644 --- a/src/app/shared-thematic/services/thematic-feature.service.ts +++ b/src/app/shared-thematic/services/thematic-feature.service.ts @@ -7,6 +7,7 @@ import { MapContextService } from '../../shared-map/services/map-context.service import { WfsRequest } from '../models/wfs-request'; import { THEMATIC_LIST } from '../models/thematic-list.enum'; import { Thematic } from '../models/thematic.model'; +import { LayerFiche } from '../models/layer-fiche.model'; @Injectable({ providedIn: 'root' @@ -69,19 +70,30 @@ export class ThematicFeatureService { thematic.layers = []; } thematic.layers = thematic.layers.map((layer: any) => { - const name = layer.technicalName; - const layerName = name.split(':').length > 0 ? name.split(':')[1] : name; // TODO must be override in thematic list component layer.displaySituationMap = false; layer.features = []; - layer.features = features.filter((feature) => { - return layerName === feature.layer; - }); + layer.features = features.filter((feature) => this.isFeatureBelongToLayer(feature, layer)); return layer; }); return thematic; } + + private isFeatureBelongToLayer(featureProperties: any, layer: LayerFiche) { + console.log(featureProperties, layer); + if (featureProperties.layer !== layer.name) { + return false; + } + if (layer.restrictions) { + const restrictionNotMet = layer.restrictions.find((restriction) => { + return featureProperties[restriction.attribute] !== restriction.value; + }); + return !restrictionNotMet; + } + return true; + } + /** * Build wfs request to access all features of a layer * @param layer