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

Method setMapParamsAsync

modules/core/MapSystem.js:613–646  ·  view source on GitHub ↗

* setMapParamsAsync * Promise-returning version of `setMapParams()` * @param loc2 Array [lon,lat] to set the center to * @param z2 Number to set the zoom to * @param r2 Number to set the rotation to (in radians) * @param duration? Duration of the transition

(loc2, z2, r2, duration = 0)

Source from the content-addressed store, hash-verified

611 * @return Promise that resolves when the transform has finished changing
612 */
613 setMapParamsAsync(loc2, z2, r2, duration = 0) {
614 const context = this.context;
615 const view1 = context.viewport;
616 const center = view1.center();
617 const loc1 = view1.centerLoc();
618 const t1 = view1.transform;
619 const z1 = t1.zoom;
620 const r1 = t1.r;
621
622 if (loc2 === undefined) loc2 = loc1;
623 if (z2 === undefined) z2 = z1;
624 if (r2 === undefined) r2 = r1;
625
626 // Bounds and precision checks
627 loc2[0] = numClamp(loc2[0] || 0, -180, 180);
628 loc2[1] = numClamp(loc2[1] || 0, -90, 90);
629 z2 = numClamp((+(z2 || 0).toFixed(2)), MIN_Z, MAX_Z);
630 r2 = numWrap((+(r2 || 0).toFixed(3)), 0, TAU); // radians
631
632 if (loc2[0] === loc1[0] && loc2[1] === loc1[1] && z2 === z1 && r2 === r1) { // nothing to do
633 return Promise.resolve(t1);
634 }
635
636 const k2 = geoZoomToScale(z2, TILESIZE);
637 const view2 = new Viewport(t1, view1.dimensions);
638 view2.transform.scale = k2;
639
640 let xy = view2.transform.translation;
641 const point = view2.project(loc2);
642 const delta = vecSubtract(center, point);
643 xy = vecAdd(xy, delta);
644
645 return this.setTransformAsync({ x: xy[0], y: xy[1], k: k2, r: r2 }, duration);
646 }
647
648
649 /**

Callers 15

addLineAsyncFunction · 0.80
drawLineAsyncFunction · 0.80
finishLineAsyncFunction · 0.80
updateLineAsyncFunction · 0.80
deleteLinesAsyncFunction · 0.80
navigationIntroAsyncFunction · 0.80
resetBearingAsyncFunction · 0.80
clickTownHallAsyncFunction · 0.80
searchStreetAsyncFunction · 0.80
selectedStreetAsyncFunction · 0.80
addPointAsyncFunction · 0.80
reselectPointAsyncFunction · 0.80

Calls 3

setTransformAsyncMethod · 0.95
centerMethod · 0.80
centerLocMethod · 0.80

Tested by

no test coverage detected