Skip to content

Commit

Permalink
Merge pull request #5080 from camptocamp/geom
Browse files Browse the repository at this point in the history
Fix alternate geometry name
  • Loading branch information
sbrunner committed Aug 23, 2019
2 parents 5d648fe + da2320b commit 3509708
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
4 changes: 3 additions & 1 deletion contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export class DatasourceManager {
}

// From there on, the node is a layer node.
const gmfLayer = /** @type import('gmf/themes.js').GmfLayer */ (node);
const gmfLayer = /** @type {import('gmf/themes.js').GmfLayer} */ (node);

// (2) Skip layer node if a data source with the same id exists
const id = Number(olUtilGetUid(gmfLayer));
Expand Down Expand Up @@ -590,6 +590,7 @@ export class DatasourceManager {
const name = gmfLayer.name;
const timeAttributeName = meta.timeAttribute;
const visible = meta.isChecked === true;
const ogcAttributes = ogcServer ? ogcServer.attributes : null;

// Create the data source and add it to the cache
this.dataSourcesCache_[id] = new gmfDatasourceOGC({
Expand All @@ -609,6 +610,7 @@ export class DatasourceManager {
ogcServerType,
wfsFeatureNS,
ogcType,
ogcAttributes,
snappable,
snappingTolerance,
snappingToEdges,
Expand Down
2 changes: 2 additions & 0 deletions contribs/gmf/src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js';
* These are **not** used by the (WMTS) queries (the wmtsLayers is used by WMTS queries).
* @property {string} [ogcServerType] The type of OGC server.
* @property {string} [ogcType] The type data source. Can be: 'WMS' or 'WMTS'.
* @property {Object<string, Object<string, import('gmf/themes.js').GmfOgcServerAttribute>>} [ogcAttributes]
* The attributes of the OGC server.
* @property {boolean} [snappable] Whether the geometry from this data source can be used to snap the geometry
* of features from other data sources that are being edited. Defaults to `false`.
* @property {boolean} [snappingToEdges] Determines whether external features can be snapped to the edges of
Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ EditingSnappingService.prototype.registerTreeCtrl_ = function(treeCtrl) {
featureNS: ogcServer.wfsFeatureNS,
featurePrefix: 'feature',
features: new olCollection(),
geometryName: ogcServer.geometryName,
interaction: null,
maxFeatures: 50,
requestDeferred: null,
Expand Down
7 changes: 6 additions & 1 deletion contribs/gmf/src/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,15 @@
* @typedef {!Object<string, !GmfOgcServer>} GmfOgcServers
*/

/**
* @typedef {Object} GmfOgcServerAttribute
* @property {string} namespace The attribute namespace.
* @property {string} type The attribute type (in namspace).
*/

/**
* @typedef {Object} GmfOgcServer
* @property {boolean} credential
* @property {string} [geometryName='geometry'] Geometry name.
* @property {string} imageType 'image/png' or 'image/jpeg'.
* @property {boolean} isSingleTile
* @property {string} [namespace] Namespace
Expand All @@ -159,6 +163,7 @@
* @property {string} urlWfs The WFS URL.
* @property {string} [wfsFeatureNS] WFS feature namespace
* @property {boolean} wfsSupport
* @property {Object<string, Object<string, GmfOgcServerAttribute>>} attributes
*/

/**
Expand Down
41 changes: 24 additions & 17 deletions src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ export const WMSInfoFormat = {
* @property {!Array.<!import('ngeo/rule/Rule.js').default>} [filterRules] A list of filter rules to apply to
* this data source using the filter condition.
* @property {boolean} [filtrable] Whether the data source is filtrable or not.
* @property {string} [geometryName] The name of the geometry attribute.
* @property {string} [ogcImageType] The type of images to fetch by queries by the (WMS) or (WMTS).
* @property {Array<WMSLayer>} [wmsLayers] A list of layer definitions that are used by WMS queries.
* These are **not** used by the (WMTS) queries (the wmtsLayers is used by WMTS queries).
* @property {Array<WFSLayer>} [wfsLayers] A list of layer definitions that are used by WFS queries.
* These are **not** used by the (WMTS) queries (the wmtsLayers is used by WMTS queries).
* @property {string} [ogcServerType] The type of OGC server.
* @property {string} [ogcType] The type data source. Can be: 'WMS' or 'WMTS'.
* @property {Object<string, Object<string, import('gmf/themes.js').GmfOgcServerAttribute>>} [ogcAttributes]
* The attributes of the OGC server.
* @property {boolean} [snappable] Whether the geometry from this data source can be used to snap the geometry
* of features from other data sources that are being edited. Defaults to `false`.
* @property {boolean} [snappingToEdges] Determines whether external features can be snapped to the edges of
Expand Down Expand Up @@ -280,7 +281,7 @@ class OGC extends ngeoDatasourceDataSource {
* @type {string}
* @private
*/
this.geometryName_ = options.geometryName || DEFAULT_GEOMETRY_NAME;
this.geometryName_ = DEFAULT_GEOMETRY_NAME;

/**
* The type of images to fetch by queries by the (WMS) or (WMTS) .
Expand Down Expand Up @@ -321,6 +322,13 @@ class OGC extends ngeoDatasourceDataSource {
*/
this.ogcType_ = options.ogcType || Type.WMS;

/**
* The attributes of the OGC server.
* @type {Object<string, Object<string, import('gmf/themes.js').GmfOgcServerAttribute>>}
* @private
*/
this.ogcAttributes_ = options.ogcAttributes;

/**
* Whether the geometry from this data source can be used to snap the
* geometry of features from other data sources that are being edited.
Expand Down Expand Up @@ -473,7 +481,7 @@ class OGC extends ngeoDatasourceDataSource {

let wfsFormat = null;
if (this.supportsWFS && wfsLayers.length) {
let format = undefined;
let format;
if (this.wfsOutputFormat_ === WFSOutputFormat.GML3) {
format = new olFormatGML3();
} else if (this.wfsOutputFormat_ === WFSOutputFormat.GML2) {
Expand Down Expand Up @@ -567,13 +575,6 @@ class OGC extends ngeoDatasourceDataSource {
// === Static property getters/setters ===
// =======================================

/**
* @inheritDoc
*/
getAttributes() {
return super.attributes;
}

/**
* @inheritDoc
*/
Expand All @@ -590,9 +591,19 @@ class OGC extends ngeoDatasourceDataSource {
}

/**
* @return {string} Geometry name
* @param {?string} layer The layer name.
* @return {?string} Geometry name
*/
get geometryName() {
geometryName(layer) {
if (!this.ogcAttributes_ || !layer) {
return this.geometryName_;
}
const attributes = this.ogcAttributes_[layer];
for (const attribute in attributes) {
if (attributes[attribute].namespace == 'http://www.opengis.net/gml') {
return attribute;
}
}
return this.geometryName_;
}

Expand Down Expand Up @@ -1008,18 +1019,14 @@ class OGC extends ngeoDatasourceDataSource {
* @private
*/
updateGeometryNameFromAttributes_() {
let geometryName = DEFAULT_GEOMETRY_NAME;

if (this.attributes) {
for (const attribute of this.attributes) {
if (attribute.type === ngeoFormatAttributeType.GEOMETRY) {
geometryName = attribute.name;
this.geometryName_ = attribute.name;
break;
}
}
}

this.geometryName_ = geometryName;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/filter/RuleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,8 @@ export class RuleHelper {
filter = olFormatFilter.or.apply(null, conditions);
}
} else if (spatialTypes.includes(operator)) {
const geometryName = dataSource.geometryName;
const featureNames = dataSource.getFiltrableWFSLayerName();
const geometryName = dataSource.geometryName(featureNames ? featureNames[0] : undefined);
if (rule instanceof ngeoRuleGeometry) {
const geometry = rule.geometry;
if (operator === rsot.CONTAINS) {
Expand Down
7 changes: 4 additions & 3 deletions src/query/Querent.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,13 @@ export class Querent {

// (3) Build query options
for (const dataSource of dataSources) {
const currentFeatureTypes = dataSource.getInRangeWFSLayerNames(resolution, true);

// (a) Create common options, if not done yet
if (!getFeatureCommonOptions) {
featureNS = dataSource.wfsFeatureNS;
const featurePrefix = dataSource.wfsFeaturePrefix;
const geometryName = dataSource.geometryName;
const geometryName = dataSource.geometryName(currentFeatureTypes[0]);
const outputFormat = dataSource.wfsOutputFormat;

getFeatureCommonOptions = {
Expand All @@ -604,7 +605,7 @@ export class Querent {
}

// (b) Add queryable layer names in featureTypes array
featureTypes = featureTypes.concat(dataSource.getInRangeWFSLayerNames(resolution, true));
featureTypes = featureTypes.concat(currentFeatureTypes);

// (c) Add filter, if any. If the case, then only one data source
// is expected to be used for this request.
Expand Down Expand Up @@ -689,7 +690,7 @@ export class Querent {
const meta = dataSources[0].wfsFormat.readFeatureCollectionMetadata(
response.data
);
return meta['numberOfFeatures'];
return meta.numberOfFeatures;
});
} else {
countPromise = this.q_.resolve();
Expand Down

0 comments on commit 3509708

Please sign in to comment.