Comments (19)
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?
from osmdroid.
You are right, now there is need to check the map view size.
If map view has been layout then setCenter works correctly.
from osmdroid.
Sorry for the close / reopen, you can close the issue.
from osmdroid.
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.
from osmdroid.
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 :
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mMapView.getController().setCenter(...);
}
});
This way, setCenter is called only once the layout has been drawn and width/height has been calculated.
from osmdroid.
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.
new Handler(Looper.getMainLooper()).post(
new Runnable() {
public void run() {
mapController.setCenter(...);
}
}
);
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?
from osmdroid.
I use externally the way with the OnGlobalLayoutListener.
But I like also the way Mapbox handle this issue internally.
At MapView.onSizeChanged they call MapController.mapViewLayedOut
where it executes any actions that have been recorded before map view is layed out.
from osmdroid.
Any progress?
from osmdroid.
I'm seeing this too.
from osmdroid.
Please try out this patch and let me know if it works:
https://gist.github.com/kurtzmarc/f99b0bbbff46791d2168
from osmdroid.
Please try out this patch and let me know if it works
Unfortunately, it works incorrect.
GeoPoint defaultPoint = new GeoPoint(Const.DEF_LATITUDE, Const.DEF_LONGITURE);
mMapView.getController().animateTo(defaultPoint);
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.
from osmdroid.
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.
from osmdroid.
Now it fixed. Thank you!
from osmdroid.
This appears to be working properly.
from osmdroid.
Hello
I still have this problem (centering ot working) with 4.2 version. ....
Has someone a trick to manage that problem ?
from osmdroid.
It's fixed in the source at repository, not released yet as new version.
If you play with the 4.2 take a look at the OnGlobalLayoutListener
solution.
from osmdroid.
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 ?
from osmdroid.
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);
...
}
});
from osmdroid.
I finally found how tout manage that.
After centering i added this code in onGlobalLayout :
///////////////
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
-
mMapView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
-
} else {
-
mMapView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
-
///////////////
}
This will remove the listener , :-)
from osmdroid.
Related Issues (20)
- java.lang.NullPointerException: Attempt to invoke interface method 'boolean org.osmdroid.views.overlay.OverlayManager.add(java.lang.Object)' on a null object reference HOT 2
- IP tracker and ad in wiki HOT 3
- open street map don't display
- TileSourceFactory US aviation maps don't load any more
- Writing and reading data from the real time database for Osmdroid HOT 1
- delete markers
- Animating the movement of a cursor along a polyline with two colors codes: the completed part and the part to do ? HOT 1
- displaying the route and deleting the marker zi database HOT 1
- BingMapTileSource always crash HOT 2
- Some issues when initializing mapsforge
- Zoom changes ignored if performed while an animation is underway HOT 1
- Issue: GroundOverlay bad placement when invalidate map
- GroundOverlay - Draw White Image on Android 11
- Map View throwing Error as Too many receivers, total of 1000, registered HOT 2
- CPU usage continually between 30 and 40% when on a closed network HOT 2
- Proposal for new location indicator (puck) HOT 1
- Question: Timeout handling in TileDownloader class HOT 2
- Crash when activity closed: MapView
- Confusing logic in CacheManager function cleanAreaAsync
- load 4326 coordinate system wmts map service
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from osmdroid.