* Rotate * @param {[Number, Number]} pos - position on screen where the center is
({
pos,
deltaAngleX = 0,
deltaAngleY = 0
}: {
pos?: [number, number];
deltaAngleX?: number;
deltaAngleY?: number;
})
| 255 | * @param {[Number, Number]} pos - position on screen where the center is |
| 256 | */ |
| 257 | rotate({ |
| 258 | pos, |
| 259 | deltaAngleX = 0, |
| 260 | deltaAngleY = 0 |
| 261 | }: { |
| 262 | pos?: [number, number]; |
| 263 | deltaAngleX?: number; |
| 264 | deltaAngleY?: number; |
| 265 | }): MapState { |
| 266 | const {startRotatePos, startRotateLngLat, startBearing, startPitch} = this.getState(); |
| 267 | |
| 268 | if (!startRotatePos || startBearing === undefined || startPitch === undefined) { |
| 269 | return this; |
| 270 | } |
| 271 | let newRotation; |
| 272 | if (pos) { |
| 273 | newRotation = this._getNewRotation(pos, startRotatePos, startPitch, startBearing); |
| 274 | } else { |
| 275 | newRotation = { |
| 276 | bearing: startBearing + deltaAngleX, |
| 277 | pitch: startPitch + deltaAngleY |
| 278 | }; |
| 279 | } |
| 280 | |
| 281 | // If we have a pivot point, adjust the camera position to keep the pivot point fixed |
| 282 | if (startRotateLngLat) { |
| 283 | const rotatedViewport = this.makeViewport({ |
| 284 | ...this.getViewportProps(), |
| 285 | ...newRotation |
| 286 | }); |
| 287 | // Use panByPosition3D if available (WebMercatorViewport), otherwise fall back to panByPosition |
| 288 | const panMethod = 'panByPosition3D' in rotatedViewport ? 'panByPosition3D' : 'panByPosition'; |
| 289 | return this._getUpdatedState({ |
| 290 | ...newRotation, |
| 291 | ...rotatedViewport[panMethod](startRotateLngLat, startRotatePos) |
| 292 | }); |
| 293 | } |
| 294 | |
| 295 | return this._getUpdatedState(newRotation); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * End rotating |
nothing calls this directly
no test coverage detected