Skip to content

Commit bd6f001

Browse files
authored
fix(landing): Fix the zoom to extend by using maplibre to adjust AntiMeridian. 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.
1 parent 7f4d1f7 commit bd6f001

File tree

1 file changed

+20
-21
lines changed
  • packages/landing/src/components

1 file changed

+20
-21
lines changed

packages/landing/src/components/map.tsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,26 @@ export class Basemaps extends Component<unknown, { isLayerSwitcherEnabled: boole
4949
};
5050

5151
updateBounds = (bounds: maplibregl.LngLatBoundsLike): void => {
52-
if (Config.map.tileMatrix !== GoogleTms) {
53-
// Transform bounds to current tileMatrix
54-
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
55-
const upperLeft = lngLatBounds.getNorthEast();
56-
const lowerRight = lngLatBounds.getSouthWest();
57-
const zoom = this.map.getZoom();
58-
const upperLeftLocation = locationTransform(
59-
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
60-
Config.map.tileMatrix,
61-
GoogleTms,
62-
);
63-
const lowerRightLocation = locationTransform(
64-
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
65-
Config.map.tileMatrix,
66-
GoogleTms,
67-
);
68-
bounds = [
69-
[upperLeftLocation.lon, upperLeftLocation.lat],
70-
[lowerRightLocation.lon, lowerRightLocation.lat],
71-
];
72-
}
52+
// Transform bounds to current tileMatrix
53+
const lngLatBounds: maplibregl.LngLatBounds = maplibre.LngLatBounds.convert(bounds);
54+
const upperLeft = lngLatBounds.getNorthEast();
55+
const lowerRight = lngLatBounds.getSouthWest();
56+
const zoom = this.map.getZoom();
57+
const upperLeftLocation = locationTransform(
58+
{ lat: upperLeft.lat, lon: upperLeft.lng, zoom },
59+
Config.map.tileMatrix,
60+
GoogleTms,
61+
);
62+
const lowerRightLocation = locationTransform(
63+
{ lat: lowerRight.lat, lon: lowerRight.lng, zoom },
64+
Config.map.tileMatrix,
65+
GoogleTms,
66+
);
67+
bounds = [
68+
[upperLeftLocation.lon, upperLeftLocation.lat],
69+
[lowerRightLocation.lon, lowerRightLocation.lat],
70+
];
71+
7372
this.map.fitBounds(bounds);
7473
};
7574

0 commit comments

Comments
 (0)