From 54ce263dee7c4b916e8917bc1e785d226cdaa363 Mon Sep 17 00:00:00 2001 From: Benoist FONTAINE <bfontaine@ALKANTE.AL> Date: Tue, 21 Jan 2020 17:37:39 +0100 Subject: [PATCH] Correction cadrage objet du visualiseur --- Controllers/Traits/ContextTrait.php | 45 +++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Controllers/Traits/ContextTrait.php b/Controllers/Traits/ContextTrait.php index e358634..1bd7a1e 100644 --- a/Controllers/Traits/ContextTrait.php +++ b/Controllers/Traits/ContextTrait.php @@ -14,6 +14,7 @@ Trait ContextTrait public function getServicePath($account){ $serviceFile = $this->config->params->PATH_DATA . "SYSTEM/services.xml"; + $doc = new \DOMDocument(); if (@$doc->load($serviceFile)){ @@ -63,12 +64,11 @@ Trait ContextTrait $contextFolder = $this->config->params->PATH_DATA . "/owscontext/" . $account . '/'; $contextFilename = str_replace('.map', '.geojson', $contextPath); } - + if (file_exists($contextFolder . $contextFilename)) { $fileContent = file_get_contents($contextFolder . $contextFilename); $fileContentAsJson = json_decode($fileContent, true); - $mapName = $fileContentAsJson["id"]; //$mapName = ltrim($contextPath, "/"); @@ -111,6 +111,16 @@ Trait ContextTrait $queryExtent = $this->getObjectExtent($object, $fileContentAsJson, $accountPath, $account); if($queryExtent && is_array($queryExtent)){ + //ajout d'une tolérance pour les objets ponctuels + //TODO :gérer le 4326 + if($queryExtent[0]["minx"]==$queryExtent[0]["maxx"]){ + $queryExtent[0]["minx"] = $queryExtent[0]["minx"]-100; + $queryExtent[0]["maxx"] = $queryExtent[0]["maxx"]+100; + } + if($queryExtent[0]["miny"]==$queryExtent[0]["maxy"]){ + $queryExtent[0]["miny"] = $queryExtent[0]["miny"]-100; + $queryExtent[0]["maxy"] = $queryExtent[0]["maxy"]+100; + } $fileContentAsJson["properties"]["bbox"][0] = (float) $queryExtent[0]["minx"]; $fileContentAsJson["properties"]["bbox"][1] = (float) $queryExtent[0]["miny"]; $fileContentAsJson["properties"]["bbox"][2] = (float) $queryExtent[0]["maxx"]; @@ -196,7 +206,9 @@ Trait ContextTrait if(count($properties)!==3){ throw new \Exception("invalid number of object arguments"); } - $layerName = $properties[0]; + $layerTitle = $properties[0]; + $layerName = $this->getLayerName($layerTitle, $contextJson["properties"]["extension"]["layers"]); + $key = $properties[1]; $value = $properties[2]; @@ -396,4 +408,31 @@ Trait ContextTrait } return $rootLayer; } + + /** + * Search layerName according to title or identifier + * @param layerTitle : title or identifier + * @param contextLayers : context obj + * return layerName in mapfile + */ + protected function getLayerName($layerTitle, $contextLayers){ + if (array_key_exists('class', $contextLayers) && strcmp($contextLayers["class"], "LayerGroup") !== 0) { + //TODO add test on identifier, but not present yet in context + if (array_key_exists('extension', $contextLayers) && + array_key_exists('name', $contextLayers["extension"]) + && strcmp($contextLayers["extension"]["name"],$layerTitle)===0) { + return $contextLayers["extension"]["layerName"]; + } + }else{ + //pour les groupes, parcours du tableau de layers + foreach ($contextLayers["layers"] as $key => $contextLayer){ + $layerName = $this->getLayerName($layerTitle, $contextLayer); + if($layerName!=null){ + return $layerName; + } + } + } + return null; + } + } \ No newline at end of file -- GitLab