Skip to content

Commit

Permalink
fix(landing): Fix the zoom to extend by using maplibre to adjust Anti…
Browse files Browse the repository at this point in the history
…Meridian. BM-1155 (#3384)

### Motivation

The zoom to extend feature is broken after upgrade the maplibre to
latest release. It always zoom back to the whole world when switching
layer, seems the caused by the anti Meridian. And this only happens to
the Web Mercator

### Modifications
Maplibre got a fix of
[adjustAntiMeridian](https://github.com/maplibre/maplibre-gl-js/blob/87486a5ef2085e600e8fa4e31252629dd8488dcd/src/geo/lng_lat_bounds.ts#L342)
between v4.5 to v4.71.
I believe that causes some conflicts with the pre-adjust in our system,
and this is fixed after we do a `maplibre.LngLatBounds.convert` for Web
Mercator as well.

### Verification
Local tested, all zoom to layer working fine for Web Mercator and NZTM
now.
  • Loading branch information
Wentao-Kuang authored Dec 20, 2024
1 parent 7f4d1f7 commit bd6f001
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 bd6f001

Please sign in to comment.