Reputation: 37
I am developing an interactive map with markers on it. However, I am facing an issue where at high zoom-out levels, the map starts repeating itself, causing my markers to duplicate due to repeated coordinates. Additionally, having multiple repeated maps on a wide screen looks unappealing.
Is there a way in the MapBox JS library to disable map repetition or perhaps replace the repeated map with an infinite ocean?
Upvotes: -2
Views: 170
Reputation: 1
In the Mapbox JS library, the repetition of maps at low zoom levels is caused by the default setting of the wrap property, which enables horizontal map wrapping. To prevent this, you can use the maxBounds option to restrict the map view to a specific bounding box.
const map = new mapboxgl.Map({
container: 'map', // ID of the container element
style: 'mapbox://styles/mapbox/streets-v11', // Mapbox style URL
center: [0, 0], // Initial center [longitude, latitude]
zoom: 2, // Initial zoom level
maxBounds: [[-180, -85], [180, 85]] // Restrict bounds
});
Upvotes: 0