Paul Alexander
Paul Alexander

Reputation: 2748

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

Upvotes: 1

Views: 1643

Answers (1)

MKer
MKer

Reputation: 3450

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 ?

  • If your GroundOverlay has no bearing => look at GroundOverlay#draw source code, at pEast and pSouthEast computation. This should be a good starting point.

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);
  • If it has a bearing, ... tricky. There is a GeometryMath#getBoundingBoxForRotatatedRectangle in osmdroid which could help. But the scroll will not fit perfectly with the ground overlay edges.

Upvotes: 2

Related Questions