Skip to content

Commit

Permalink
Fix the zoom to extend by using maplibre to adjust AntiMeridian
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentao-Kuang committed Dec 19, 2024
1 parent 7f4d1f7 commit 2714925
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions packages/landing/src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,26 @@ export class Basemaps extends Component<unknown, { isLayerSwitcherEnabled: boole
};

updateBounds = (bounds: maplibregl.LngLatBoundsLike): void => {
if (Config.map.tileMatrix !== GoogleTms) {
// Transform bounds to current tileMatrix
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
const upperLeft = lngLatBounds.getNorthEast();
const lowerRight = lngLatBounds.getSouthWest();
const zoom = this.map.getZoom();
const upperLeftLocation = locationTransform(
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
const lowerRightLocation = locationTransform(
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
bounds = [
[upperLeftLocation.lon, upperLeftLocation.lat],
[lowerRightLocation.lon, lowerRightLocation.lat],
];
}
// Transform bounds to current tileMatrix
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
const upperLeft = lngLatBounds.getNorthEast();
const lowerRight = lngLatBounds.getSouthWest();
const zoom = this.map.getZoom();
const upperLeftLocation = locationTransform(
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
const lowerRightLocation = locationTransform(
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
Config.map.tileMatrix,
GoogleTms,
);
bounds = [
[upperLeftLocation.lon, upperLeftLocation.lat],
[lowerRightLocation.lon, lowerRightLocation.lat],
];

this.map.fitBounds(bounds);
};

Expand Down

0 comments on commit 2714925

Please sign in to comment.