Skip to content

Commit 083d37e

Browse files
committed
[BUGFIX] GetFeatureInfo with layer's title
Since QGIS 2.6, When querying GetFeatureInfo with text/xml format, the layer's name can be the layer's title.
1 parent ba48b8f commit 083d37e

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lizmap/modules/lizmap/classes/lizmapProject.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ public function getOptions(){
170170
public function getLayers(){
171171
return $this->cfg->layers;
172172
}
173+
174+
public function findLayerByName( $name ){
175+
if ( property_exists($this->cfg->layers, $name ) )
176+
return $this->cfg->layers->$name;
177+
return null;
178+
}
179+
180+
public function findLayerByTitle( $title ){
181+
foreach ( $this->cfg->layers as $layer ) {
182+
if ( !property_exists( $layer, 'title' ) )
183+
continue;
184+
if ( $layer->title == $title )
185+
return $layer;
186+
}
187+
return null;
188+
}
173189

174190
public function hasLocateByLayer(){
175191
if ( property_exists($this->cfg,'locateByLayer') ){

lizmap/modules/lizmap/controllers/service.classic.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,17 @@ function getFeatureInfoHtml($params, $xmldata){
469469

470470
foreach($xml->Layer as $layer){
471471
$layername = $layer['name'];
472+
$configLayer = $this->project->findLayerByName( $layername );
473+
// since 2.6 layer's name can be layer's title
474+
if ( $configLayer == null )
475+
$configLayer = $this->project->findLayerByTitle( $layername );
476+
if ( $configLayer == null )
477+
continue;
472478

473479
// Avoid layer if no popup asked by the user for it
474480
// or if no popup property
475-
if(property_exists($configLayers->$layername, 'popup')){
476-
if($configLayers->$layername->popup != 'True'){
481+
if(property_exists($configLayer, 'popup')){
482+
if($configLayer->popup != 'True'){
477483
continue;
478484
}
479485
}
@@ -482,13 +488,13 @@ function getFeatureInfoHtml($params, $xmldata){
482488
}
483489

484490
// Get layer title
485-
$layerTitle = $configLayers->$layername->title;
491+
$layerTitle = $configLayer->title;
486492

487493
// Get the template for the popup content
488494
$templateConfigured = False;
489-
if(property_exists($configLayers->$layername, 'popupTemplate')){
495+
if(property_exists($configLayer, 'popupTemplate')){
490496
// Get template content
491-
$popupTemplate = (string)trim($configLayers->$layername->popupTemplate);
497+
$popupTemplate = (string)trim($configLayer->popupTemplate);
492498
// Use it if not empty
493499
if(!empty($popupTemplate)){
494500
$templateConfigured = True;

0 commit comments

Comments
 (0)