From 4fa181baae921f8beeb326b2bcb93c18b489bb23 Mon Sep 17 00:00:00 2001 From: Laurent Lienher Date: Fri, 2 Mar 2018 10:45:53 +0100 Subject: [PATCH] Add maxzoom for permalink search --- contribs/gmf/src/controllers/abstract.js | 31 ------------------------ contribs/gmf/src/directives/search.js | 13 +++++++--- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/contribs/gmf/src/controllers/abstract.js b/contribs/gmf/src/controllers/abstract.js index 60ce1471e66e..09482b1ef551 100644 --- a/contribs/gmf/src/controllers/abstract.js +++ b/contribs/gmf/src/controllers/abstract.js @@ -22,8 +22,6 @@ goog.require('gmf.mapDirective'); /** @suppress {extraRequire} */ goog.require('gmf.searchDirective'); /** @suppress {extraRequire} */ -goog.require('gmf.FulltextSearchService'); -/** @suppress {extraRequire} */ goog.require('gmf.themeselectorDirective'); /** @suppress {extraRequire} */ goog.require('ngeo.BackgroundLayerMgr'); @@ -513,17 +511,6 @@ gmf.AbstractController = function(config, $scope, $injector) { cgxp.tools.openInfoWindow = function(url, title, opt_width, opt_height) { gmfx.openIframePopup(url, title, opt_width, opt_height); }; - - /** - * @private - */ - this.fullTextSearch_ = $injector.get('gmfFulltextSearchService'); - - const searchQuery = this.ngeoLocation.getParam('search'); - if (searchQuery) { - const overlay = ngeoFeatureOverlayMgr.getFeatureOverlay(); - this.search_(searchQuery, overlay); - } }; @@ -632,22 +619,4 @@ gmf.AbstractController.prototype.updateCurrentTheme_ = function(fallbackThemeNam }); }; -/** - * Performs a full-text search and centers the map on the first search result. - * @param {string} query Search query. - * @param {ngeo.FeatureOverlay} overlay Feature overlay to add the feature if found. - * @private - */ -gmf.AbstractController.prototype.search_ = function(query, overlay) { - this.fullTextSearch_.search(query, {'limit': 1}) - .then((data) => { - if (data && data.features[0]) { - const format = new ol.format.GeoJSON(); - const feature = format.readFeature(data.features[0]); - overlay.addFeature(feature); - this.map.getView().fit(feature.getGeometry().getExtent()); - } - }); -}; - gmf.module.controller('AbstractController', gmf.AbstractController); diff --git a/contribs/gmf/src/directives/search.js b/contribs/gmf/src/directives/search.js index acf0ad3cf36a..f66e0529a9ce 100644 --- a/contribs/gmf/src/directives/search.js +++ b/contribs/gmf/src/directives/search.js @@ -477,6 +477,9 @@ gmf.SearchController.prototype.$onInit = function() { if (this.ngeoLocation_.getParam('search-select-index')) { resultIndex = parseInt(this.ngeoLocation_.getParam('search-select-index'), 10); } + if (this.ngeoLocation_.getParam('search-maxzoom')) { + this.maxZoom = parseInt(this.ngeoLocation_.getParam('search-maxzoom'), 10) || 16; + } this.fulltextsearch_(searchQuery, resultIndex); } } @@ -899,8 +902,7 @@ gmf.SearchController.prototype.selectFromGMF_ = function(event, feature, dataset } } - const size = this.map_.getSize(); - if (featureGeometry && size) { + if (featureGeometry && this.map_.getSize()) { const view = this.map_.getView(); this.featureOverlay_.clear(); this.featureOverlay_.addFeature(feature); @@ -908,7 +910,7 @@ gmf.SearchController.prototype.selectFromGMF_ = function(event, feature, dataset const fitArray = featureGeometry.getType() === 'GeometryCollection' ? featureGeometry.getExtent() : featureGeometry; view.fit(fitArray, { - size, + size: this.map_.getSize(), maxZoom: this.maxZoom}); } this.leaveSearch_(); @@ -982,7 +984,10 @@ gmf.SearchController.prototype.fulltextsearch_ = function(query, resultIndex) { const format = new ol.format.GeoJSON(); const feature = format.readFeature(data.features[resultIndex - 1]); this.featureOverlay_.addFeature(feature); - this.map_.getView().fit(feature.getGeometry().getExtent()); + this.map_.getView().fit(feature.getGeometry().getExtent(), { + size: this.map_.getSize(), + maxZoom: this.maxZoom + }); this.inputValue = /** @type {string} */ (feature.get('label')); } });