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

Enhance OL map component in updating map position based on center #10521

Closed
1 task done
dsuren1 opened this issue Aug 29, 2024 · 0 comments · Fixed by #10525
Closed
1 task done

Enhance OL map component in updating map position based on center #10521

dsuren1 opened this issue Aug 29, 2024 · 0 comments · Fixed by #10525

Comments

@dsuren1
Copy link
Contributor

dsuren1 commented Aug 29, 2024

Description

The OL Map component requires a minor enhancement in updating the map position from props, especially the center. Currently, an exact match is performed, leading to a map view update even when the difference is <= 0.00000001. This value is reprojected, causing a minor fractional difference, which in turn triggers onMapViewChange, updating the props and leading to a multiple update.

const centerIsUpdated = newProps.center.y === currentCenter.y &&
newProps.center.x === currentCenter.x;
if (!centerIsUpdated) {
// let center = ol.proj.transform([newProps.center.x, newProps.center.y], 'EPSG:4326', newProps.projection);
let center = reproject({ x: newProps.center.x, y: newProps.center.y }, 'EPSG:4326', newProps.projection, true);
view.setCenter([center.x, center.y]);

To avoid unnecessary updates, a nearly equal match is more suitable in these scenarios instead of performing an exact match.

  const isNearlyEqual = function (a, b) {
    if (a === undefined || b === undefined) {
      return false;
    }
    return a.toFixed(8) - b.toFixed(8) <= 0.00000001;
  };

What kind of improvement you want to add? (check one with "x", remove the others)

  • Minor changes to existing features

Other useful information

This update is needed for downstream project where a similar scenario is observed when using certain CRS

@dsuren1 dsuren1 changed the title Enhance OL map component for updating map position based on center comparison Enhance OL map component in updating map position based on center Aug 30, 2024
@tdipisa tdipisa added this to the 2024.02.00 milestone Aug 30, 2024
@tdipisa tdipisa assigned dsuren1 and unassigned tdipisa Aug 30, 2024
@MV88 MV88 added BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch and removed BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch labels Aug 30, 2024
dsuren1 added a commit to dsuren1/MapStore2 that referenced this issue Aug 30, 2024
@tdipisa tdipisa linked a pull request Sep 2, 2024 that will close this issue
6 tasks
@tdipisa tdipisa closed this as completed Sep 6, 2024
@ElenaGallo ElenaGallo self-assigned this Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants