* setMapParams * Set loc, zoom, and rotation at the same time. * @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 in mi
(loc2, z2, r2, duration = 0)
| 566 | * @return this |
| 567 | */ |
| 568 | setMapParams(loc2, z2, r2, duration = 0) { |
| 569 | const context = this.context; |
| 570 | const view1 = context.viewport; |
| 571 | const center = view1.center(); |
| 572 | const loc1 = view1.centerLoc(); |
| 573 | const t1 = view1.transform; |
| 574 | const z1 = t1.zoom; |
| 575 | const r1 = t1.r; |
| 576 | |
| 577 | if (loc2 === undefined) loc2 = loc1; |
| 578 | if (z2 === undefined) z2 = z1; |
| 579 | if (r2 === undefined) r2 = r1; |
| 580 | |
| 581 | // Bounds and precision checks |
| 582 | loc2[0] = numClamp(loc2[0] || 0, -180, 180); |
| 583 | loc2[1] = numClamp(loc2[1] || 0, -90, 90); |
| 584 | z2 = numClamp((+(z2 || 0).toFixed(2)), MIN_Z, MAX_Z); |
| 585 | r2 = numWrap((+(r2 || 0).toFixed(3)), 0, TAU); // radians |
| 586 | |
| 587 | if (loc2[0] === loc1[0] && loc2[1] === loc1[1] && z2 === z1 && r2 === r1) { // nothing to do |
| 588 | return this; |
| 589 | } |
| 590 | |
| 591 | const k2 = geoZoomToScale(z2, TILESIZE); |
| 592 | const view2 = new Viewport(t1, view1.dimensions); |
| 593 | view2.transform.scale = k2; |
| 594 | |
| 595 | let xy = view2.transform.translation; |
| 596 | const point = view2.project(loc2); |
| 597 | const delta = vecSubtract(center, point); |
| 598 | xy = vecAdd(xy, delta); |
| 599 | |
| 600 | return this.transform({ x: xy[0], y: xy[1], k: k2, r: r2 }, duration); |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /** |
no test coverage detected