Skip to content

Commit

Permalink
fix scale calculation for non-metric projection (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnevogt authored Feb 24, 2025
1 parent bce31b4 commit e7fdc5d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/cuddly-monkeys-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@open-pioneer/map": minor
---

improve scale calculation for none-metric projections

Fix scale calculation for projections with none-metric units (e.g. EPSG:4326).
Note: The calculated scale (`useScale`) still may deviate from the desired scale (`setScale`) for non-metric projections. This is due to limitiations in the [getPointResolution](https://openlayers.org/en/latest/apidoc/module-ol_proj.html#.getPointResolution) function from OL.
2 changes: 1 addition & 1 deletion src/packages/map/model/MapModelImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class MapModelImpl extends EventEmitter<MapModelEvents> implements MapMod
* Returns the appropriate scale for the given resolution and units, see OpenLayers function getScaleForResolution()
* https://github.com/openlayers/openlayers/blob/7fa9df03431e9e1bc517e6c414565d9f848a3132/src/ol/control/ScaleLine.js#L454C3-L454C24
*/
const pointResolution = getPointResolution(projection, resolution, center);
const pointResolution = getPointResolution(projection, resolution, center, "m"); //point resolution in meter per pixel
const scale = Math.round(pointResolution * INCHES_PER_METRE * DEFAULT_DPI);
return scale;
});
Expand Down
2 changes: 1 addition & 1 deletion src/packages/map/ui/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function useScale(map: OlMap | undefined): number | undefined {
* Returns the appropriate scale for the given resolution and units, see OpenLayers function getScaleForResolution()
* https://github.com/openlayers/openlayers/blob/7fa9df03431e9e1bc517e6c414565d9f848a3132/src/ol/control/ScaleLine.js#L454C3-L454C24
*/
const pointResolution = getPointResolution(projection, resolution, center);
const pointResolution = getPointResolution(projection, resolution, center, "m"); //point resolution in meter per pixel
const scale = Math.round(pointResolution * INCHES_PER_METRE * DEFAULT_DPI);
return scale;
}, [projection, resolution, center]);
Expand Down

0 comments on commit e7fdc5d

Please sign in to comment.