-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MapController.setCenter offset #22
Comments
I tried triggering it in OpenStreetMapViewer via a menu item and both setCenter() and animateTo() worked properly. However if it is called from onActivityCreated() there is an issue. I think it's because the MapView's width and height is zero because it hasn't had onLayout called yet. Is that where you are calling setCenter()? Or can you confirm that when you call it mMapView.getWidth() is zero? |
You are right, now there is need to check the map view size. |
Sorry for the close / reopen, you can close the issue. |
I think I want to keep this open a little longer until I investigate the getWidth() issues and see if there is a nice solution for that. |
I had this issue in my application which was previously using OSMDroid 4.1 and called setCenter in Fragment.onCreateView. To make it work properly with 4.2, I used something like this in onCreateView :
This way, setCenter is called only once the layout has been drawn and width/height has been calculated. |
i found another workaround which might be a little bit less invasive: just delay the call to setCenter by one tick in the main loop so android gets a chance to do it's layouting before the actual call happens.
thinking about a proper solution, would it make sense to make center the one property of a MapView which is used to calculate everything else from? |
I use externally the way with the OnGlobalLayoutListener. But I like also the way Mapbox handle this issue internally. |
Any progress? |
I'm seeing this too. |
Please try out this patch and let me know if it works: |
Unfortunately, it works incorrect.
In my project this code set defaultPoint in center screen before osmdroid 4.2. Now it set point at pixel (0,0) without patch and at pixel (screen.w, screen.h) with one. |
Sorry - I missed that method. I am going to commit a different approach that will keep track of the calls you make and "replay" them in order once the MapView has a layout. |
…lay them until the MapView has a layout. Updates #22.
Now it fixed. Thank you! |
This appears to be working properly. |
…layout of the maps. Allow listeners to subscribe to first layout event. Change MapController to use this for determining first layout. Updates #22.
Hello I still have this problem (centering ot working) with 4.2 version. .... Has someone a trick to manage that problem ? |
It's fixed in the source at repository, not released yet as new version. |
I have implemented this solution with addOnGlobalLayoutListener. The trouble now is that the map is centering itself and I can not move it (it comes back) ! How can i remove the listener after the first centering ? |
You can try this: mapView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
mapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
else
mapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
...
}
}); |
I finally found how tout manage that. After centering i added this code in onGlobalLayout :
This will remove the listener , :-) |
…lay them until the MapView has a layout. Updates osmdroid#22.
…layout of the maps. Allow listeners to subscribe to first layout event. Change MapController to use this for determining first layout. Updates osmdroid#22.
Setting initial pan and zoom requires a delay
Setting initial pan and zoom requires a delay
…ks when GPS is disabled as well. There is a bug where the map center should default to the a certain location but it is always centered to the upper left. See this: osmdroid/osmdroid#22 (comment) for details. Furthermore, after the new home location is set it is not being updated in the user list until the app is closed and opened again. This is the issue we had before for GPS. I think I'll rename the activity to SetHomeLocationActivity and make separate ones for destinations and expenses.
When we call the new MapController.setCenter implemented at revision 423680b,
the map center is not at the GeoPoint we pass, but at an offset of half the screen down right.
Can you confirm that?
The text was updated successfully, but these errors were encountered: