Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hard code the snapping options #4318

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,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 @@ -458,12 +458,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 @@ -503,6 +500,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 @@ -91,8 +91,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 @@ -115,8 +114,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 @@ -157,8 +155,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 @@ -177,8 +174,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 @@ -191,24 +187,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 @@ -222,8 +215,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 @@ -964,7 +956,7 @@ exports.guessServiceTypeByUrl = function(url) {
* @type {string}
* @private
*/
exports.DEFAULT_GEOMETRY_NAME_ = 'the_geom';
exports.DEFAULT_GEOMETRY_NAME_ = 'geom';


/**
Expand All @@ -989,18 +981,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