Skip to content

Commit

Permalink
probleme d ordre different entre feature planign et bdtopo
Browse files Browse the repository at this point in the history
  • Loading branch information
IGNFhc committed Feb 27, 2024
1 parent 8a0e238 commit 0f7ea3d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 118 deletions.
81 changes: 35 additions & 46 deletions src/js/map-interactivity/feature-property-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const natureRouteToDisplay = ["Autoroute", "Bretelle", "Chemin",

const isIndifferencie = (prop) => {
if (prop == "Indifférenciée" || prop == "Indifférencié") return true;
return false;
else return false;
};

const featurePropertyFilter = (feature) => {
Expand All @@ -29,62 +29,51 @@ const featurePropertyFilter = (feature) => {
});
return result;
}
let nature = "";
if (Object.prototype.hasOwnProperty.call(feature.properties, "nature")) {
nature = feature.properties.nature;

//Attribut toponyme en priorité
if (feature.properties.hasOwnProperty('toponyme')) {
result = result + feature.properties.toponyme + "<br/>";
}

Object.entries(feature.properties).forEach((prop) => {
// Troncon de route
if(feature.layer["source-layer"] == "troncon_de_route") {
// Autoroute
if(prop[0] == "cpx_classement_administratif" && nature == "Type autoroutier") {
result = result + `${prop[1]} <br />`;
}
// Contenu dans natureRouteToDisplay
if(prop[0] == "nature" && natureRouteToDisplay.includes(nature)) {
result = result + `${prop[1]} <br />`;
}
// Attributs des routes
if(feature.layer["source-layer"] == "troncon_de_route") {
let cpx_classement_administratif = feature.properties.hasOwnProperty('cpx_classement_administratif') ? feature.properties.cpx_classement_administratif : "";
let cpx_numero = feature.properties.hasOwnProperty('cpx_numero') ? feature.properties.cpx_numero : "";
let cpx_toponyme_route_nommee = feature.properties.hasOwnProperty('cpx_toponyme_route_nommee') ? feature.properties.cpx_toponyme_route_nommee : "";
var routeName = `${cpx_classement_administratif} ${cpx_numero} ${cpx_toponyme_route_nommee} <br/>`
routeName = routeName.trim();
if (routeName != "") {
result = result + routeName;
}
// Voies Ferrées
if (feature.layer["source-layer"] == "troncon_de_voie_ferree"){
if(prop[0] == "nature") {
result = result + `${prop[1]} <br />`;
}
else {
if (feature.properties.hasOwnProperty('nature')
&& natureRouteToDisplay.includes(feature.properties.nature))
result = result + `${feature.properties.nature} <br />`;
}
// Le reste
if(feature.layer["source-layer"] == "construction_lineaire"
|| feature.layer["source-layer"] == "construction_surfacique"
|| feature.layer["source-layer"] == "construction_ponctuelle"
|| feature.layer["source-layer"] == "equipement_de_transport"
|| feature.layer["source-layer"] == "pylone"
|| feature.layer["source-layer"] == "reservoir"
|| feature.layer["source-layer"] == "plan_d_eau"
|| feature.layer["source-layer"] == "cimetiere"
|| feature.layer["source-layer"] == "zone_de_vegetation"
|| feature.layer["source-layer"] == "zone_d_estran"
|| feature.layer["source-layer"] == "cimetiere"
|| feature.layer["source-layer"] == "ligne_orographique"
|| feature.layer["source-layer"] == "cours_d_eau"
|| feature.layer["source-layer"] == "surface_hydrographique"
|| feature.layer["source-layer"] == "parc_ou_reserve"
|| feature.layer["source-layer"] == "zone_d_activite_ou_d_interet"
|| feature.layer["source-layer"] == "terrain_de_sport") {
if(prop[0] == "nature") {
result = result + `${prop[1]} <br />`;
}
if(prop[0] == "nature_detaillee") {
result = result + `${prop[1]} <br />`;
}

}
var nature = ""
if (feature.layer["source-layer"] != "batiment") {
var nature = ""
if (feature.properties.hasOwnProperty("nature")) {
nature += feature.properties.nature;
}
if (feature.properties.hasOwnProperty("nature_detaillee")) {
nature = nature != "" ? nature + ", " + feature.properties.nature_detaillee : feature.properties.nature_detaillee;
}
}
if (nature != "") {
result = result + nature + "<br/>";
}


Object.entries(feature.properties).forEach((prop) => {
// Batiment
if(feature.layer["source-layer"] == "batiment") {
if(prop[0] == "nature" && isIndifferencie(prop[0])) {
if(prop[0] == "nature" && !isIndifferencie(prop[1])) {
result = result + `Nature : ${prop[1]} <br />`;
}
if(prop[0] == "usage_1" && isIndifferencie(prop[0])) {
if(prop[0] == "usage_1" && !isIndifferencie(prop[1])) {
result = result + `Usage : ${prop[1]} <br />`;
}
if(prop[0] == "nombre_de_logements" && prop[0] != "") {
Expand Down
65 changes: 42 additions & 23 deletions src/js/map-interactivity/legend-plan-ign.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function beautifyLayerName(feature, source) {
}
// PLAN IGN
else {
if (Object.hasOwnProperty.call(feature.properties, "texte")
&& feature.properties.texte)
return feature.properties.texte;

if (Object.hasOwnProperty.call(feature.layer, "metadata")
&& Object.hasOwnProperty.call(feature.layer.metadata, "legend-title"))
return feature.layer.metadata["legend-title"];
Expand Down Expand Up @@ -199,39 +203,60 @@ function getLegend(svg, layername) {
function Legend(features, zoom) {

const source = features.length > 0 ? features[0].source : "";
let legend = "";
let svg = "";
var featuresForLegend = [];

// Légende pour POI
if (source == "poi_osm") {
let featurePOI = features.filter(feat => {
if (source == "poi_osm" && feat.source == "poi_osm") return feat;
})
.map(feat => {
feat.layer["properties"] = feat.properties;
return feat.layer;
});
var layername = featurePOI.length > 0 ? beautifyLayerName(featurePOI[0], source) : "";
if (featurePOI) {
svg = MapBoxStyleToSVG(featurePOI, zoom);
legend = getLegend(svg, layername);
}
return legend;
}


// PLAN IGN et BDTOPO
let stylePLANIGN = [];
if (source == "plan_ign" || source == "bdtopo") {
stylePLANIGN = globals.manager.layerSwitcher.layers["PLAN.IGN.INTERACTIF$GEOPORTAIL:GPP:TMS"].style;
}
let legend = "";
let svg = "";

var f = features.filter(feat => {
var FeaturesBDTOPO = features.filter(feat => feat.source == "bdtopo");
if (FeaturesBDTOPO.length == 0) return legend;

var FeaturesPLANIGN = features.filter(feat => {
if (source == "plan_ign" || source == "bdtopo") {
if (feat.source == "plan_ign" && feat.layer.id != "bckgrd") {
// Dans le cas où c'est un symbole textuel et pas une icone on n'affichera pas de légende.
if (feat.layer.type == "symbol" && !Object.hasOwnProperty.call(feat.layer.layout, "icon-image")) return;
if (feat.layer.id == "zone batie") return;
// pour éviter les désynchronisation Bdtopo PLANIGN on prend feature de plan ign si correspond au type de feature bdtopo sélectionnée.
if (feat.layer.type != FeaturesBDTOPO[0].layer.type) return;
return feat;
}
}
if (source == "poi_osm") {
if (feat.source == "poi_osm") return feat;
}
});

if (f.length == 0) return legend;
if (FeaturesPLANIGN.length == 0) return legend;

/**
* Cas où 1er élément dans bdtopo est entité dans une ZA
* mais 1er élément dans planIGN est ZA
*
* */
if (f[0].source == "plan_ign" && f[0].sourceLayer == "bati_zai") {
if (features[0].sourceLayer != "zone_d_activite_ou_d_interet") f = f.filter(feat => feat.sourceLayer != "bati_zai");
if (FeaturesPLANIGN[0].sourceLayer == "bati_zai") {
if (FeaturesBDTOPO[0].sourceLayer != "zone_d_activite_ou_d_interet") FeaturesPLANIGN.shift();
}

var featuresForLegend = [];
/**
* Gestion des groupes de légende pour PALN IGN:
*
Expand All @@ -243,26 +268,20 @@ function Legend(features, zoom) {
* sont utilisés pour générer le svg de légende.
*
*/
if ((source == "plan_ign" || source == "bdtopo") && f.length > 0) {
featuresForLegend = stylePLANIGN.filter((elem) => {
if (elem.id == f[0].layer.id) {
var featuresForLegend = [];
featuresForLegend = stylePLANIGN.filter((elem) => {
if (elem.id == FeaturesPLANIGN[0].layer.id) {
return elem;
}
if (Object.hasOwnProperty.call(f[0].layer.metadata, "legend-group")
if (Object.hasOwnProperty.call(FeaturesPLANIGN[0].layer.metadata, "legend-group")
&& Object.hasOwnProperty.call(elem, "metadata")
&& Object.hasOwnProperty.call(elem.metadata, "legend-group")
&& f[0].layer.metadata["legend-group"] == elem.metadata["legend-group"]) {
&& FeaturesPLANIGN[0].layer.metadata["legend-group"] == elem.metadata["legend-group"]) {
return elem;
}
});
}

if (source == "poi_osm") featuresForLegend = f.map(feat => {
feat.layer["properties"] = feat.properties;
return feat.layer;
});

var layername = f.length > 0 ? beautifyLayerName(f[0], source) : "";
var layername = FeaturesPLANIGN.length > 0 ? beautifyLayerName(FeaturesPLANIGN[0], source) : "";
if (featuresForLegend) {
svg = MapBoxStyleToSVG(featuresForLegend, zoom);
legend = getLegend(svg, layername);
Expand Down
57 changes: 11 additions & 46 deletions www/data/plan-ign-interactif-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -15927,24 +15927,6 @@
"text-halo-width": 4
}
},
{
"id": "administratif_ou_militaire",
"type": "fill",
"source": "bdtopo",
"source-layer": "zone_d_activite_ou_d_interet",
"minzoom": 14,
"paint": {
"fill-color": "transparent"
},
"filter": [
"all",
[
"==",
"categorie",
"Administratif ou militaire"
]
]
},
{
"id": "gestion_des_eaux",
"type": "fill",
Expand Down Expand Up @@ -16053,16 +16035,6 @@
]
]
},
{
"id": "zone_d_activite_ou_d_interet",
"type": "line",
"source": "bdtopo",
"source-layer": "zone_d_activite_ou_d_interet",
"paint": {
"line-color": "transparent",
"line-width": 15
}
},
{
"id": "surface_hydrographique_surf",
"type": "fill",
Expand Down Expand Up @@ -16310,7 +16282,7 @@
],
"paint": {
"line-color": "transparent",
"line-width": 15
"line-width": 5
}
},
{
Expand Down Expand Up @@ -16451,7 +16423,7 @@
],
"paint": {
"line-color": "transparent",
"line-width": 15,
"line-width": 5,
"line-dasharray": [
3,
2
Expand All @@ -16474,7 +16446,7 @@
],
"paint": {
"line-color": "transparent",
"line-width": 15,
"line-width": 5,
"line-dasharray": [
3,
2
Expand Down Expand Up @@ -16553,6 +16525,14 @@
"source": "bdtopo",
"source-layer": "equipement_de_transport",
"minzoom": 15,
"filter": [
"all",
[
"!=",
"nature",
"Port"
]
],
"paint": {
"line-color": "transparent",
"line-width": 15
Expand Down Expand Up @@ -16753,21 +16733,6 @@
"fill-color": "transparent"
}
},
{
"id": "port",
"type": "fill",
"source": "bdtopo",
"source-layer": "equipement_de_transport",
"minzoom": 15,
"filter": [
"==",
"nature",
"Port"
],
"paint": {
"fill-color": "transparent"
}
},
{
"id": "station_de_metro",
"type": "fill",
Expand Down
3 changes: 0 additions & 3 deletions www/data/poi-osm-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"sources": {
"poi_osm": {
"type": "vector",
"minzoom": 14,
"maxzoom": 19,
"tiles": [
"https://data.geopf.fr/tms/1.0.0/OSM.POI/{z}/{x}/{y}.pbf"
Expand All @@ -23,7 +22,6 @@
"type": "symbol",
"source": "poi_osm",
"source-layer": "point_interet",
"minzoom": 14.5,
"maxzoom": 18,
"layout": {
"visibility": "visible",
Expand All @@ -45,7 +43,6 @@
"type": "symbol",
"source": "poi_osm",
"source-layer": "point_interet",
"minzoom": 18,
"layout": {
"visibility": "visible",
"symbol-placement": "point",
Expand Down

0 comments on commit 0f7ea3d

Please sign in to comment.