Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(context): set map zoom level after importing context #1324

Closed
wants to merge 11 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Directive, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { filter } from 'rxjs/operators';

import { MapViewOptions, MapBrowserComponent, MapControlsOptions, MapScaleLineOptions } from '@igo2/geo';
import { MapBrowserComponent, MapControlsOptions, MapScaleLineOptions } from '@igo2/geo';
import type { IgoMap } from '@igo2/geo';

import { ContextService } from './context.service';
Expand Down Expand Up @@ -59,9 +59,10 @@ export class MapContextDirective implements OnInit, OnDestroy {
// this.component.map.ol.setTarget(target);

const viewContext: ContextMapView = context.map.view;
if (!this.component.view || viewContext.keepCurrentView !== true || context.map.view.projection !== this.map.projection) {
this.component.view = viewContext as MapViewOptions;
if (!this.component.view || viewContext.keepCurrentView === true || context.map.view.projection !== this.map.projection) {
this.component.view = viewContext;
}

if (this.component.map.geolocationController) {
this.component.map.geolocationController.updateGeolocationOptions(viewContext);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export class IgoMap {

updateView(options: MapViewOptions) {
const currentView = this.ol.getView();
const viewOptions = Object.assign(
// to update the zoom we need to delete 'resolution' property
const {resolution, ...viewOptions} = Object.assign(
{
zoom: currentView.getZoom()
},
alecarn marked this conversation as resolved.
Show resolved Hide resolved
Expand Down