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 #1384

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"unused-imports/no-unused-imports": "error",
"no-multi-spaces": "error",
"eqeqeq": ["error", "always"],
"eqeqeq": ["error", "smart"],
"semi": ["error", "always"],
"no-trailing-spaces": "error",
"no-multiple-empty-lines": "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class ContextImportExportComponent implements OnInit, OnDestroy {
this.res = this.contextService.getContextFromLayers(
this.map,
contextOptions.layers,
contextOptions.name
contextOptions.name,
false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi passer le keepCurrentView a false ici?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si tu veux exporter un contexte, j'imagine que naturellement, tu veux reloader la vue lors de l'importation.

);
this.res.imported = true;
this.contextExportService.export(this.res).pipe(take(1)).subscribe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ export class ContextService {
getContextFromLayers(
igoMap: IgoMap,
layers: Layer[],
name: string
name: string,
keepCurrentView? : boolean
): DetailedContext {
const currentContext = this.context$.getValue();
const view = igoMap.ol.getView();
Expand All @@ -523,7 +524,8 @@ export class ContextService {
view: {
center: center.getCoordinates(),
zoom: view.getZoom(),
projection: proj
projection: proj,
keepCurrentView
}
},
layers: [],
Expand Down
44 changes: 24 additions & 20 deletions packages/geo/src/lib/map/shared/map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import olMap from 'ol/Map';
import olView from 'ol/View';
import olView, { ViewOptions } from 'ol/View';
import olControlAttribution from 'ol/control/Attribution';
import olControlScaleLine from 'ol/control/ScaleLine';
import * as olproj from 'ol/proj';
Expand Down Expand Up @@ -185,14 +185,16 @@ export class IgoMap implements MapBase {

updateView(options: MapViewOptions) {
const currentView = this.ol.getView();
const viewOptions = Object.assign(
{
zoom: currentView.getZoom()
},
currentView.getProperties()
);
const viewOptions: MapViewOptions = {
...currentView.getProperties(),
...options
};

if (options.zoom && options.resolution == null) {
viewOptions.resolution = undefined;
}

this.setView(Object.assign(viewOptions, options));
this.setView(viewOptions);
if (options.maxZoomOnExtent) {
this.viewController.maxZoomOnExtent = options.maxZoomOnExtent;
}
Expand All @@ -208,21 +210,23 @@ export class IgoMap implements MapBase {
this.viewController.clearStateHistory();
}

options = Object.assign({ constrainResolution: true }, options);
const view = new olView(options);
this.ol.setView(view);
const viewOptions = this.handleMapViewOptions(options);
this.ol.setView(new olView(viewOptions));

if (options) {
if (options.maxLayerZoomExtent) {
this.viewController.maxLayerZoomExtent = options.maxLayerZoomExtent;
}
if (options.maxLayerZoomExtent) {
this.viewController.maxLayerZoomExtent = options.maxLayerZoomExtent;
}
}

if (options.center) {
const projection = view.getProjection().getCode();
const center = olproj.fromLonLat(options.center, projection);
view.setCenter(center);
}
private handleMapViewOptions(options: MapViewOptions): ViewOptions {
const viewOptions: ViewOptions = { constrainResolution: true, ...options };

if (options.center) {
const projection = olproj.createProjection(options.projection, 'EPSG:3857');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P-etre faire attention. Passer par le view controller (ou le get projection) pour définir la projection de la map. Ce n'est pas toujours en 3857

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alecarn Pourquoi creer une projection?
cela suffirait?
viewOptions.center = olproj.fromLonLat(options.center, this.viewController.olView.getProjection().getCode());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En passant par le viewCtrl, j'ai l'impression qu'on fait une conversion pour rien. Parce qu'a ce point ci, le viewCtrl représente la vue précédente
et dans les options on pourrait retrouver une nouvelle projection et positionnement/center?

viewOptions.center = olproj.fromLonLat(options.center, projection);
}

return viewOptions;
}

updateControls(value: MapControlsOptions) {
Expand Down