Skip to content

Commit

Permalink
feat(view): add maxZoomOnExtent options to restrict the zoom level af…
Browse files Browse the repository at this point in the history
…ter a set extent
  • Loading branch information
mbarbeau committed Feb 3, 2020
1 parent 583e908 commit 74fae5a
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 156 deletions.
20 changes: 14 additions & 6 deletions packages/geo/src/lib/map/shared/controllers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export class MapViewController extends MapController {
*/
state$ = new BehaviorSubject<MapViewState>(undefined);

/**
* View Padding
*/
padding = [0, 0, 0, 0];

/**
* Max zoom after set extent
*/
maxZoomOnExtent = 19;

/**
* Extent stream
*/
Expand All @@ -52,11 +62,6 @@ export class MapViewController extends MapController {
*/
private stateIndex: number = 0;

/**
* View Padding
*/
padding = [0, 0, 0, 0];

/**
* Whether the view controller should keep the view's state history
*/
Expand Down Expand Up @@ -326,7 +331,10 @@ export class MapViewController extends MapController {
const moySize = (toSize + fromSize) / 2;
const xSize = distCenter / moySize;

const maxZoom = action === MapViewAction.Move ? zoom : zoom > 19 ? zoom : 19;
const maxZoom =
action === MapViewAction.Move || zoom > this.maxZoomOnExtent
? zoom
: this.maxZoomOnExtent;

olView.fit(extent, {
maxZoom,
Expand Down
1 change: 1 addition & 0 deletions packages/geo/src/lib/map/shared/map.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type MapExtent = [number, number, number, number];
export interface MapViewOptions {
projection?: string;
center?: [number, number];
maxZoomOnExtent?: number;
geolocate?: boolean;
buffer?: Buffer;

Expand Down
11 changes: 9 additions & 2 deletions packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export class IgoMap {
);

this.setView(Object.assign(viewOptions, options));
if (options.maxZoomOnExtent) {
this.viewController.maxZoomOnExtent = options.maxZoomOnExtent;
}
}

/**
Expand Down Expand Up @@ -188,8 +191,12 @@ export class IgoMap {

baseLayer.visible = true;

this.viewController.olView.setMinZoom(baseLayer.dataSource.options.minZoom || (this.options.view || {}).minZoom);
this.viewController.olView.setMaxZoom(baseLayer.dataSource.options.maxZoom || (this.options.view || {}).maxZoom);
this.viewController.olView.setMinZoom(
baseLayer.dataSource.options.minZoom || (this.options.view || {}).minZoom
);
this.viewController.olView.setMaxZoom(
baseLayer.dataSource.options.maxZoom || (this.options.view || {}).maxZoom
);
}

getBaseLayers(): Layer[] {
Expand Down
Loading

0 comments on commit 74fae5a

Please sign in to comment.