Skip to content

Commit 25d8cd5

Browse files
lesbaaLes Moffat
andauthored
Rd 1086 fix leaflet bounds issue (#31)
* RD-1086 Tie max bounds in leaflet instacne to max bounds in MapTiler map. * RD-1086 Remove console.log and pass correct param to constructor * 4.1.1 * RD-1086 Add GH issue to changelog * RD-1086 Fix typo --------- Co-authored-by: Les Moffat <les.moffat@maptiler.com>
1 parent f8237fa commit 25d8cd5

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# MapTiler Client Changelog
22

3+
## 4.1.1
4+
- Constrain maxbounds on Leaflet to those of MapLibre / Maptiler ensure layers are reconclied in terms of position properly. Fixes [30](https://github.com/maptiler/leaflet-maptilersdk/issues/30)
5+
36
## 4.1.0
47
- Update @maptiler/sdk to the latest version
58

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@maptiler/leaflet-maptilersdk",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "Vector tiles basemap plugin for Leaflet - multi-lingual basemaps using MapTiler SDK",
55
"module": "dist/leaflet-maptilersdk.js",
66
"type": "module",

src/leaflet-maptilersdk.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,25 @@ export const MaptilerLayer = L.Layer.extend({
268268

269269
_initMaptilerSDK: function () {
270270
const center = this._map.getCenter();
271+
const maxBounds = (() => {
272+
if (this.options.maxBounds) {
273+
return this.options.maxBounds;
274+
}
275+
276+
// Maplibre is LngLat
277+
return [
278+
[Number.NEGATIVE_INFINITY, -90],
279+
[Number.POSITIVE_INFINITY, 90],
280+
];
281+
})();
282+
283+
// Leaflet expects LatLng
284+
this._map.setMaxBounds(
285+
L.latLngBounds(L.latLng(maxBounds[0][1], maxBounds[0][0]), L.latLng(maxBounds[1][1], maxBounds[1][0])),
286+
);
287+
271288
const options = {
289+
maxBounds,
272290
...this.options,
273291
projection: "mercator",
274292
container: this._container,

0 commit comments

Comments
 (0)