Loading osmdroid MapView in a new thread - android

Loading of the map in my application was slow on some devices. I wanted to load the map in a different thread and show a progress dialog until it is done.
I found this article: http://pygmalion.nitri.de/android-starting-an-activity-containing-a-mapview-takes-forever-380.html
I think that the only thing it does is waiting for defined time and then run the code inside the run() method. That's not what I want.
I tried to use ASyncTask with the same XML layout as in the article above:
in doInBackground()
created MapView by new MapView(MyActivity.this);
setters for multitouch, zoom controls, tilesource (offline with osmbonusback)
in onPostExecute()
added mapview to the prepared FrameLayout
The map loaded correctly but the zoom coontrols were on the top of the screen. Also when I zoomed in, the tiles got rescaled instead of loading the correct zoom level tiles - until I moved the map.
Is there any way to open the activity instantly, wait for the map and let the user know it is loading?

Related

Keep custom Google Map overlay tiles visible after zoom

I'm using Tile Overlay feature of Google Map for Android to display custom map tiles, provided by third party service.
My problem is that, when user zooms the map, and it switches to next zoom level, already visible tiles are disappearing, and then getTile() method of my TileProvider implemetation is triggered. This causes unpleasant blinking of my map view, and moments when user can see only default map.
Standard Google Map behavior scales and "overzooms" currently visible tiles, until new ones are loaded. Is there any way I can create the same effect with Tile Overlay? I am aware that "overzoomed" tiles can be blurry, but that is ok in my case.
Remove custom tiles when zoom level changed is default Android GoogleMap behavior. To "suppress" it (showing previous map when tiles for zoom±1 level still downloading ) you can:
1) create GroundOverlay with screenshot of current map view. Screenshot of google map you can do like in answers for this question of DiscDev and remove it when tiles downloaded;
2) create custom view which extends MapView class like in this answer and show in overridden dispatchDraw() method whatever you want;
3) you can set ImageView over your MapView and show it with screenshot on it while zoom changed and new tiles loaded. And if necessary you can translate tap events from ImageView to MapView and so on.
I prefer p.2 - create MapView-based custom view, override dispatchDraw() and show temporary map within it while new map loading.

Android google maps tile overlay update on zoom

I have a tile overlay in Android Google Map. Everything works fine. But when I zoom in, all tiles disappear then new tiles are downloaded and only after 1-2 secs(when new tiles are downloaded) the map shows them. Therefore, the map doesn't show tiles for some time. Is there a way to update tiles only when new tiles are downloaded?
I use a basic UrlTileProvider and Aeris Overlay maps.
Anyway, you can download each tile as image to local internal or external storage with, for example, Picasso library (or separate Thread or AsyncTask) and determine "all new tiles are downloaded" event "manually" (e.g. increment downloaded tiles counter on every public void onSuccess() for Picasso or protected void onPostExecute() for AsyncTask or on end of public void run() for Thread and wait that equals all tiles quantity) then use TileProvider for downloaded tiles local storage like in this answer of Alex Vasilkov.
Update
For showing previous map when tiles for zoom+1 level still downloading it's possible to create GroundOverlay with screenshot of current map view. Screenshot of google map you can do like in answers for this question of DiscDev
Update #2
There are several ways to solve you problem: 1) you can create custom view which extends MapView class like in this answer and show in overridendispatchDraw() method whatever you want or 2) you can set ImageView over your MapView and show it with screenshot on it while zoom changed and new tiles loaded. And if necessary you can translate tap events from ImageView to MapView and so on.
I prefer p.1 - create MapView-based custom view, override dispatchDraw() and show temporary map within it while new map loading.

android google map ~10k markers

i am doing an android app, that is displaying markers on google map. The problem here is i need to handle ~10k markers. I can't do clustering as every marker is important and i can't show this markers from some zoom level as it is important to get the 'bigger picture'
WHAT I'VE TRIED:
displaying only visible markers, but they are too dense and still I am left with few thousands and map just can't handle it..
I moved away from google markers and created surfaceview over map fragment. And this works fine when I update my 'markers' after google map camera changes (after u stop dragging it), but this looks bad, because in between updates they are anchored to its position on screen not on map. And when i try to update my surfaceview while dragging it is not doing too well and freezes.
QUESTIONS:
will moving from surfaceview to opengl improve rendering time?
any other ideas?
EDIT:
firstly i will clarify, important is not every single marker, but the shape of the cloud of markers.
And also I've already tried heatmaps from google maps extension, but it kept freezing while dragging the map, heap kept growing until it finally breaks.
Rendering markers in google map is very resource expensive task. If the marker is custom designed it will take more time to just to create the bitmap.Traditional way of creating marker will not help here, bcz rendering is done by Main Thread. You have to implement some parallel processing to create the markers, So redering markers will not disturb your main thread. You can implement something like this
http://leaks.wanari.com/2016/05/05/rendering-markers-for-android/
I hope it will help you. Good Luck.

android google map changeing on the run

i have a map view using google map API
in my map i have few overlays markers which i've designed throw extending the ItemizedOverlay.
i want to change this markers drawable image after the map is already visible to user.
is it possible ?
my intention is to run some lazy drawable loading (like you do in a list view), because all my images are coming from the web, and i don't want the user to wait for all the images to load before i load the map.
on a list view its kind of easy, because the thread will update the ImageView, but here i don't know how to access a specific item after the map has loaded..
thanks!
Check out the function setMarker in OverlayItem. It will let you change the image for a specific marker. Just make sure you centerBound the image before setting it.
OverLayItem
According to me first load all the dummy iamges and show it on the mapview and simultaniously start a background task to download all the images from server and once the image downloads process completes just clear all the overlays on the mapview and reload the actually downloaded images on the mapview.

Android Google maps - custom tile overlay

Been working on a custom tile overlay implementation for an android app.
I'm having trouble with threading the image downloads in the background.
Quick overview:
I have a class (MapOverlay) that extends Overlay. The draw method basically calculates the images (bitmaps) needed and the x,y position to draw them on the screen. I then have an AsyncTask that loops through each tiles and download the images if it doesn't exist on the storage card (local caching) then once the AsyncTask has completed I then loop through the images and draw them to the canvas object that is passed into the draw method of the MapOverlay. But the bitmaps are never getting drawn.
I have done some rudimentary debugging by logging the width and the height of the canvas element at the time the AsyncTask completes but it is returning 0 for them so I'm guessing that the canvas object is no longer available to the code running in AsyncTask's onPostExecute() after the draw method has completed
Without the threading I had this working pretty well, except for the "freezing" while panning while the image downloading blocks the UI thread. Now I'm totally suck trying to get threading to work
Have you tried calling postInvalidate() when the AsyncTask done downloading? That way the call in MapView.draw() will get and draw the downloaded overlay (that is if your caching system works).

Categories

Resources