Skip to content

Commit

Permalink
Add WFS attributes aliases to dataSources
Browse files Browse the repository at this point in the history
  • Loading branch information
asaunier committed Dec 7, 2017
1 parent 1775ec4 commit 28c22d6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
12 changes: 11 additions & 1 deletion contribs/gmf/src/datasource/datasourcesmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ goog.require('gmf');
goog.require('gmf.datasource.OGC');
goog.require('gmf.SyncLayertreeMap');
goog.require('gmf.TreeManager');
goog.require('gmf.WFSAliases');
goog.require('ngeo.map.BackgroundLayerMgr');
/** @suppress {extraRequire} */
goog.require('ngeo.datasource.DataSources');
Expand Down Expand Up @@ -39,13 +40,14 @@ gmf.datasource.DataSourcesManager = class {
* @param {!ngeo.map.LayerHelper} ngeoLayerHelper Ngeo Layer Helper.
* @param {!ngeo.RuleHelper} ngeoRuleHelper Ngeo rule helper service.
* @param {!ngeo.WMSTime} ngeoWMSTime wms time service.
* @param {!gmf.WFSAliases} gmfWFSAliases Gmf WFS aliases service.
* @ngInject
* @ngdoc service
* @ngname gmfDataSourcesManager
*/
constructor($q, $rootScope, $timeout, gmfThemes, gmfTreeManager,
ngeoBackgroundLayerMgr, ngeoDataSources, ngeoLayerHelper, ngeoRuleHelper,
ngeoWMSTime
ngeoWMSTime, gmfWFSAliases
) {

// === Injected properties ===
Expand Down Expand Up @@ -113,6 +115,12 @@ gmf.datasource.DataSourcesManager = class {
*/
this.ngeoWMSTime_ = ngeoWMSTime;

/**
* @type {!gmf.WFSAliases}
* @private
*/
this.gmfWFSAliases_ = gmfWFSAliases;


// === Inner properties ===

Expand Down Expand Up @@ -551,6 +559,8 @@ gmf.datasource.DataSourcesManager = class {
};

this.ngeoDataSources_.push(dataSource);

this.gmfWFSAliases_.describe(dataSource);
}

/**
Expand Down
47 changes: 47 additions & 0 deletions contribs/gmf/src/services/wfsaliases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
goog.provide('gmf.WFSAliases');

goog.require('gmf');
goog.require('ngeo.datasource.DataSourcesHelper');


gmf.WFSAliases = class {

/**
* Service that provides methods to get additional information and actions
* when perfoming WFS requests.
*
* @struct
* @param {ngeo.datasource.DataSourcesHelper} ngeoDataSourcesHelper Ngeo data
* source helper service.
* @ngdoc service
* @ngname gmfWFSAliases
* @ngInject
*/
constructor(ngeoDataSourcesHelper) {

// === Injected properties ===

/**
* @type {ngeo.datasource.DataSourcesHelper}
* @private
*/
this.ngeoDataSourcesHelper_ = ngeoDataSourcesHelper;
}


/**
* @param {ngeo.datasource.OGC} dataSource Data source.
* @export
*/
describe(dataSource) {
// Only QGIS Server supports WFS aliases
if (dataSource.ogcServerType === 'qgisserver' && !dataSource.attributes) {
// Trigger an additional WFS DescribeFeatureType request to get
// datasource attributes, including aliases.
this.ngeoDataSourcesHelper_.getDataSourceAttributes(dataSource);
}
}
};


gmf.module.service('gmfWFSAliases', gmf.WFSAliases);
7 changes: 7 additions & 0 deletions options/ngeox.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ ngeox.Attribute.prototype.maxLength;
ngeox.Attribute.prototype.name;


/**
* The attribute alias.
* @type {string|null}
*/
ngeox.Attribute.prototype.alias;


/**
* Whether the attribute required to have a value set or not. Defaults to
* `false`.
Expand Down
3 changes: 3 additions & 0 deletions src/ol-ext/format/wfsattribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ ngeo.format.WFSAttribute = class {
readFromComplexTypeElement_(object) {

const name = goog.asserts.assertString(object['name']);
const alias = 'alias' in object ?
goog.asserts.assertString(object['alias']) : null;
const required = object['minOccurs'] != '0';

const attribute = {
name,
alias,
required
};

Expand Down
2 changes: 2 additions & 0 deletions src/ol-ext/format/xsdattribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ ngeo.format.XSDAttribute.prototype.readFromElementNode_ = function(node) {
const name = node.getAttribute('name');
goog.asserts.assertString(name, 'name should be defined in element node.');

const alias = node.getAttribute('alias');
const nillable = node.getAttribute('nillable');
const required = !(nillable === true || nillable === 'true');

const attribute = {
name,
alias,
required
};

Expand Down

0 comments on commit 28c22d6

Please sign in to comment.