Skip to content

Commit

Permalink
Merge pull request #3096 from camptocamp/use_metadata_resolution
Browse files Browse the repository at this point in the history
Allow to zoom with resolutions in metadata
  • Loading branch information
ger-benjamin authored Nov 15, 2017
2 parents 0fc51df + a6ed452 commit 8f253ee
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 23 deletions.
55 changes: 32 additions & 23 deletions contribs/gmf/src/directives/layertree.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,24 +354,6 @@ gmf.LayertreeController.prototype.listeners = function(scope, treeCtrl) {
};


/**
* Return 'out-of-resolution' if the current resolution of the map is out of
* the min/max resolution in the node.
* @param {gmfThemes.GmfLayerWMS} gmfLayerWMS the GeoMapFish Layer WMS.
* @return {string|undefined} 'out-of-resolution' or undefined.
* @export
*/
gmf.LayertreeController.prototype.getResolutionStyle = function(gmfLayerWMS) {
var style;
var resolution = this.map.getView().getResolution();
if (gmfLayerWMS.minResolutionHint !== undefined && resolution < gmfLayerWMS.minResolutionHint ||
gmfLayerWMS.maxResolutionHint !== undefined && resolution > gmfLayerWMS.maxResolutionHint) {
style = 'out-of-resolution';
}
return style;
};


/**
* Toggle the state of treeCtrl's node.
* @param {ngeo.LayertreeController} treeCtrl ngeo layertree controller, from
Expand Down Expand Up @@ -585,6 +567,30 @@ gmf.LayertreeController.prototype.removeNode = function(node) {
};


/**
* Return 'out-of-resolution' if the current resolution of the map is out of
* the min/max resolution in the node.
* @param {gmfThemes.GmfLayerWMS} gmfLayer the GeoMapFish Layer. WMTS layer is
* also allowed (the type is defined as GmfLayerWMS only to avoid some
* useless tests to know if a minResolutionHint property can exist
* on the node).
* @return {string|undefined} 'out-of-resolution' or undefined.
* @export
*/
gmf.LayertreeController.prototype.getResolutionStyle = function(gmfLayer) {
var resolution = this.map.getView().getResolution();
var minResolution = gmf.Themes.getNodeMinResolution(gmfLayer);
if (minResolution !== undefined && resolution < minResolution) {
return 'out-of-resolution';
}
var maxResolution = gmf.Themes.getNodeMaxResolution(gmfLayer);
if (maxResolution !== undefined && resolution > maxResolution) {
return 'out-of-resolution';
}
return undefined;
};


/**
* Set the resolution of the map with the max or min resolution of the node.
* @param {ngeo.LayertreeController} treeCtrl ngeo layertree controller, from
Expand All @@ -595,11 +601,14 @@ gmf.LayertreeController.prototype.zoomToResolution = function(treeCtrl) {
var gmfLayer = /** @type {gmfThemes.GmfLayerWMS} */ (treeCtrl.node);
var view = this.map.getView();
var resolution = view.getResolution();
if (gmfLayer.minResolutionHint !== undefined && resolution < gmfLayer.minResolutionHint) {
view.setResolution(view.constrainResolution(gmfLayer.minResolutionHint, 0, 1));
}
if (gmfLayer.maxResolutionHint !== undefined && resolution > gmfLayer.maxResolutionHint) {
view.setResolution(view.constrainResolution(gmfLayer.maxResolutionHint, 0, -1));
var minResolution = gmf.Themes.getNodeMinResolution(gmfLayer);
if (minResolution !== undefined && resolution < minResolution) {
view.setResolution(view.constrainResolution(minResolution, 0, 1));
} else {
var maxResolution = gmf.Themes.getNodeMaxResolution(gmfLayer);
if (maxResolution !== undefined && resolution > maxResolution) {
view.setResolution(view.constrainResolution(maxResolution, 0, -1));
}
}
};

Expand Down
38 changes: 38 additions & 0 deletions contribs/gmf/src/services/themesservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,44 @@ gmf.Themes.prototype.hasNodeEditableLayers_ = function(node) {
};


/**
* Get the maximal resolution defined for this layer. Looks in the
* layer itself before to look into its metadata.
* @param {gmfThemes.GmfLayerWMS} gmfLayer the GeoMapFish Layer. WMTS layer is
* also allowed (the type is defined as GmfLayerWMS only to avoid some
* useless tests to know if a maxResolutionHint property can exist
* on the node).
* @return {number|undefined} the max resolution or undefined if any.
*/
gmf.Themes.getNodeMaxResolution = function(gmfLayer) {
var metadata = gmfLayer.metadata;
var maxResolution = gmfLayer.maxResolutionHint;
if (maxResolution === undefined && metadata !== undefined) {
maxResolution = metadata.maxResolution;
}
return maxResolution;
};


/**
* Get the minimal resolution defined for this layer. Looks in the
* layer itself before to look into its metadata.
* @param {gmfThemes.GmfLayerWMS} gmfLayer the GeoMapFish Layer. WMTS layer is
* also allowed (the type is defined as GmfLayerWMS only to avoid some
* useless tests to know if a minResolutionHint property can exist
* on the node).
* @return {number|undefined} the min resolution or undefined if any.
*/
gmf.Themes.getNodeMinResolution = function(gmfLayer) {
var metadata = gmfLayer.metadata;
var minResolution = gmfLayer.minResolutionHint;
if (minResolution === undefined && metadata !== undefined) {
minResolution = metadata.minResolution;
}
return minResolution;
};


/**
* @param {number=} opt_roleId The role id to send in the request.
* Load themes from the "themes" service.
Expand Down

0 comments on commit 8f253ee

Please sign in to comment.