Skip to content

Commit

Permalink
feat(baselayer): the map zoom is now limited by the baselayer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Jan 27, 2020
1 parent a36648e commit 08c42d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface DataSourceOptions {
// view?: ol.olx.layer.ImageOptions;
id?: string;
ol?: olSource;
minZoom?: number;
maxZoom?: number;
// TODO: Should those options really belong here?
sourceFields?: SourceFieldsOptionsParams[];
download?: DownloadOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ export class BaseLayersSwitcherComponent implements AfterViewInit, OnDestroy {

get baseLayers(): Layer[] {
const mapResolution = this.map.viewController.getResolution();
const mapZoom = this.map.viewController.getZoom();

const bl = this._baseLayers.filter(l => {
return (
(!l.options.maxResolution ||
mapResolution <= l.options.maxResolution) &&
(!l.options.minResolution || mapResolution >= l.options.minResolution)
(!l.options.minResolution || mapResolution >= l.options.minResolution) &&
(!l.options.source.options.maxZoom || mapZoom <= l.options.source.options.maxZoom) &&
(!l.options.source.options.minZoom || mapZoom >= l.options.source.options.minZoom)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ export class MiniBaseMapComponent implements AfterViewInit, OnDestroy {

const options: any = Object.assign(
Object.create(baselayer.options),
baselayer.options
baselayer.options,
{
visible: true,
baseLayer: false
}
);
options.visible = true;

const layer = this.layerService.createLayer(options);
this.basemap.addLayer(layer);
Expand Down
3 changes: 3 additions & 0 deletions packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ 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);
}

getBaseLayers(): Layer[] {
Expand Down

0 comments on commit 08c42d2

Please sign in to comment.