MAPBOX JS

Hi Everyone. When I render a marker with specific coordinates on the map using MAPBOX, I want the map to automatically redirect to those coordinates, just like in Leaflet JS, which I am more familiar with. If you are aware of the set View function that exists in leaflet JS that's is what I am looking for. In any case, I'm hoping that MAPBOX has a comparable feature that I could use for my project.
8 Replies
Chris Bolson
Chris Bolson•14mo ago
I am not familiar with mapbox but a quick search came up with this:
map.flyTo({
center: [latidude, longitude]
});
map.flyTo({
center: [latidude, longitude]
});
Stefano
Stefano•14mo ago
your amazing chris thank you i must of not found it beacuse i searched a lot i guess different names
Chris Bolson
Chris Bolson•14mo ago
I agree that it isn't the most intuitive of function names. I would have thought something like setCenter() (with optional panning ) would have made more sense.
Stefano
Stefano•14mo ago
yeah i got it to work now figuring out how i can have it to zoom in not just fly to it
Chris Bolson
Chris Bolson•14mo ago
Amongst other options, flyTo() accepts a zoom:
map.flyTo({
center: [0, 0],
zoom: 9,
speed: 0.2,
curve: 1,
easing(t) {
return t;
}
});
map.flyTo({
center: [0, 0],
zoom: 9,
speed: 0.2,
curve: 1,
easing(t) {
return t;
}
});
https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto
Stefano
Stefano•14mo ago
your a G thank you
Chris Bolson
Chris Bolson•14mo ago
Actually, bearing in mind all those options, the naming isn't too bad 😆 Mapbox actually looks quite interesting - I might have to have a play with that when I get a moment.
Stefano
Stefano•14mo ago
yeah currently using it beacuase i just learned about promises so putting the info i know in a project with apis fetching and using .thens haha that's the only way i can truly understand a topic