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)
Other useful information
This update is needed for downstream project where a similar scenario is observed when using certain CRS
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.MapStore2/web/client/components/map/openlayers/Map.jsx
Lines 540 to 546 in 04e8784
To avoid unnecessary updates, a nearly equal match is more suitable in these scenarios instead of performing an exact match.
What kind of improvement you want to add? (check one with "x", remove the others)
Other useful information
This update is needed for downstream project where a similar scenario is observed when using certain CRS