From 0ef0e2871549c261fafc5bac7a80b0d837a0d1fd Mon Sep 17 00:00:00 2001 From: Jan Zak Date: Wed, 5 May 2021 14:19:37 +0200 Subject: [PATCH] Add normalize flag (default true) to MapController --- docs/api-reference/core/map-controller.md | 1 + modules/core/src/controllers/map-controller.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/api-reference/core/map-controller.md b/docs/api-reference/core/map-controller.md index ec4ba95df30..1f2515fdcb9 100644 --- a/docs/api-reference/core/map-controller.md +++ b/docs/api-reference/core/map-controller.md @@ -38,6 +38,7 @@ Supports all [Controller options](/docs/api-reference/core/controller.md#options - `dragMode` - default `'pan'` (drag to pan, shift/ctrl + drag to rotate) - `keyboard` - arrow keys to pan, arrow keys with shift/ctrl down to rotate, +/- to zoom +- `normalize` - normalize viewport props to fit map height into viewport. Default `true` ## Custom MapController diff --git a/modules/core/src/controllers/map-controller.js b/modules/core/src/controllers/map-controller.js index 34a85c2fec4..97d5114fe0b 100644 --- a/modules/core/src/controllers/map-controller.js +++ b/modules/core/src/controllers/map-controller.js @@ -72,7 +72,10 @@ export class MapState extends ViewState { /** Pitch when current perspective rotate operation started */ startPitch, /** Zoom when current zoom operation started */ - startZoom + startZoom, + + /** Normalize viewport props to fit map height into viewport, default enabled */ + normalize } = {}) { assert(Number.isFinite(longitude)); // `longitude` must be supplied assert(Number.isFinite(latitude)); // `latitude` must be supplied @@ -90,7 +93,8 @@ export class MapState extends ViewState { maxZoom, minZoom, maxPitch, - minPitch + minPitch, + normalize }); this._state = { @@ -356,7 +360,11 @@ export class MapState extends ViewState { const {maxPitch, minPitch, pitch} = props; props.pitch = clamp(pitch, minPitch, maxPitch); - Object.assign(props, normalizeViewportProps(props)); + // Normalize viewport props to fit map height into viewport + const {normalize = true} = props; + if (normalize) { + Object.assign(props, normalizeViewportProps(props)); + } return props; }