i am developing an android app using osmdroid. I am drawing an overlay on the map, depending where your current location is. Depending on the zoomlevel should the overlay get more details (level of detail). In other words, i have to draw the overlay on every zoomlevel. My Problem is the onCreate function is called only once and so is my function to draw the overlay.
I have to optimize the overlay algorithm. The overlay i am drawing on the map should be detailed as necessary and not more. On a zoomlevel of 0, it is not necessary to draw a little polygon with several thousands points.
Related
Is there a way to display a custom map using the Google Maps API and draw polylines on it using (x, y) coordinates? I am not interested in geolocation, since I just want to create a demo scenario for an indoor navigation app.
Depending on your needs you can use Tile Overlays that allows you to load your own map using the tile engine of the map or Ground Overlays that draws a fixed image on a given coordinate.
As both are map overlays you can still draw polylines, polygons, markers, ... on the map
Background: I want to draw several Polygons on a map (few thousand coordinates in all). This worked pretty fast on Google Maps V1 by Overlays. But Google Maps V2 seems to be ineligible for that.
First of all I tried to add polygons directly to the map by
googleMap.addPolygon(myPolygonOptions);
but this is not just unusable slow, it seems to be buggy too, because it always forgets some polygons.
Then I tried to draw the polygon on an invisible view placed above the map, by drawing paths. But the method
projection.toScreenLocation(geoCoordinate);
is a joke to its "toPixels" Google Maps V1 counterpart. Where Google Maps V1 takes 1 second, Google Maps V2 takes 21(!) seconds, so this is unusable too.
Then I thought about giving Overlays a try. Ground overlays seems to be what I'm looking for:
A ground overlay is an image that is fixed to a map. Unlike markers,
ground overlays are oriented against the Earth's surface rather than
the screen, so rotating, tilting or zooming the map will change the
orientation of the image. Ground overlays are useful when you wish to
fix a single image at one area on the map.
But then I read a comment in this posting that it is not performant too and doesn't even work well.
So the last hope are Tile Overlays. The question is: What happens with tile overlays when I rotate the map. Do they change their orientation too or will they stay oriented as loaded?
[UPDATE]
I tried GroundOverlays and they are pretty fast, even on old Smartphones, so I will choose this approach.
The tile will be rotated together with the map. The TileProvider will not get aware of the rotation at all. While drawing the tile is always oriented north up. You may have a look at the answer to this SO question for a very handy tile provider: Google Maps API v2 draw part of circle on MapFragment
basically i am trying to draw the path i.e road path. for that i ususally have more then 50 geopoints to link together to draw a path, but the itemized over is also drawing the image on every point, The image that i passed in the constructor. Due to this apart from looking ugly it also slows down my phone. Ite even became hard to move the map too by touching the screen.
so i dont want to draw any image on any geopoint, is it possible or else i should go for Overlay, and a overlay for every couple of geopoint(two geopoints to draw a line between them). I think that would be a overhead for the mobile to manage too many overlays, i.e for 50 geopoints there would be 25 overlays on the map.
That's just what ItemizedOverlay does. Sounds like you need a regular Overlay. Here's an example.
I have faced some problems with the Android MapView API. I get OverlayItems from a database which I want to display in a MapView. If I'm displaying 100 Icons, I have no issues, but if it gets more - like 500 Items in one City - it first looks really bad, while second it slows down a lot. Unfortunately my goal is to display 10000 of them. I think one solution can be to register a listener to ZoomLevels to make them appear/dissapear, but I couldn't find that functionality. Second, I couldn't find a function to scale my Overlays with the Zoom of the Map.
Any Ideas are very welcome
There is a very strange behavior in ItemizedOverlay draw method. When you say: Draw line from (x,y) to (x1,y1) the draw method is called about 20-30-40 times - i don't know why. It is acceptable when you draw one line, but when you draw a thousands of lines,icons and so on...it is very very bad! To solve this problem you should create a cached overlay. This is overlay that catches the first draw, creates the object and then prevents the future draws that do the same draw.
A cluster is a dozen of icons behind one icon. For example if you have 1000 markers on the map, in a specific minimal zoom level you can not see each marker separately - it becomes a mess of icons and colors and so on. And instead of 100 markers that are very very close one by one you place a cluster marker. And on zoom in remove this cluster and create another clusters...do this until the markers became far enough away and you can seen them divided.
Check this: Cluster markers
Take the following approaches:
Create a cached overlay to prevent multiple drawing of same clusters;
Draw in thread;
Cluster your markers depending on zoom level and marker proximity.
Each time you draw in the overlay, check for sure is the current marker inside of the visible part of the screen. If it is not, do no draw it!
I had a similar problem with the icon size and zoom level in my application. What I ended up doing was having 2 sets of overlays containing the markers, one with a "zoomed in" icon and one with a "zoomed out" icon. Then just changed the overlay at a certain zoom level (using a zoom poller - On zoom event for google maps on android)
I am developing an app for my Universities campus that displays the campus in a MapView; then using geopoints draws the outlines of the buildings on campus on the mapView using the draw method a class that extents Overlay. There are about 50-60 buildings being drawn, resulting in a very laggy map as the draw method constantly gets drawn over and over.
I have looked into my problem and I have found some people mentioning drawing the buildings on a canvas, but I have found no good examples or info on how to go about implementing this. Can anyone point me in the right direction on how to reduce the map's lag? The map looks very nice but the lag just kills its usefulness.
Thanks!
If you have all the points organized into polygons you can draw polygons on a canvas and then draw it on an Overlay. That i think would be quicker.
Also you can always do some calculation about what part of the building need to be redrawn for the next position and just change that part of the Canvas.
If you moved (X,Y) pixels from an earlier position, shift the existing canvas into the new position and just draw the new things that appear on map.
This is not the optimal solution of course because this kind of caching wouldn't work with the zoom.
Hope it helped somehow!
JQCorreia