androidandroid-mapviewosmdroidbounding-boxoverlays

osmdroid set bounds to edges of an image overlay in a mapview


I've made an app with an osmdroid mapview, the user is able to import a jpeg into the map as a groundoverlay, the image imported would be the floorplan of a building and would fill the mapview. Does anyone know how I would go about settings the scroll boundaries of the mapview to the edges of the groundoverlay so that the user cannot scroll outside of the groundoverlay/floorplan.

any ideas on this would be great


Solution

  • Set the viewable area with mapView.setScrollableAreaLimit(groundOverlayBoundingBox).

    You may also need to limit the min zoom level (MapView#setMinZoomLevel).

    Now, how to compute the GroundOverlay BoundingBox ?

    EDIT - with the maths:

    GeoPoint pEast = position.destinationPoint(width, 90.0f);   
    GeoPoint pSouthEast = pEast.destinationPoint(height, -180.0f);
    int north = position.getLatitudeE6()*2 - pSouthEast.getLatitudeE6();
    int west = position.getLongitudeE6()*2 - pEast.getLongitudeE6();
    BoundingBoxE6 bb = new BoundingBoxE6(north, pEast.getLongitudeE6(),
      pSouthEast.getLatitudeE6(), west);