Fly to diffrent location
I have given center point to map. After API call I want to change the center coordinates of map. How can I do? I'm using deck gl over mapbox gl and typescript and Vue language.See the bellow code. `initMap() { mapboxgl.accessToken = MAPBOX_TOKEN; this.map = new mapboxgl.Map({ container: 'mapbox-map', interactive: false, style: "mapbox://styles/mapbox/light-v10", center: [INITIAL_VIEW_STATE.longitude, INITIAL_VIEW_STATE.latitude], zoom: INITIAL_VIEW_STATE.zoom, pitch: INITIAL_VIEW_STATE.pitch, bearing: INITIAL_VIEW_STATE.bearing }) this.map.on('style.load', () => { this.initDeck(); }) }
initDeck() {
this.deck = new Deck({
canvas: 'deck-canvas',
width: '100%',
height: '100%',
initialViewState: INITIAL_VIEW_STATE,
controller: true,
onViewStateChange: ({ viewState, interactionState }) => {
this.map.jumpTo({
center: [viewState.longitude, viewState.latitude],
zoom: viewState.zoom,
pitch: viewState.pitch,
bearing: viewState.bearing
});
if (interactionState.isZooming) {
this.zoomLevelChanged(viewState);
}
},
})
}`
and want to change from
@Watch('center') changeMapCenter(value: [number, number]) {
// set new center point of map
}
I found a solution.
@Watch('center') changeMapCenter(value: [number, number]) {
if (value && value.length > 0) {
this.map.flyTo({ center: this.center });
this.deck.viewState = {
longitude: value[0],
latitude: value[1],
...INITIAL_VIEW_STATE,
transitionDuration: 1000,
transitionInterpolator: new FlyToInterpolator(),
};
}
}