Problem with zoomToBoundingBox()
See original GitHub issueI have problem to use zoomToBoundingBox()
. According to what I’ve read somewhere here, I’ve created my own MapView class to call zoomToBoundingBox()
in onLayout()
. Here is my code:
public class MyMapView extends MapView {
public void setBoundingBox(BoundingBoxE6 boundingBox) {
this.boundingBox = boundingBox;
}
private BoundingBoxE6 boundingBox = null;
...
@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
super.onLayout(arg0, arg1, arg2, arg3, arg4);
// Now that we have laid out the map view,
// zoom to any bounding box
if (this.boundingBox != null) {
this.zoomToBoundingBox(this.boundingBox);
}
}
}
So, In my fragment I initialize the boundingBox:
@Override
public void onResume() {
super.onResume();
final BoundingBoxE6 boundingBox = new BoundingBoxE6( ... );
// this gives ``N:44899816; E:5020385; S:44899001; W:5019482``
mMapView.setBoundingBox(boundingBox);
mMapView.invalidate();
}
So, the calculated bounding box should obviously cause to get a max zoom level but it doesn’t.
First, problem in calculation; onLayout()
is called after onResume()
and I explored the code of zoomToBoundingBox()
and here are the results on each data calculated:
zoomLevel = 0
maxZoomLatitudeSpan = 55.08
requiredLatitudeZoom = 14.0 // I have a big doubt on this result!
maxZoomLongitudeSpan = 472.07
requiredLongitudeZoom = 17.0 // hum well, better but not best expected value
So zoomToBoundingBox() will choose a zoom level of 14.0 why? Anyway, requiredLongitudeZoom of 17.0 is not the best result. As you can see here (http://imgur.com/ZEnX2Za), the max level of 18.0 is possible.
So how should I use zoomToBoundingBox()
?
Issue Analytics
- State:
- Created 8 years ago
- Comments:17
Top Results From Across the Web
OSMDroid5 : can't get zoomToBoundingBox() working correctly
First, problem in calculation; onLayout() is called after onResume() and I explored the code of zoomToBoundingBox() and here are the results ...
Read more >zoomToBoundingBox not working - Google Groups
Hello everyone, i am a newbie to osmdroid and i encountered a problem when trying to view all ... addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
Read more >Zoom to Bounding Box - Popular Blocks - Mike Bostock
Zoom to Bounding Box. Open. This example demonstrates how to compute a suitable translate and scale to zoom to the bounding box of...
Read more >[Solved]-d3 zoom to bounding box II scrolling while zooming ...
Coding example for the question d3 zoom to bounding box II scrolling while ... There is another transition inside reset() function, and we...
Read more >Zoom to Bounding Box / Raj Shrestha - Observable
Zoom to Bounding Box ... corona = Error: File not found: covid_data.json ... n), arc: ƒ(), area: ƒ(), areaRadial: ƒ(), ascending: ƒ(t, n),...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
simplest solution may be to just call zoomToBoundingBox twice.
this works for me on all zoom levels that i’ve tested. Always goes to the expected zoom level (15)
Hello, I tried to call
zoomToBoundingBox()
inMapView.addOnFirstLayoutListener(new OnFirstLayoutListener() { ...});
but that doesn’t solve all problems. The view is well centered (calling it with animate=true doesn’t work at all #264) but the zoom level is not ok. Below is the code:If I put the same code in an
onClickListener()
, it perfectly works: