MCPcopy Create free account
hub / github.com/facebook/Rapid / _map3dmoved

Method _map3dmoved

modules/core/Map3dSystem.js:360–387  ·  view source on GitHub ↗

* _map3dmoved * Respond to changes in the 3d map, for example if the user interacts with it. * Update zoom and bearing offsets from main map, and recenter the main map if needed.

()

Source from the content-addressed store, hash-verified

358 * Update zoom and bearing offsets from main map, and recenter the main map if needed.
359 */
360 _map3dmoved() {
361 const context = this.context;
362 const maplibre = this.maplibre;
363 const map = context.systems.map;
364 const viewport = context.viewport;
365 const transform = viewport.transform;
366
367 if (!maplibre) return; // called too early?
368 if (!this._lastv) return; // haven't positioned the map yet (it may be at null island), Rapid#1441
369
370 const mlCenter = maplibre.getCenter();
371 const mlCenterLoc = [mlCenter.lng, mlCenter.lat];
372 const mlZoom = maplibre.getZoom();
373 const mlBearing = maplibre.getBearing();
374
375 const mainCenterLoc = viewport.centerLoc();
376 const mainZoom = transform.zoom;
377 // Why a '-' here? Because "bearing" is the angle that the user points, not the angle that north points.
378 const mainBearing = numWrap(-transform.rotation * RAD2DEG, 0, 360);
379
380 this._zDiff = mainZoom - mlZoom;
381 this._bDiff = mainBearing - mlBearing;
382
383 // Recenter main map, if 3dmap center moved
384 if (!vecEqual(mainCenterLoc, mlCenterLoc, 1e-6)) {
385 map.center(mlCenterLoc);
386 }
387 }
388
389
390 /**

Callers

nothing calls this directly

Calls 2

centerLocMethod · 0.80
centerMethod · 0.80

Tested by

no test coverage detected