Comments (3)
You can use an example for Viewport Change Methods
from the map example page https://urbica.github.io/react-map-gl/#/Components/MapGL
from react-map-gl.
You can manipulate the viewport state with setViewport
, and that would be reflected in the map state, i.e., programmatic navigation.
const [viewport, setViewport] = useState({
latitude: 37.78,
longitude: -122.41,
zoom: 11
});
<button onClick={() => { setViewport({ zoom: viewport.zoom + 1 }) }}>
Zoom in
</button>
<MapGL
style={{ width: '100%', height: '400px' }}
mapStyle='mapbox://styles/mapbox/light-v9'
accessToken={MAPBOX_ACCESS_TOKEN}
latitude={viewport.latitude}
longitude={viewport.longitude}
zoom={viewport.zoom}
onViewportChange={setViewport}
/>;
I'd appreciate a PR with such an example in the docs if you want to contribute.
from react-map-gl.
Thanks @stepankuzmin – and then probably a Provider to pass the setter around?
import React, { useState, useContext } from 'react';
const SetViewportProvider = createContext({});
export const useSetViewportProvider = () => useContext(SetViewportProvider);
<Map>
<SetViewportProvider.Provider value={setViewport}>
{children}
</SetViewportProvider.Provider>
</Map>
import { useSetViewportProvider } from './Map';
const setter = useSetViewportProvider();
<button onClick={() => setter((oldstate) => ({ ...oldstate, zoom: 10 }))} />
It looks like changing the zoom level via this technique jumps in immediately without any easing/animation, despite AnimationOptions being set. Is this expected?
from react-map-gl.
Related Issues (20)
- Replace 'require' statement with 'import' HOT 2
- Add fitBoundsOptions to MapGL component HOT 1
- Forward className and style to div.mapboxgl-marker element in Marker component
- [Question] Full example code HOT 1
- How to get current zoom level of the map? HOT 2
- sourceCaches has been renamed in mapbox-gl
- Padding in flyTo for customLayer is unfit
- [Request] heatmap not responding to zoom?
- [Request] add support for new cooperativeGestures option
- Source component does not support cluster properties
- How to custom control panel in draw
- Zoom Control
- Add 3D terrain to a map HOT 2
- Incompatibility with Vitejs HOT 5
- Wrong typing for <Marker> component HOT 1
- Error Source cannot be removed while layer using it
- More than 16 maps on a page // Callback if browser invalidates WebGL context
- Popup not rendering on click
- Question: How to implement user interaction with layers HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-map-gl.