Skip to content

Commit

Permalink
Add normalize flag (default true) to MapController
Browse files Browse the repository at this point in the history
  • Loading branch information
zakjan committed May 6, 2021
1 parent f784d65 commit 85de7b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/api-reference/core/map-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions modules/core/src/controllers/map-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -90,7 +93,8 @@ export class MapState extends ViewState {
maxZoom,
minZoom,
maxPitch,
minPitch
minPitch,
normalize
});

this._state = {
Expand Down Expand Up @@ -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));
//
const {normalize = true} = props;
if (normalize) {
Object.assign(props, normalizeViewportProps(props));
}

return props;
}
Expand Down

0 comments on commit 85de7b0

Please sign in to comment.