Skip to content

Commit

Permalink
Add max-zoom setting for point geometries for oedit permalinks (#4279)
Browse files Browse the repository at this point in the history
* Add pointRecenterZoom property to gmfPermalinkOptions

* Example usage of pointRecenterZoom
  • Loading branch information
pfirpfel authored Oct 2, 2018
1 parent 31d3225 commit 1fbc303
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions contribs/gmf/apps/oeedit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@
{action: 'add_layer', title: 'Add a layer'}
]);
module.constant('gmfContextualdatacontentTemplateUrl', window.location.pathname + 'contextualdata.html');
module.value('gmfPermalinkOptions',
/** @type {gmfx.PermalinkOptions} */ ({
pointRecenterZoom: 10
}));
module.value('ngeoWfsPermalinkOptions',
/** @type {ngeox.WfsPermalinkOptions} */ ({
url: 'https://geomapfish-demo.camptocamp.net/2.2/wsgi/mapserv_proxy',
Expand Down
11 changes: 10 additions & 1 deletion contribs/gmf/options/gmfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ gmfx.ObjectEditingToolsOptions.prototype.regularPolygonRadius;
* crosshairStyle: (Array<(null|ol.style.Style)>|null|ol.FeatureStyleFunction|ol.style.Style|undefined),
* crosshairEnabledByDefault: (boolean|undefined),
* projectionCodes: (Array.<string>|undefined),
* useLocalStorage: (boolean|undefined)
* useLocalStorage: (boolean|undefined),
* pointRecenterZoom: (number|undefined)
* }}
*/
gmfx.PermalinkOptions;
Expand Down Expand Up @@ -207,6 +208,14 @@ gmfx.PermalinkOptions.prototype.projectionCodes;
gmfx.PermalinkOptions.prototype.useLocalStorage;


/**
* Zoom level to use when result is a single point feature. If not set the map
* is not zoomed to a specific zoom level.
* @type {number|undefined}
*/
gmfx.PermalinkOptions.prototype.pointRecenterZoom


/**
* Fields that can come from a print v3 server and can be used in the partial
* of the gmf print panel.
Expand Down
19 changes: 17 additions & 2 deletions contribs/gmf/src/services/permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ goog.require('ngeo.WfsPermalink');
goog.require('goog.asserts');
goog.require('ol.Feature');
goog.require('ol.geom.Point');
goog.require('ol.geom.MultiPoint');
goog.require('ol.proj');
goog.require('ol.style.Stroke');
goog.require('ol.style.RegularShape');
Expand Down Expand Up @@ -187,6 +188,12 @@ gmf.Permalink = function($timeout, $rootScope, $injector, ngeoDebounce, gettextC
*/
this.crosshairEnabledByDefault_ = !!gmfPermalinkOptions.crosshairEnabledByDefault;

/**
* @type {number|undefined}
* @private
*/
this.pointRecenterZoom_ = gmfPermalinkOptions.pointRecenterZoom;

/**
* @type {?gmf.Themes}
* @private
Expand Down Expand Up @@ -698,10 +705,18 @@ gmf.Permalink.prototype.registerMap_ = function(map, oeFeature) {
// (1) Initialize the map view with either:
// a) the given ObjectEditing feature
// b) the X, Y and Z available within the permalink service, if available
if (oeFeature && oeFeature.getGeometry()) {
const geom = typeof oeFeature !== 'undefined' && oeFeature !== null ? oeFeature.getGeometry() : undefined;
if (geom) {
const size = map.getSize();
goog.asserts.assert(size);
view.fit(oeFeature.getGeometry().getExtent(), size);
let maxZoom;
if (geom instanceof ol.geom.Point || geom instanceof ol.geom.MultiPoint) {
maxZoom = this.pointRecenterZoom_;
}
view.fit(geom.getExtent(), {
size,
maxZoom
});
} else {
center = this.getMapCenter();
if (center) {
Expand Down

0 comments on commit 1fbc303

Please sign in to comment.