MCPcopy
hub / github.com/visgl/deck.gl / getViewState

Function getViewState

modules/mapbox/src/deck-utils.ts:183–220  ·  view source on GitHub ↗
(map: Map)

Source from the content-addressed store, hash-verified

181}
182
183export function getViewState(map: Map): MapViewState & {
184 repeat: boolean;
185 padding: {
186 left: number;
187 right: number;
188 top: number;
189 bottom: number;
190 };
191} {
192 const {lng, lat} = map.getCenter();
193
194 const viewState: MapViewState & {
195 repeat: boolean;
196 padding: {
197 left: number;
198 right: number;
199 top: number;
200 bottom: number;
201 };
202 } = {
203 // Longitude returned by getCenter can be outside of [-180, 180] when zooming near the anti meridian
204 // https://github.com/visgl/deck.gl/issues/6894
205 longitude: ((lng + 540) % 360) - 180,
206 latitude: lat,
207 zoom: map.getZoom(),
208 bearing: map.getBearing(),
209 pitch: map.getPitch(),
210 padding: map.getPadding(),
211 repeat: map.getRenderWorldCopies()
212 };
213
214 if (map.getTerrain?.()) {
215 // When the base map has terrain, we need to target the camera at the terrain surface
216 centerCameraOnTerrain(map, viewState);
217 }
218
219 return viewState;
220}
221
222function centerCameraOnTerrain(map: Map, viewState: MapViewState) {
223 if (map.getFreeCameraOptions) {

Callers 5

_onAddOverlaidMethod · 0.90
MapboxOverlayClass · 0.90
getDeckInstanceFunction · 0.70
getViewportFunction · 0.70
onMapMoveFunction · 0.70

Calls 8

centerCameraOnTerrainFunction · 0.85
getTerrainMethod · 0.80
getCenterMethod · 0.65
getZoomMethod · 0.65
getBearingMethod · 0.65
getPitchMethod · 0.65
getPaddingMethod · 0.65
getRenderWorldCopiesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…