Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve map_zoom setting when using search parameter #3001

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions contribs/gmf/src/directives/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ gmf.SearchController.prototype.$onInit = function() {
if (this.ngeoLocation_.getParam('search-select-index')) {
resultIndex = parseInt(this.ngeoLocation_.getParam('search-select-index'), 10);
}
this.fulltextsearch_(searchQuery, resultIndex);
let mapZoom = null;
if (this.ngeoLocation_.getParam('map_zoom')) {
mapZoom = parseInt(this.ngeoLocation_.getParam('map_zoom'), 10);
}
this.fulltextsearch_(searchQuery, resultIndex, mapZoom);
}
}
};
Expand Down Expand Up @@ -947,9 +951,10 @@ gmf.SearchController.datasetsempty_ = function(event, query, empty) {
* Performs a full-text search and centers the map on the first search result.
* @param {string} query Search query.
* @param {number} resultIndex Return nth result instead.
* @param {?number} opt_zoom Optional zoom level.
* @private
*/
gmf.SearchController.prototype.fulltextsearch_ = function(query, resultIndex) {
gmf.SearchController.prototype.fulltextsearch_ = function(query, resultIndex, opt_zoom) {
if (resultIndex < 1) { // can't be lower than one
resultIndex = 1;
}
Expand All @@ -959,7 +964,11 @@ 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());
const fitOptions = /** @type {olx.view.FitOptions} */ ({});
if (opt_zoom) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that the zoom can be 0 but in the case the test will be false.
Should be changed to if (opt_zoom !== undefined) {

fitOptions.maxZoom = opt_zoom;
}
this.map_.getView().fit(feature.getGeometry().getExtent(), fitOptions);
this.inputValue = /** @type {string} */ (feature.get('label'));
}
});
Expand Down