React-map-gl: Viewport Transition Offsets

Created on 22 Jun 2018  路  2Comments  路  Source: visgl/react-map-gl

Current map transition methods like panTo allow specifying a pixel based offset which is applied to the animation final destination point. Looking at the docs, I can't seem to find any equivalent option with viewport transition to do this. Would be nice to include this feature for UI's that have overlaying panels which requires offsetting the map's center.

Anyone know of a workaround for this?

Most helpful comment

@Pessimistress

Where do you find the numbers for the bounds? (i.e [[-73.9876, 40.7661], [-72.9876, 41.7661]]) ?

All 2 comments

Use the fitBounds utility:

import WebMercatorViewport from 'viewport-mercator-project';
const viewport = new WebMercatorViewport({width: 600, height: 400});
const bound = viewport.fitBounds(
  [[-73.9876, 40.7661], [-72.9876, 41.7661]],
  {padding: 20, offset: [0, -40]}
);
// => bounds: instance of WebMercatorViewport
// {longitude: -73.48760000000007, latitude: 41.268014439447484, zoom: 7.209231188444142}

Then you can trigger a transition to the returned lng/lat/zoom.

@Pessimistress

Where do you find the numbers for the bounds? (i.e [[-73.9876, 40.7661], [-72.9876, 41.7661]]) ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nip10 picture nip10  路  4Comments

miccferr picture miccferr  路  4Comments

ckalas picture ckalas  路  5Comments

AriLFrankel picture AriLFrankel  路  3Comments

bogdancaspar picture bogdancaspar  路  3Comments