Skip to content

Commit

Permalink
speed-up loading of embedded layers
Browse files Browse the repository at this point in the history
  • Loading branch information
mind84 committed Feb 1, 2024
1 parent 6a668a7 commit ec5e163
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lizmap/modules/lizmap/lib/Project/QgisProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1486,18 +1486,20 @@ protected function readLayers($xml)
if (!$xmlLayers) {
return $layers;
}
// Associative array that stores the embedded projects path as key and the list of embedded layers attributes as value.
// The the embedded layers definition are retreived outside the main foreach loop to avoid loading the same embedded qgis project multiple times
// for each embedded layer
$embeddedProjects = array();

foreach ($xmlLayers as $xmlLayer) {
$attributes = $xmlLayer->attributes();
if (isset($attributes['embedded']) && (string) $attributes->embedded == '1') {
$xmlFile = realpath(dirname($this->path).DIRECTORY_SEPARATOR.(string) $attributes->project);
$qgsProj = new QgisProject($xmlFile, $this->services, $this->appContext);
$layer = $qgsProj->getLayerDefinition((string) $attributes->id);
$layer['qgsmtime'] = filemtime($xmlFile);
$layer['file'] = $xmlFile;
$layer['embedded'] = 1;
$layer['projectPath'] = (string) $attributes->project;
$layers[] = $layer;
if (!array_key_exists($xmlFile, $embeddedProjects)) {
$embeddedProjects[$xmlFile] = array();
}
// populate array of embedded layers
$embeddedProjects[$xmlFile][] = $attributes;
} else {
$layer = array(
'type' => (string) $attributes->type,
Expand Down Expand Up @@ -1659,6 +1661,20 @@ protected function readLayers($xml)
$layers[] = $layer;
}
}
// loop through the embedded projects if any, to get the embedded layers definition
foreach ($embeddedProjects as $projectPath => $layersAttributes) {
if (is_array($layersAttributes)) {
$embeddedProject = new QgisProject($projectPath, $this->services, $this->appContext);
foreach ($layersAttributes as $attributes) {
$layer = $embeddedProject->getLayerDefinition((string) $attributes->id);
$layer['qgsmtime'] = filemtime($projectPath);
$layer['file'] = $projectPath;
$layer['embedded'] = 1;
$layer['projectPath'] = (string) $attributes->project;
$layers[] = $layer;
}
}
}

return $layers;
}
Expand Down

0 comments on commit ec5e163

Please sign in to comment.