-1

Mapbox map is having infinite world scrolling. I have tried a lot but I am unable to stop world infinite scrolling.

Mapbox was having some way previously (Disable horizontal repeating of world map with mapbox) but not currently supported and not sure for Android.

Also, by listening to camera move, I tried cancelling transaction (camera animation) but it did not worked.

I was not able to find any related API in mapbox which can stop this continuous world scrolling in Android.

I am using Mapbox SDK 9.0.0

AndroidT
  • 69
  • 5
  • Can you clarify what you mean by infinite map scrolling? – ItsMeNaira Mar 06 '20 at 08:14
  • By infinite map scrolling stop, I mean to say that when map reaches edge of world, it should stop there. Currently, it keeps on scrolling around the globe. – AndroidT Mar 06 '20 at 10:19

1 Answers1

1

This example from the Mapbox documentation shows how to restrict map panning. You can create a LatLngBounds object from the northwest and southeast corners of the region where you'd like to restrict map panning to. In this case, the region will be the entire world, and the boundaries will specify where you want the "left" and "right" vertical cutoffs to be.

The coordinates below worked well for me, but you could further adjust them to get the exact effect that you are looking for. geojson.io is a great resource for visualizing GeoJSON features on a map, if you'd like to experiment with adjusting this bounding box.

/* Define bounding box. */
    private static final LatLng BOUND_CORNER_NW = new LatLng(82.85338229176081, -141.328125);
    private static final LatLng BOUND_CORNER_SE = new LatLng( -62.59334083012023, 167.34375);
    private static final LatLngBounds RESTRICTED_BOUNDS_AREA = new LatLngBounds.Builder()
            .include(BOUND_CORNER_NW)
            .include(BOUND_CORNER_SE)
            .build();

Note that Mapbox GL JS has setRenderWorldCopies and getRenderWorldCopies methods, which, as demonstrated in this render world copies example, allows you to toggle between rendering a single world and multiple copies of the world. The Maps SDK for Android does not include the same feature, however.

Adriana Babakanian
  • 1,239
  • 6
  • 8
  • I wanted this to work for Android. Your suggested answer does not work for Android. Can you please help as we are extensively using Mapbox in our company. Thanks. – AndroidT Mar 09 '20 at 12:10
  • Were you able to try out this linked example (https://docs.mapbox.com/android/maps/examples/restrict-map-panning/) and replace the `RESTRICTED_BOUNDS_AREA` with the one defined in my code snippet above? I tried this out in a sample app and it worked for me. – Adriana Babakanian Mar 09 '20 at 15:31