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

Mapstate update #217

Merged
merged 22 commits into from
Mar 13, 2024
Merged

Mapstate update #217

merged 22 commits into from
Mar 13, 2024

Conversation

lucas-angermann
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

For 3D applications it would be useful to add view rotation and view angle to the mapState. This would enable us to set initial values and change them according to user input.
Issue Number: #216

What is the new behavior?

The mapState now contains the values rotation and viewAngle. To use this functionality, map-ol, map-cesium and map-maplibre were connected to the new mapState values. In demo-maps some examples were added.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Is it part of one/more packages and which?

@lucas-angermann lucas-angermann added the enhancement feat: (New feature or request) label Feb 15, 2024
@lucas-angermann lucas-angermann self-assigned this Feb 15, 2024
@boeckMt
Copy link
Member

boeckMt commented Feb 19, 2024

@lucas-angermann thanks for all the work!

I have a few comments on this.

CHANGELOG.md Outdated
@@ -1,3 +1,14 @@
# [12.x.x](https://github.com/dlr-eoc/ukis-frontend-libraries/tree/v12.0.0) (2024-02-07) (services-map-state, map-ol, map-cesium and map-maplibre)
Copy link
Member

Choose a reason for hiding this comment

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

You can actually omit the version, I always add it when we create a new version

}
resetViewAngle() {
/** set map rotation with the MapStateService */
this.mapStateSvc.setViewAngle(0.01);
Copy link
Member

Choose a reason for hiding this comment

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

What are the low values "0.0.1" good for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When setting the value to 0, there seems to be an rounding issue with the conversions. So it is more stable to use very small numbers instead of 0. Internally, small numbers close to 0 are then snapped to zero (https://openlayers.org/en/latest/apidoc/module-ol_View-View.html):

The rotation constraint snaps to specific angles. It is determined by the following options: enableRotation and constrainRotation. By default rotation is allowed and its value is snapped to zero when approaching the horizontal.

Copy link
Member

@boeckMt boeckMt Feb 19, 2024

Choose a reason for hiding this comment

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

Then I would handle that internally, but leave the interface as a user would expect.

e.g.

let radAngle;
if(viewAngle === 0){
  radAngle = viewAngle;
}else{
  radAngle = CesiumMath.toRadians(viewAngle-90)
}

and OpenLayers

@@ -224,38 +224,41 @@ export class MapCesiumService {
}

// Set initial oblique view, see https://cesium.com/learn/cesiumjs/ref-doc/Camera.html
//subtract 90°, to get the same behavior as in openlayers
public setViewAngle(viewAngle: number) {
Copy link
Member

Choose a reason for hiding this comment

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

Here, I would allow the flyTo options to be passed and merged. I implemented this in one of our projects so that users don't have to set a timeout and can listen to flyTo.complete instead.

/**
*  Set initial oblique view, see https://cesium.com/learn/cesiumjs/ref-doc/Camera.html
*  subtract 90°, to get the same behavior as in openlayers
*  options of viewer.camera.flyTo`
*/
public setViewAngle(viewAngle: number, options?: any`) {
  const flyToOptions = Object.assign({
      destination: this.viewer.camera.position,
      orientation: {
         heading: this.viewer.camera.heading,
         pitch: CesiumMath.toRadians(viewAngle-90),
         roll: this.viewer.camera.roll,
    });
    }, options || {});
    this.viewer.camera.flyTo(flyToOptions)
}

return CesiumMath.toDegrees(this.viewer.camera.pitch) + 90;
}
// subtract rotation degree from 360° to get the same behavior as in openlayers
public setRotation(rotation: number) {
Copy link
Member

Choose a reason for hiding this comment

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

Here I would also allow the user to listen to flyTo.complete.

@@ -59,6 +59,28 @@ export class MapStateService {
this.setMapState(state);
}

public setViewAngle(angle: number, notifier: IMapState['options']['notifier'] = 'user') {
if (!angle) {
Copy link
Member

Choose a reason for hiding this comment

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

In here, I would allow to pass 0 as an angle. Otherwise, users must use small values to reset the ViewAngle.

}

public setRotation(rotation: number, notifier: IMapState['options']['notifier'] = 'user') {
if (!rotation) {
Copy link
Member

Choose a reason for hiding this comment

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

In here, I would allow to pass 0 as rotation. Otherwise, users must use small values.

Copy link
Member

@boeckMt boeckMt left a comment

Choose a reason for hiding this comment

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

These are my comments, maybe you can check what can be solved.

@boeckMt
Copy link
Member

boeckMt commented Mar 12, 2024

@lucas-angermann I tried to resolve my comments, maybe you can check if this is all correct?

Copy link
Contributor Author

@lucas-angermann lucas-angermann left a comment

Choose a reason for hiding this comment

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

Looks good, thank you for the changes!

@lucas-angermann lucas-angermann merged commit ff2e872 into main Mar 13, 2024
11 checks passed
@lucas-angermann lucas-angermann deleted the mapstate-update branch March 13, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feat: (New feature or request)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants