zskarte / zskarte-client

Zivilschutz-Karte allows to draw situation maps for disaster management
https://www.zskarte.ch/
MIT License
13 stars 8 forks source link

redesign projection handling, add format selection #398

Open swerder opened 4 months ago

swerder commented 4 months ago

This pull request contains a redesign of the projection / coordinate format systems with added functions. It fixes https://github.com/zskarte/zskarte-client/issues/57

It adds a Coord format selection to:

and allow to show/edit the values as number or text representation in corresponding format.

I added format selection to coordinates.component behind the small symbol at right.

coordinates component-options

This my be difficult to click on touchscreen, so perhaps it have to be moved to somewhere else / increase in size / other option to open. I don't know how/where this setting should be persisted in your concept so I leave an TODO for that.

In edit-coordinates.component the values can now be entered as numbers or formatted strings. Also the json is pretty printed for display (but can be changed with prettyf or course).

edit-coordinates component-JSON-prettify

The new GPS°'" format have an slightly problem if used in edit-coordinates.component as if the json conversion have to escape the ".

edit-coordinates component-GPS-JSON-problem

But on parsing the values back for save, it's allowed to remove the " symbol on the coordinates completely, for simplify it an bit.

In map-renderer.component.ts the functions

  this.selectedFeatureCoordinates = this.selectedFeature.pipe(
    map((feature) => {
      const coords = this.getFeatureCoordinates(feature);
      return projectionByIndex(this.selectedProjectionIndex).translate(coords);
    }),
  );
  this.mouseProjection = this._state.getCoordinates().pipe(
    takeUntil(this._ngUnsubscribe),
    map((coords) => {
      const transform = this.transformToCurrentProjection(coords) ?? [];
      return projectionByIndex(this.selectedProjectionIndex).translate(transform);
    }),
  );

  getFeatureCoordinates(feature: Feature | null | undefined): Coordinate {
    const center = getCenter(feature?.getGeometry()?.getExtent() ?? []);
    return this.transformToCurrentProjection(center) ?? [];
  }

  transformToCurrentProjection(coordinates: Coordinate) {
    return projectionByIndex(this.selectedProjectionIndex).transformTo(coordinates);
  }

are never used, I adjusted them anyway. Also the "selectedProjectionIndex" have not any effect, as it cannot be set/changed and is not used by coordinates.component I suggest to delete this functions and the selectedProjectionIndex if not planed to be used again.

PS: is there an option to do the DeepSource checks locally? "yarn lint" have not shown any issues.