Skip to content

Commit

Permalink
[BUGFIX] New function "attributeLayers" does not show columns/tables …
Browse files Browse the repository at this point in the history
…aliases

To do it, Lizmap adds an aliases property to GeoJSON FeatureCollections
Fixes #94
Fixes #120
  • Loading branch information
rldhont committed Feb 12, 2015
1 parent 34cc6ae commit 09752cd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lizmap/modules/lizmap/classes/qgisVectorLayer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ public function getFields() {
return $fields;
}

public function getAliasFields() {
$fields = $this->getFields();
$aliases = array();
foreach( $fields as $f ) {
$aliases[$f] = $f;
$alias = $this->xmlLayer->xpath("aliases/alias[@field='".$f."']");
if( count($alias) != 0 ) {
$alias = $alias[0];
$aliases[$f] = (string)$alias['name'];
}
}
return $aliases;
}

public function getWfsFields() {
$fields = $this->getFields();
$excludeFields = $this->xmlLayer->xpath(".//excludeAttributesWFS/attribute");
Expand Down
14 changes: 14 additions & 0 deletions lizmap/modules/lizmap/controllers/service.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,24 @@ function GetFeature(){

// Return response
$rep = $this->getResponse('binary');
/*
if(preg_match('#^GML#', $this->params['outputformat']))
$rep->mimeType = 'text/xml';
else
$rep->mimeType = 'text/json';
* */
$rep->mimeType = $mime;
if ( $mime == 'text/plain' && strtolower( $this->params['outputformat'] ) == 'geojson' ) {
$rep->mimeType = 'text/json';
$layer = $this->project->findLayerByName( $this->params['typename'] );
if ( $layer != null ) {
$layer = $this->project->getLayer( $layer->id );
$aliases = $layer->getAliasFields();
$layer = json_decode( $data );
$layer->aliases = (object) $aliases;
$data = json_encode( $layer );
}
}
$rep->content = $data;
$rep->doDownload = false;
$rep->outputFileName = 'qgis_server_wfs';
Expand Down
5 changes: 4 additions & 1 deletion lizmap/www/js/attributeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,10 @@ var lizAttributeTable = function() {
config.attributeLayers[aName]['features'] = features;
html+= '<tr>';
for (var idx in features[0].properties){
html+='<th>' + idx + '</th>';
if ( 'aliases' in data && idx in data.aliases )
html+='<th>' + data.aliases[idx] + '</th>';
else
html+='<th>' + idx + '</th>';
}
html+='<th></th>';
html+='</tr>';
Expand Down

0 comments on commit 09752cd

Please sign in to comment.