Coder Social home page Coder Social logo

Comments (8)

SamSamskies avatar SamSamskies commented on June 12, 2024 1

@mark-rodgers just published v1.8.0. Now you should be able to just do this and the weird behavior of the viewport updating even when passing a noop to onViewportChange is gone. I may not have to make a version 2 after all. 😄

handleGeocoderResult = result => {
  this.setState({
    searchLngLat: result.result.center
  });
};

<Geocoder
  mapRef={this.mapRef}
  onResult={this.handleGeocoderResult}
  mapboxApiAccessToken={"***"}/>

Let me know if you have any other problems.

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on June 12, 2024

Hi @mark-rodgers, sorry, but I don't think that's possible. You'll probably need to build a custom component to do that using the Mapbox geocoding API. https://docs.mapbox.com/api/search/#geocoding

You could prob borrow a lot of code from https://github.com/mapbox/mapbox-gl-geocoder/blob/master/lib/index.js

from react-map-gl-geocoder.

easherma avatar easherma commented on June 12, 2024

@mark-rodgers if you can access all the config settings from the geocoder-api, you can set flyTo to be false, which should do what you are looking for, no?
https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on June 12, 2024

@easherma you can actually pass flyTo down as a prop, but unfortunately that only prevents the animation from happening. It will still go to the location that is searched for.

Ideally, this component shouldn't move if you pass in a noop as the onViewportChange prop value. However, since I'm using the mapbox-gl-geocoder object to do most of the heavy lifting, I don't think that's possible. If I ever get around to writing a version 2 of this component, I plan to remove the mapbox-gl-geocoder dependency. Then I'd be able to get rid of this unexpected behavior.

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on June 12, 2024

@easherma you're actually right. I misunderstood how flyTo works. Sorry, I'm a dummy.

@mark-rodgers You have to set flyTo to false and also pass in a noop to onViewportChange.

handleGeocoderResult = result => {
  this.setState({
    searchLngLat: result.result.center
  });
};

<Geocoder
  mapRef={this.mapRef}
  onViewportChange={() => {}}
  flyTo={false}
  onResult={this.handleGeocoderResult}
  mapboxApiAccessToken={"***"}/>

from react-map-gl-geocoder.

SamSamskies avatar SamSamskies commented on June 12, 2024

@mark-rodgers I'm going to remove the flyTo param as that should always be false. This is a bug in my code due to my misunderstanding of what the flyTo option does. onViewportChange should be the only way to update the viewport. I'll also default onViewportChange to a noop. That way you won't even need to provide those props.

from react-map-gl-geocoder.

mark-rodgers avatar mark-rodgers commented on June 12, 2024

Awesome! I’ll checkout the latest release soon, I’m sure this update will be useful to many!

from react-map-gl-geocoder.

easherma avatar easherma commented on June 12, 2024

from react-map-gl-geocoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.