Skip to content

Commit

Permalink
Add maxzoom for permalink search
Browse files Browse the repository at this point in the history
  • Loading branch information
llienher committed Mar 12, 2018
1 parent 2f7a064 commit 4fa181b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 35 deletions.
31 changes: 0 additions & 31 deletions contribs/gmf/src/controllers/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
};


Expand Down Expand Up @@ -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);
13 changes: 9 additions & 4 deletions contribs/gmf/src/directives/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -899,16 +902,15 @@ 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);
this.displayColorPicker = true;
const fitArray = featureGeometry.getType() === 'GeometryCollection' ?
featureGeometry.getExtent() : featureGeometry;
view.fit(fitArray, {
size,
size: this.map_.getSize(),
maxZoom: this.maxZoom});
}
this.leaveSearch_();
Expand Down Expand Up @@ -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'));
}
});
Expand Down

0 comments on commit 4fa181b

Please sign in to comment.