diff --git a/contribs/gmf/apps/oeedit/index.html b/contribs/gmf/apps/oeedit/index.html index 726b9a1ae003..b7a86d80b0c7 100644 --- a/contribs/gmf/apps/oeedit/index.html +++ b/contribs/gmf/apps/oeedit/index.html @@ -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', diff --git a/contribs/gmf/options/gmfx.js b/contribs/gmf/options/gmfx.js index dde2aee5f5ad..bd3c8cc5c3a2 100644 --- a/contribs/gmf/options/gmfx.js +++ b/contribs/gmf/options/gmfx.js @@ -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.|undefined), - * useLocalStorage: (boolean|undefined) + * useLocalStorage: (boolean|undefined), + * pointRecenterZoom: (number|undefined) * }} */ gmfx.PermalinkOptions; @@ -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. diff --git a/contribs/gmf/src/services/permalink.js b/contribs/gmf/src/services/permalink.js index d287f8355dfa..b35b7d5a0c3e 100644 --- a/contribs/gmf/src/services/permalink.js +++ b/contribs/gmf/src/services/permalink.js @@ -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'); @@ -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 @@ -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) {