Skip to content

Commit

Permalink
fix(zoom): limit max zoom resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
cbourget committed Apr 24, 2019
1 parent e8ddafa commit 4f63adf
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/geo/src/lib/map/shared/controllers/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import OlView from 'ol/View';

import { MapViewAction } from '../map.enums';
import { MapExtent, MapViewState } from '../map.interface';
import { viewStatesAreEqual } from '../map.utils';
import { getScaleFromResolution, viewStatesAreEqual } from '../map.utils';
import { MapController } from './controller';

export interface MapViewControllerOptions {
Expand Down Expand Up @@ -89,7 +89,7 @@ export class MapViewController extends MapController {
}

this.extent$$ = this.extent$
.pipe(debounceTime(100))
.pipe(debounceTime(50))
.subscribe((value: {extent: MapExtent, action: MapViewAction}) => {
this.setExtent(value.extent, value.action);
});
Expand Down Expand Up @@ -145,11 +145,12 @@ export class MapViewController extends MapController {
* @param dpi Dot per inches
* @returns View scale
*/
getScale(dpi = 96) {
const unit = this.getOlProjection().getUnits();
const resolution = this.getResolution();
const inchesPerMetre = 39.37;
return resolution * olproj.METERS_PER_UNIT[unit] * inchesPerMetre * dpi;
getScale(dpi = 72) {
return getScaleFromResolution(
this.getResolution(),
this.getOlProjection().getUnits(),
dpi
);
}

/**
Expand Down Expand Up @@ -286,7 +287,7 @@ export class MapViewController extends MapController {
private setExtent(extent: MapExtent, action: MapViewAction) {
const olView = this.olView;
if (action === MapViewAction.Zoom) {
olView.fit(extent, {maxZoom: 17});
olView.fit(extent, {maxZoom: 17, minResolution: 0.5});
} else if (action === MapViewAction.Move) {
olView.fit(extent, {maxZoom: olView.getZoom()});
}
Expand Down

0 comments on commit 4f63adf

Please sign in to comment.