Skip to content

Commit

Permalink
Merge pull request #4318 from camptocamp/namespace
Browse files Browse the repository at this point in the history
Don't hard code the snapping options
  • Loading branch information
sbrunner committed Oct 24, 2018
2 parents ea40422 + 8fd8db1 commit 975f362
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 61 deletions.
14 changes: 6 additions & 8 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,9 @@ const exports = class {

// (5) ogcServer
const ogcServerType = ogcServer ? ogcServer.type : undefined;
const wfsFeatureNS = ogcServer ? ogcServer.namespace : undefined;
const wmsIsSingleTile = ogcServer ? ogcServer.isSingleTile : undefined;
const wfsUrl = ogcServer && ogcServer.wfsSupport ?
ogcServer.urlWfs : undefined;
const wfsUrl = ogcServer && ogcServer.wfsSupport ? ogcServer.urlWfs : undefined;
const wmsUrl = ogcServer ? ogcServer.url : undefined;

let wfsOutputFormat = ngeoDatasourceOGC.WFSOutputFormat.GML3;
Expand All @@ -509,12 +509,9 @@ const exports = class {

// (6) Snapping
const snappable = !!meta.snappingConfig;
const snappingTolerance = meta.snappingConfig ?
meta.snappingConfig.tolerance : undefined;
const snappingToEdges = meta.snappingConfig ?
meta.snappingConfig.edge : undefined;
const snappingToVertice = meta.snappingConfig ?
meta.snappingConfig.vertex : undefined;
const snappingTolerance = meta.snappingConfig ? meta.snappingConfig.tolerance : undefined;
const snappingToEdges = meta.snappingConfig ? meta.snappingConfig.edge : undefined;
const snappingToVertice = meta.snappingConfig ? meta.snappingConfig.vertex : undefined;

// (7) Dimensions
const dimensions = this.dimensions_;
Expand Down Expand Up @@ -556,6 +553,7 @@ const exports = class {
ogcImageType,
ogcLayers,
ogcServerType,
wfsFeatureNS,
ogcType,
snappable,
snappingTolerance,
Expand Down
60 changes: 36 additions & 24 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,13 @@ exports.prototype.registerTreeCtrl_ = function(treeCtrl) {
this.handleTreeCtrlStateChange_.bind(this, treeCtrl)
);

// Todo: some of the properties here are hardcoded, but could come from
// the node metadata at some point.
const ogcServer = this.getOGCServer_(treeCtrl);
this.cache_[uid] = {
active: false,
featureNS: 'http://mapserver.gis.umn.edu/mapserver',
featureNS: ogcServer.wfsFeatureNS,
featurePrefix: 'feature',
features: new olCollection(),
geometryName: 'geom',
geometryName: ogcServer.geometryName,
interaction: null,
maxFeatures: 50,
requestDeferred: null,
Expand Down Expand Up @@ -268,6 +267,36 @@ exports.prototype.unregisterAllTreeCtrl_ = function() {
};


/**
* Get the OGC server.
*
* @param {ngeo.layertree.Controller} treeCtrl The layer tree controller
* @return {?gmfThemes.GmfOgcServers} The OGC server.
* @private
*/
exports.prototype.getOGCServer_ = function(treeCtrl) {
const gmfLayer = /** @type {gmfThemes.GmfLayer} */ (treeCtrl.node);
if (gmfLayer.type !== gmfThemeThemes.NodeType.WMS) {
return null;
}
const gmfLayerWMS = /** @type {gmfThemes.GmfLayerWMS} */ (gmfLayer);

let ogcServerName;
const gmfGroup = /** @type {gmfThemes.GmfGroup} */ (treeCtrl.parent.node);
if (gmfGroup.mixed) {
ogcServerName = gmfLayerWMS.ogcServer;
} else {
const firstTreeCtrl = ngeoLayertreeController.getFirstParentTree(treeCtrl);
const firstNode = /** @type {gmfThemes.GmfGroup} */ (firstTreeCtrl.node);
ogcServerName = firstNode.ogcServer;
}
if (!ogcServerName) {
return null;
}
return this.ogcServers_[ogcServerName];
};


/**
* Get the configuration required to do WFS requests (for snapping purpose)
* from a Layertree controller that has a leaf node.
Expand All @@ -279,10 +308,7 @@ exports.prototype.unregisterAllTreeCtrl_ = function() {
* 2) its node `type` property is equal to `WMS`
* 3) in its node `childLayers` property, the `queryable` property is set
* to `true`
* 4) if its node `mixed` property is:
* a) true: then the node must have an `ogcServer` property set
* b) false: then the first parent node must have an `ogcServer` property set
* 5) the ogcServer defined in 3) has the `wfsSupport` property set to `true`.
* 4) the ogcServer defined in 3) has the `wfsSupport` property set to `true`.
*
* @param {ngeo.layertree.Controller} treeCtrl The layer tree controller
* @return {?gmf.editing.Snapping.WFSConfig} The configuration object.
Expand Down Expand Up @@ -316,22 +342,8 @@ exports.prototype.getWFSConfig_ = function(treeCtrl) {
}

// (4)
let ogcServerName;
const gmfGroup = /** @type {gmfThemes.GmfGroup} */ (treeCtrl.parent.node);
if (gmfGroup.mixed) {
ogcServerName = gmfLayerWMS.ogcServer;
} else {
const firstTreeCtrl = ngeoLayertreeController.getFirstParentTree(treeCtrl);
const firstNode = /** @type {gmfThemes.GmfGroup} */ (firstTreeCtrl.node);
ogcServerName = firstNode.ogcServer;
}
if (!ogcServerName) {
return null;
}

// (5)
const ogcServer = this.ogcServers_[ogcServerName];
if (!ogcServer.wfsSupport) {
const ogcServer = this.getOGCServer_(treeCtrl);
if (!ogcServer || !ogcServer.wfsSupport) {
return null;
}

Expand Down
39 changes: 10 additions & 29 deletions src/datasource/OGC.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {string}
* @private
*/
this.geometryName_ = options.geometryName ||
exports.DEFAULT_GEOMETRY_NAME_;
this.geometryName_ = options.geometryName || exports.DEFAULT_GEOMETRY_NAME_;

/**
* The type of images to fetch by queries by the (WMS) or (WMTS) .
Expand All @@ -122,8 +121,7 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {string}
* @private
*/
this.ogcServerType_ = options.ogcServerType ||
exports.ServerType.MAPSERVER;
this.ogcServerType_ = options.ogcServerType || exports.ServerType.MAPSERVER;

/**
* The type data source. Can be: 'WMS' or 'WMTS'.
Expand Down Expand Up @@ -164,8 +162,7 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {number}
* @private
*/
this.snappingTolerance_ = options.snappingTolerance !== undefined ?
options.snappingTolerance : 10;
this.snappingTolerance_ = options.snappingTolerance !== undefined ? options.snappingTolerance : 10;

/**
* The name of the time attribute.
Expand All @@ -184,8 +181,7 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {?ngeox.TimeProperty}
* @private
*/
this.timeProperty_ = options.timeProperty !== undefined ?
options.timeProperty : null;
this.timeProperty_ = options.timeProperty !== undefined ? options.timeProperty : null;

/**
* @type {number|undefined}
Expand All @@ -198,24 +194,21 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {string}
* @private
*/
this.wfsFeatureNS_ = options.wfsFeatureNS ||
exports.WFSFeatureNS[this.ogcServerType_];
this.wfsFeatureNS_ = options.wfsFeatureNS;

/**
* The feature prefix to use with WFS requests.
* @type {string}
* @private
*/
this.wfsFeaturePrefix_ = options.wfsFeaturePrefix ||
exports.WFSFeaturePrefix.FEATURE;
this.wfsFeaturePrefix_ = options.wfsFeaturePrefix || exports.WFSFeaturePrefix.FEATURE;

/**
* The OutputFormat to use with WFS requests.
* @type {string}
* @private
*/
this.wfsOutputFormat_ = options.wfsOutputFormat ||
exports.WFSOutputFormat.GML3;
this.wfsOutputFormat_ = options.wfsOutputFormat || exports.WFSOutputFormat.GML3;

/**
* The url to use for (WFS) requests.
Expand All @@ -229,8 +222,7 @@ const exports = class extends ngeoDatasourceDataSource {
* @type {string}
* @private
*/
this.wmsInfoFormat_ = options.wmsInfoFormat ||
exports.WMSInfoFormat.GML;
this.wmsInfoFormat_ = options.wmsInfoFormat || exports.WMSInfoFormat.GML;

/**
* Whether the (WMS) images returned by this data source
Expand Down Expand Up @@ -996,7 +988,7 @@ exports.guessServiceTypeByUrl = function(url) {
* @type {string}
* @private
*/
exports.DEFAULT_GEOMETRY_NAME_ = 'the_geom';
exports.DEFAULT_GEOMETRY_NAME_ = 'geom';


/**
Expand All @@ -1021,18 +1013,7 @@ exports.Type = {


/**
* Available Feature namespace for WFS requests.
* @const {Object.<string, string>}
*/
exports.WFSFeatureNS = {
'geoserver': 'http://www.opengis.net/gml/3.2',
'mapserver': 'http://mapserver.gis.umn.edu/mapserver',
'qgisserver': 'http://www.qgis.org/gml'
};


/**
* Available Feature namespace for WFS requests.
* Available Feature prefix for WFS requests.
* @enum {string}
*/
exports.WFSFeaturePrefix = {
Expand Down

0 comments on commit 975f362

Please sign in to comment.