Skip to content

Commit

Permalink
feat(SharedThematic): ajout d'un identifiant unique pour la configura…
Browse files Browse the repository at this point in the history
…tion des couches ainsi que le nom utiliser dans les features retourner par requeste
  • Loading branch information
cboucheIGN committed Dec 17, 2024
1 parent 4a79908 commit 20fcfc4
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 76 deletions.
8 changes: 6 additions & 2 deletions src/app/requete/pages/requete-new/requete-new.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 {
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/app/shared-map/services/map-context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -108,9 +73,4 @@ export class ThematicTabsComponent implements OnInit {
return res;
}


private parseLayerFromTechnicalName(technicalName: string) {
return technicalName.split(':')[1];
}

}
28 changes: 21 additions & 7 deletions src/app/shared-thematic/models/layer-fiche.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,51 @@ 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;

constructor() { }

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
};
}

Expand Down
92 changes: 70 additions & 22 deletions src/app/shared-thematic/models/thematic-list.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
]
}),
Expand All @@ -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'
}
]
})
Expand Down
22 changes: 17 additions & 5 deletions src/app/shared-thematic/services/thematic-feature.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 20fcfc4

Please sign in to comment.