Giter VIP home page Giter VIP logo

Comments (3)

stepankuzmin avatar stepankuzmin commented on June 1, 2024 1

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.

stepankuzmin avatar stepankuzmin commented on June 1, 2024

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.

braco avatar braco commented on June 1, 2024

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)

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.