From 1d945999811fa917565c74b09552aa5d305390ca Mon Sep 17 00:00:00 2001 From: Michael Kuenzli Date: Fri, 28 Sep 2018 09:10:49 +0200 Subject: [PATCH 1/3] Add pointRecenterZoom property to gmfPermalinkOptions --- contribs/gmf/options/gmfx.js | 11 ++++++++++- contribs/gmf/src/services/permalink.js | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/contribs/gmf/options/gmfx.js b/contribs/gmf/options/gmfx.js index dde2aee5f5ad..0bc3aadd1991 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..427f185e6796 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 @@ -700,8 +707,16 @@ gmf.Permalink.prototype.registerMap_ = function(map, oeFeature) { // b) the X, Y and Z available within the permalink service, if available if (oeFeature && oeFeature.getGeometry()) { const size = map.getSize(); + const geom = oeFeature.getGeometry(); 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) { From a0013ccde26aec8dbf4d4dd0ba92a2c1464f8742 Mon Sep 17 00:00:00 2001 From: Michael Kuenzli Date: Mon, 1 Oct 2018 10:26:18 +0200 Subject: [PATCH 2/3] Example usage of pointRecenterZoom --- contribs/gmf/apps/oeedit/index.html | 4 ++++ 1 file changed, 4 insertions(+) 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', From 6f3d7da9bea4ebd63a32d091a15a157a7604e90c Mon Sep 17 00:00:00 2001 From: Michael Kuenzli Date: Mon, 1 Oct 2018 11:08:26 +0200 Subject: [PATCH 3/3] PR feedback --- contribs/gmf/options/gmfx.js | 2 +- contribs/gmf/src/services/permalink.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contribs/gmf/options/gmfx.js b/contribs/gmf/options/gmfx.js index 0bc3aadd1991..bd3c8cc5c3a2 100644 --- a/contribs/gmf/options/gmfx.js +++ b/contribs/gmf/options/gmfx.js @@ -172,7 +172,7 @@ gmfx.ObjectEditingToolsOptions.prototype.regularPolygonRadius; * crosshairEnabledByDefault: (boolean|undefined), * projectionCodes: (Array.|undefined), * useLocalStorage: (boolean|undefined), - * pointRecenterZoom: (number|undefined), + * pointRecenterZoom: (number|undefined) * }} */ gmfx.PermalinkOptions; diff --git a/contribs/gmf/src/services/permalink.js b/contribs/gmf/src/services/permalink.js index 427f185e6796..b35b7d5a0c3e 100644 --- a/contribs/gmf/src/services/permalink.js +++ b/contribs/gmf/src/services/permalink.js @@ -705,9 +705,9 @@ 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(); - const geom = oeFeature.getGeometry(); goog.asserts.assert(size); let maxZoom; if (geom instanceof ol.geom.Point || geom instanceof ol.geom.MultiPoint) {