Skip to content

Commit

Permalink
geosolutions-it#9018: Dashboard - Zoom in/out on maps connected to a …
Browse files Browse the repository at this point in the history
…3D map

Description:
- fix inconsistently issue of zoom in/out that happens in 3d map sync with another map [2d or 3d]
  • Loading branch information
mahmoudadel54 committed Jul 8, 2024
1 parent 3c550c8 commit ef8f885
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions web/client/components/map/cesium/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ class CesiumMap extends React.Component {
return false;
}
// avoid errors like 44.40641479 !== 44.40641478999999
return a.toFixed(12) - b.toFixed(12) <= 0.000000000001;
return Math.abs(a.toFixed(12) - b.toFixed(12)) <= 0.000000000001; // using Math.abs to include negative values
};

// there are some transition cases where the center is not defined
Expand All @@ -497,15 +497,15 @@ class CesiumMap extends React.Component {

const centerIsUpdate = !isNearlyEqual(newProps.center.x, currentCenter.longitude) ||
!isNearlyEqual(newProps.center.y, currentCenter.latitude);
const zoomChanged = newProps.zoom !== currentZoom;
const zoomChanged = Math.round(newProps.zoom) !== Math.round(currentZoom); // round both to ignore the small tolerance due to calc zoom from hight

// Do the change at the same time, to avoid glitches
if (centerIsUpdate || zoomChanged) {
const position = {
destination: Cesium.Cartesian3.fromDegrees(
newProps.viewerOptions?.cameraPosition?.longitude ?? newProps.center.x,
newProps.viewerOptions?.cameraPosition?.latitude ?? newProps.center.y,
newProps.viewerOptions?.cameraPosition?.height ?? this.getHeightFromZoom(newProps.zoom ?? 0)
newProps.mapStateSource !== this.props.id ? newProps?.center?.x ?? newProps.viewerOptions?.cameraPosition?.longitude : newProps.viewerOptions?.cameraPosition?.longitude ?? newProps.center.x,
newProps.mapStateSource !== this.props.id ? newProps?.center?.y ?? newProps.viewerOptions?.cameraPosition?.latitude : newProps.viewerOptions?.cameraPosition?.latitude ?? newProps.center.y,
newProps.mapStateSource !== this.props.id ? this.getHeightFromZoom(newProps.zoom ?? 0) ?? newProps.viewerOptions?.cameraPosition?.height : newProps.viewerOptions?.cameraPosition?.height ?? this.getHeightFromZoom(newProps.zoom ?? 0)
),
orientation: newProps.viewerOptions?.orientation
};
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/map/openlayers/Map.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ class OpenlayersMap extends React.Component {
_updateMapPositionFromNewProps = (newProps) => {
var view = this.map.getView();
const currentCenter = this.props.center;

const centerIsUpdated = newProps.center.y === currentCenter.y &&
newProps.center.x === currentCenter.x;

Expand All @@ -545,7 +546,7 @@ class OpenlayersMap extends React.Component {
let center = reproject({ x: newProps.center.x, y: newProps.center.y }, 'EPSG:4326', newProps.projection, true);
view.setCenter([center.x, center.y]);
}
if (Math.round(newProps.zoom) !== this.props.zoom) {
if (Math.round(newProps.zoom) !== Math.round(this.props.zoom)) {
view.setZoom(Math.round(newProps.zoom));
}
if (newProps.bbox && newProps.bbox.rotation !== undefined || this.bbox && this.bbox.rotation !== undefined && newProps.bbox.rotation !== this.props.bbox.rotation) {
Expand Down

0 comments on commit ef8f885

Please sign in to comment.