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

add a pointzoom feature like the mapbox.js geocoder #33

Closed
ckc11 opened this issue Mar 17, 2016 · 1 comment
Closed

add a pointzoom feature like the mapbox.js geocoder #33

ckc11 opened this issue Mar 17, 2016 · 1 comment

Comments

@ckc11
Copy link

ckc11 commented Mar 17, 2016

If the geocoder returns a result without a bbox object, the map just centers the map on the result, and if the current zoom level is very low (i.e. zoomed out) then the centering of the map on the search result isn't very helpful. It would be great to implement a minimum zoom level for a point result that does not have an associated bbox.

The mapbox.js library is currently using a pointZoom option of 16.

options: {
        proximity: true,
        position: 'topleft',
        pointZoom: 16,
        keepOpen: false,
        autocomplete: false
    }

and using it in the chooseResult function:

if (result.bbox) {
    this._map.fitBounds(util.lbounds(result.bbox));
} else if (result.center) {
    this._map.setView([result.center[1], result.center[0]], (this._map.getZoom() === undefined) ?
        this.options.pointZoom :
        Math.max(this._map.getZoom(), this.options.pointZoom));
}

so it can be easily added to the change event on the "flyTo" instead of just centering:

input.addEventListener('change', function() {
  var selected = this._typeahead.selected;
  if (selected) {
    if (this.options.flyTo) {
      if (selected.bbox && selected.context <= 3) {
        var bbox = selected.bbox;
        map.fitBounds([[bbox[0], bbox[1]],[bbox[2], bbox[3]]]);
      } else {
        map.flyTo({ center: selected.center });
      }
    }
    this._input = selected;
    this.fire('result', { result: selected });
  }
}.bind(this));
@tristen
Copy link
Member

tristen commented Mar 25, 2016

@ckc11 👍 up for putting this together in a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants