dlr-eoc / ukis-frontend-libraries

A collection of angular ui-components, services, interfaces... to help you create geospatial mapping applications for the web.
Apache License 2.0
17 stars 4 forks source link

Map-ol: Missing ol map interactions after component toggle #178

Closed lucas-angermann closed 1 year ago

lucas-angermann commented 1 year ago

Describe the bug

In an UKIS application, two mapping components are used in one parent component, the existing map-ol and the experimental map-cesium. One can switch between the two maps with a button toggle. When switched from the map-ol map to cesium and back, the pan navigation does not work anymore. One can still zoom with scrolling, but the map navigation is quite limitted.

In the ngOnDestroy() of the map-ol.component.ts the map interactions are removed, which is the possible reason for the error. Apparently, not all services or objects are deleted, when the map-ol component is destroyed. Presumably, the openlayers map object with the still remains and causes the error. A intermidiate fix is to create a new ol map object in the parent component when the map view is switched back to map-ol, which overrides the old map with the removed interactions. this.mapOlSvc.map = new olMap({});

To Reproduce

The bug shold occur in all applications, when one switches on the same page from map-ol to a different map view and back.

Expected behavior

After switching back to the map-ol view, the map navigation is working without problems.

Versions

boeckMt commented 1 year ago

I think this is because Interactions are removed in OnDestroy https://github.com/dlr-eoc/ukis-frontend-libraries/blob/d8d806a84ee72ad8b538354d1f32e5d29cdb3250/projects/map-ol/src/lib/map-ol.component.ts#LL126C6-L128C10 but MapOlService and so the map are still existing. We need to add the default interactions https://openlayers.org/en/latest/apidoc/module-ol_interaction_defaults.html again e.g. here https://github.com/dlr-eoc/ukis-frontend-libraries/blob/main/projects/map-ol/src/lib/map-ol.component.ts#L504.