diff --git a/lizmap/modules/lizmap/lib/Project/QgisProject.php b/lizmap/modules/lizmap/lib/Project/QgisProject.php index 51ce982f9b..6c1ae8a159 100644 --- a/lizmap/modules/lizmap/lib/Project/QgisProject.php +++ b/lizmap/modules/lizmap/lib/Project/QgisProject.php @@ -376,35 +376,18 @@ public function setPropertiesAfterRead(ProjectConfig $cfg) */ protected function setShortNames(ProjectConfig $cfg) { - if ($this->path) { - $project = Qgis\ProjectInfo::fromQgisPath($this->path); - foreach ($project->projectlayers as $layer) { - if (is_null($layer->shortname)) { - continue; - } - $layerCfg = $cfg->getLayer($layer->layername); - if ($layerCfg) { - $layerCfg->shortname = $layer->shortname; - } - } - + if (!$this->path) { return; } - $shortNames = $this->xpathQuery('//maplayer/shortname'); - if ($shortNames) { - foreach ($shortNames as $sname) { - $sname = (string) $sname; - $xmlLayer = $this->xpathQuery("//maplayer[shortname='{$sname}']"); - if (!$xmlLayer) { - continue; - } - $xmlLayer = $xmlLayer[0]; - $name = (string) $xmlLayer->layername; - $layerCfg = $cfg->getLayer($name); - if ($layerCfg) { - $layerCfg->shortname = $sname; - } + $project = Qgis\ProjectInfo::fromQgisPath($this->path); + foreach ($project->projectlayers as $layer) { + if (is_null($layer->shortname)) { + continue; + } + $layerCfg = $cfg->getLayer($layer->layername); + if ($layerCfg) { + $layerCfg->shortname = $layer->shortname; } } } @@ -414,29 +397,18 @@ protected function setShortNames(ProjectConfig $cfg) */ protected function setLayerOpacity(ProjectConfig $cfg) { - if ($this->path) { - $project = Qgis\ProjectInfo::fromQgisPath($this->path); - foreach ($project->projectlayers as $layer) { - if ($layer->layerOpacity == 1) { - continue; - } - $layerCfg = $cfg->getLayer($layer->layername); - if ($layerCfg) { - $layerCfg->opacity = $layer->layerOpacity; - } - } - + if (!$this->path) { return; } - $layerWithOpacities = $this->xpathQuery('//maplayer/layerOpacity[.!=1]/parent::*'); - if ($layerWithOpacities) { - foreach ($layerWithOpacities as $layerWithOpacity) { - $name = (string) $layerWithOpacity->layername; - $layerCfg = $cfg->getLayer($name); - if ($layerCfg) { - $opacity = (float) $layerWithOpacity->layerOpacity; - $layerCfg->opacity = $opacity; - } + + $project = Qgis\ProjectInfo::fromQgisPath($this->path); + foreach ($project->projectlayers as $layer) { + if ($layer->layerOpacity == 1) { + continue; + } + $layerCfg = $cfg->getLayer($layer->layername); + if ($layerCfg) { + $layerCfg->opacity = $layer->layerOpacity; } } } @@ -446,82 +418,26 @@ protected function setLayerOpacity(ProjectConfig $cfg) */ protected function setLayerGroupData(ProjectConfig $cfg) { - if ($this->path) { - $project = Qgis\ProjectInfo::fromQgisPath($this->path); - $groupShortNames = $project->layerTreeRoot->getGroupShortNames(); - foreach ($groupShortNames as $name => $shortName) { - $layerCfg = $cfg->getLayer($name); - if (!$layerCfg) { - continue; - } - $layerCfg->shortname = $shortName; - } - $groupsMutuallyExclusive = $project->layerTreeRoot->getGroupsMutuallyExclusive(); - foreach ($groupsMutuallyExclusive as $group) { - $layerCfg = $cfg->getLayer($group); - if (!$layerCfg) { - continue; - } - $layerCfg->mutuallyExclusive = 'True'; - } - + if (!$this->path) { return; } - $groupsWithShortName = $this->xpathQuery("//layer-tree-group/customproperties/property[@key='wmsShortName']/parent::*/parent::*"); - if ($groupsWithShortName) { - foreach ($groupsWithShortName as $group) { - $name = (string) $group['name']; - $shortNameProperty = $group->xpath("customproperties/property[@key='wmsShortName']"); - if (!$shortNameProperty) { - continue; - } - - $shortNameProperty = $shortNameProperty[0]; - $sname = (string) $shortNameProperty['value']; - if (!$sname) { - continue; - } - - $layerCfg = $cfg->getLayer($name); - if (!$layerCfg) { - continue; - } - $layerCfg->shortname = $sname; - } - } else { - $groupsWithShortName = $this->xpathQuery("//layer-tree-group/customproperties/Option[@type='Map']/Option[@name='wmsShortName']/parent::*/parent::*/parent::*"); - if ($groupsWithShortName) { - foreach ($groupsWithShortName as $group) { - $name = (string) $group['name']; - $shortNameProperty = $group->xpath("customproperties/Option[@type='Map']/Option[@name='wmsShortName']"); - if (!$shortNameProperty) { - continue; - } - $shortNameProperty = $shortNameProperty[0]; - $sname = (string) $shortNameProperty['value']; - if (!$sname) { - continue; - } - - $layerCfg = $cfg->getLayer($name); - if (!$layerCfg) { - continue; - } - $layerCfg->shortname = $sname; - } + $project = Qgis\ProjectInfo::fromQgisPath($this->path); + $groupShortNames = $project->layerTreeRoot->getGroupShortNames(); + foreach ($groupShortNames as $name => $shortName) { + $layerCfg = $cfg->getLayer($name); + if (!$layerCfg) { + continue; } + $layerCfg->shortname = $shortName; } - - $groupsMutuallyExclusive = $this->xpathQuery("//layer-tree-group[@mutually-exclusive='1']"); - if ($groupsMutuallyExclusive) { - foreach ($groupsMutuallyExclusive as $group) { - $name = (string) $group['name']; - $layerCfg = $cfg->getLayer($name); - if ($layerCfg) { - $layerCfg->mutuallyExclusive = 'True'; - } + $groupsMutuallyExclusive = $project->layerTreeRoot->getGroupsMutuallyExclusive(); + foreach ($groupsMutuallyExclusive as $group) { + $layerCfg = $cfg->getLayer($group); + if (!$layerCfg) { + continue; } + $layerCfg->mutuallyExclusive = 'True'; } } @@ -530,31 +446,18 @@ protected function setLayerGroupData(ProjectConfig $cfg) */ protected function setLayerShowFeatureCount(ProjectConfig $cfg) { - if ($this->path) { - $project = Qgis\ProjectInfo::fromQgisPath($this->path); - $layersShowFeatureCount = $project->layerTreeRoot->getLayersShowFeatureCount(); - foreach ($layersShowFeatureCount as $layer) { - $layerCfg = $cfg->getLayer($layer); - if (!$layerCfg) { - continue; - } - $layerCfg->showFeatureCount = 'True'; - } - + if (!$this->path) { return; } - $layersWithShowFeatureCount = $this->xpathQuery("//layer-tree-layer/customproperties/property[@key='showFeatureCount'][@value='1']/parent::*/parent::*"); - if (!$layersWithShowFeatureCount) { - $layersWithShowFeatureCount = $this->xpathQuery("//layer-tree-layer/customproperties/Option[@type='Map']/Option[@name='showFeatureCount'][@value='1']/parent::*/parent::*/parent::*"); - } - if ($layersWithShowFeatureCount) { - foreach ($layersWithShowFeatureCount as $layer) { - $name = (string) $layer['name']; - $layerCfg = $cfg->getLayer($name); - if ($layerCfg) { - $layerCfg->showFeatureCount = 'True'; - } + + $project = Qgis\ProjectInfo::fromQgisPath($this->path); + $layersShowFeatureCount = $project->layerTreeRoot->getLayersShowFeatureCount(); + foreach ($layersShowFeatureCount as $layer) { + $layerCfg = $cfg->getLayer($layer); + if (!$layerCfg) { + continue; } + $layerCfg->showFeatureCount = 'True'; } } @@ -571,14 +474,6 @@ protected function unsetPropAfterRead(ProjectConfig $cfg) $cfg->removeLayer($layer->layername); } } - } else { - $pluginLayers = $this->xpathQuery('//maplayer[type="plugin"]'); - if ($pluginLayers) { - foreach ($pluginLayers as $layer) { - $name = (string) $layer->layername; - $cfg->removeLayer($name); - } - } } // unset cache for editionLayers diff --git a/tests/units/classes/Project/QgisProjectTest.php b/tests/units/classes/Project/QgisProjectTest.php index 24d14ace8f..7c772b59af 100644 --- a/tests/units/classes/Project/QgisProjectTest.php +++ b/tests/units/classes/Project/QgisProjectTest.php @@ -112,15 +112,42 @@ public function testSetLayerOpacity() { $file = __DIR__.'/Ressources/simpleLayer.qgs.cfg'; $json = json_decode(file_get_contents($file)); - $expectedLayer = clone $json->layers; + $expectedLayer = json_decode(json_encode($json->layers)); $expectedLayer->montpellier_events->opacity = (float) 0.85; $cfg = new Project\ProjectConfig((object) array('layers' => $json->layers)); $testProj = new qgisProjectForTests(); - $testProj->setXmlForTest(simplexml_load_file(__DIR__.'/Ressources/opacity.qgs')); + $testProj->setPath(__DIR__.'/Ressources/opacity.qgs'); $testProj->setLayerOpacityForTest($cfg); $this->assertEquals($expectedLayer, $cfg->getLayers()); } + public function testSetLayerGroupData() + { + $file = __DIR__.'/Ressources/hiddengrouplayer.qgs.cfg'; + $json = json_decode(file_get_contents($file)); + $expectedLayer = json_decode(json_encode($json->layers)); + $expectedLayer->Hidden->shortname = 'Hidden'; + $expectedLayer->Hidden->mutuallyExclusive = 'True'; + $cfg = new Project\ProjectConfig((object) array('layers' => $json->layers)); + $testProj = new qgisProjectForTests(); + $testProj->setPath(__DIR__.'/Ressources/opacity.qgs'); + $testProj->setLayerGroupDataForTest($cfg); + $this->assertEquals($expectedLayer->Hidden, $cfg->getLayers()->Hidden); + } + + public function testSetLayerShowFeatureCount() + { + $file = __DIR__.'/Ressources/simpleLayer.qgs.cfg'; + $json = json_decode(file_get_contents($file)); + $expectedLayer = json_decode(json_encode($json->layers)); + $expectedLayer->montpellier_events->showFeatureCount = 'True'; + $cfg = new Project\ProjectConfig((object) array('layers' => $json->layers)); + $testProj = new qgisProjectForTests(); + $testProj->setPath(__DIR__.'/Ressources/opacity.qgs'); + $testProj->setLayerShowFeatureCountForTest($cfg); + $this->assertEquals($expectedLayer, $cfg->getLayers()); + } + public static function getLayerData() { $layers = array( @@ -447,7 +474,7 @@ public function testSetShortNames($file, $lname, $sname) ), ); $testProj = new qgisProjectForTests(); - $testProj->setXmlForTest(simplexml_load_file($file)); + $testProj->setPath($file); $cfg = new Project\ProjectConfig((object) array('layers' => (object) $layers)); $testProj->setShortNamesForTest($cfg); $layer = $cfg->getLayers(); diff --git a/tests/units/classes/Project/Ressources/hiddengrouplayer.qgs.cfg b/tests/units/classes/Project/Ressources/hiddengrouplayer.qgs.cfg new file mode 100644 index 0000000000..1dbd2c928f --- /dev/null +++ b/tests/units/classes/Project/Ressources/hiddengrouplayer.qgs.cfg @@ -0,0 +1,28 @@ +{ + "layers": { + "Hidden": { + "id": "Hidden", + "name": "Hidden", + "type": "group", + "title": "Hidden", + "abstract": "", + "link": "", + "minScale": 1, + "maxScale": 1000000000000, + "toggled": "True", + "popup": "False", + "popupSource": "lizmap", + "popupTemplate": "", + "popupMaxFeatures": 10, + "popupDisplayChildren": "False", + "noLegendImage": "False", + "groupAsLayer": "False", + "baseLayer": "False", + "displayInLegend": "True", + "singleTile": "False", + "imageFormat": "image/png", + "cached": "False", + "clientCacheExpiration": 300 + } + } +} diff --git a/tests/units/classes/Project/Ressources/opacity.qgs b/tests/units/classes/Project/Ressources/opacity.qgs index fb09d9b1d0..938b6632f9 100644 --- a/tests/units/classes/Project/Ressources/opacity.qgs +++ b/tests/units/classes/Project/Ressources/opacity.qgs @@ -1,25 +1,965 @@ - - + + + + + + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + + + + + + + osm_mapnik20190220152650417 + osm_stamen_toner20190220152651073 + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + + + + + + + + + + meters + + 417828.47766224615043029 + 5393709.71128619741648436 + 441352.08966992393834516 + 5412981.91368997748941183 + + 0 + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + 0 + + + + + + + + + + + + + + + + + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + + + 3.70694994926452637 + 43.51250076293945313 + 4.07507991790771396 + 43.75249862670898438 + + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + ./edition/events.gpkg|layername=events + Touristic events + + + + montpellier_events + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + true + + + + + + + + + + + + + ogr + + + + + + + + + + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COALESCE( "description", '<NULL>' ) + COALESCE( "description", '<NULL>' ) + + + + + 0 - not opacity 0 - 1 + 0.85 + + + + + + + + + + + - - - - 0 - montpellier_events - 0 - 0.85 - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /home/mdouchin/Documents/3liz/Infra/lizmap-demo/demo + + 0 + /home/mdouchin/Documents/3liz/Infra/lizmap-demo/demo + + 0 + generatedlayout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COALESCE( "description", '<NULL>' ) + <div style="padding:10px;"> +<p style="font-weight:bold;font-size:1.2em;">[% "titre" %]</p> + +<p> <i>[% "field_thematique" %]</i></p> + +<p> +[%'<i class="icon-time"></i> ' || format_date( + "field_date", + 'd MMMM yyyy - HH:mm' +)%] +<br/> +[%'<i class="icon-map-marker"></i> ' || "field_lieu"%] +</p> + +<img style="width: 100%;" src="[% "vignette_src" %]" alt="[% "vignette_alt" %]" title="[% "vignette_alt" %]"/> + +<p style="padding: 10px 0px; font-size:0.8em;">[% "description" %]</p> +<p style="font-size:0.8em;"><a href="[% "url" %]" target="_blank">Voir le site</a></p> + +</div> + + + + -20037508.34278924390673637 + -20037508.34278925508260727 + 20037508.34278924390673637 + 20037508.34278924390673637 + + osm_mapnik20190220152650417 + crs=EPSG:3857&format=&type=xyz&url=http://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png + + + + osm-mapnik + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + 0 + 0 + + + + + false + + + + + wms + + + + + + + + 1 + 1 + 0 + + + + + + + + + None + WholeRaster + Estimated + 0.02 + 0.98 + 2 + + + + + + + 0 + + + + -20037508.34278924390673637 + -20037508.34278925508260727 + 20037508.34278924390673637 + 20037508.34278924390673637 + + osm_stamen_toner20190220152651073 + crs=EPSG:3857&format=&type=xyz&url=http://tile.stamen.com/toner-lite/%7Bz%7D/%7Bx%7D/%7By%7D.png + + + + osm-stamen-toner + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + 0 + 0 + + + + + false + + + + + wms + + + + + + + + 1 + 1 + 0 + + + + + + + + + None + WholeRaster + Estimated + 0.02 + 0.98 + 2 + + + + + + + 0 + + + + + + + + + + + + + 1 + EPSG:3857 + 3857 + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + + + conditions unknown + true + + 16 + 30 + false + 0 + false + 50 + true + false + 0 + + + edition_polygon_34db893a_6765_42e5_aa9a_712b69e30dc2 + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + tramstop_4cdf2dad_6f48_4491_b318_693cc9184208 + + + false + + + + 390483.99668047408340499 + 5375009.91444000415503979 + 477899.4732063576229848 + 5436768.56305211596190929 + + None + 8 + 90 + + + + + + 1 + + + 255 + + true + + + + MU + 2 + true + + + current_layer + to vertex and segment + 10 + 1 + + false + + 150 + 255 + 255 + 0 + 255 + 255 + 255 + + + + false + + + + + + + + + + + + false + + + + + + false + + + + WGS84 + + + + m2 + meters + + + true + + EPSG:4326 + EPSG:3857 + + + + + false + + + + + + + 5000 + + + + 8 + 8 + 8 + 8 + + Touristic events around Montpellier, France + + + false + + + + false + + + + + + + + + + + + + + + + + + + + + + 2000-01-01T00:00:00 + + + diff --git a/tests/units/classes/Project/Ressources/simpleLayer.qgs.cfg b/tests/units/classes/Project/Ressources/simpleLayer.qgs.cfg index 858cca6a4e..5675e17ad3 100644 --- a/tests/units/classes/Project/Ressources/simpleLayer.qgs.cfg +++ b/tests/units/classes/Project/Ressources/simpleLayer.qgs.cfg @@ -31,6 +31,6 @@ "imageFormat": "image/png", "cached": "False", "clientCacheExpiration": 300 - } + } } } diff --git a/tests/units/testslib/QgisProjectForTests.php b/tests/units/testslib/QgisProjectForTests.php index 5c87126ddb..2c7a4510cc 100644 --- a/tests/units/testslib/QgisProjectForTests.php +++ b/tests/units/testslib/QgisProjectForTests.php @@ -39,6 +39,16 @@ public function setLayerOpacityForTest($cfg) return $this->setLayerOpacity($cfg); } + public function setLayerGroupDataForTest($cfg) + { + return $this->setLayerGroupData($cfg); + } + + public function setLayerShowFeatureCountForTest($cfg) + { + return $this->setLayerShowFeatureCount($cfg); + } + public function getTheXmlAttribute() { return $this->xml;