Android MapView path.draw draws crazy polygon lines all over the place - android

I've been struggling for a couple of weeks now with google's android mapview.
I'm drawing a large amount of polygons with a large amount of points. on average 15 polygons and around 1000 points each.
The first issue I experienced was performance... No surprise. After doing some testing I realised the culprit is projection.ToPixel() which I successfully bypass when the users pans by simply moving all my points in the direction by x amount of pixels (the difference), however when zooming I have no choice but to make use of the toPixel method.
Is there possibly a more efficient way of modifying my points depending on the zoom level? after some research I've found examples on how to do this with circles and other shapes, but I have no clue where to begin with reshaping polygons, any ideas on this?
The second issue i'm having is that when I have the entire polygon in view all is grand, but when I pan over the map bounds (where the map is effectively starting again to the left and right) on any side the polygon lines seem to reach and stretch out across the map bounds causing crazy spaghetti lines all over the place! I take it what's happening is that the path.close() or path.LineTo() methods think the shortest path is flying halfway across the world to reach the next point which causes these lines. I have no idea how to address this. I simply can't ignore points that do not fall within the current lon/lat spans because that (obviously) causes the polygon to change shape al the time!
Has anyone experienced this issue and how can one go about solving it? I'm not even sure what I should be googling!?
UPDATE 1:
The problem can be easily solved by preventing the mapview from looping. Is there some way to prevent the mapview from looping the world!?!?

Related

How can I calculate parameters in order to position a ground overlay, using points in the middle of an image?

Im making an android project where I want to show to the user a map of a place (the place doesnt have any detail in google maps, just a vague outline). I have some physical architectual sketches of the place, that I scanned and cut a bit. Unfortunetly they still have a wide gap between the edges of the image and the actual lines of the sketch, as well as having potential distortions mainly from trimming it.
The main problem is that i can only get accurate locations (longitude and latitude) of some parts in the middle of the image (the lines themselves), and not the edges of it or the middle. When i come to put the image as a ground overlay, it only lets me input a center, a width (and maybe length) and a bearing. However, I have no idea how to transform those 4 co-ordinates into a center, width and bearing. can anyone from here help me with this?
I tried measuring the physical copies of the image with a ruler and doing some algebra but its very slow, prone to mistakes and i dont know if its that accurate. I thought to maybe put the cords manualy and showing the image to check if its allined and mess with it until it works, but when it tried implementing it i realirzed i dont know how to calculate the arguments needed (center width and bearing) from the cords.
i now think of maybe manually inputting the Anchor, Bearing and Width and checking that manually but It will be slow and tedius and very inaccurate, so hopefuly i can get help before too long.
some more info: i have a bird's eye view and GIS of the area but its a building with some floors so i can only know some locations on the outside. I dont know the locations of the bounderies since they are arbitrary on the sketch. I also have no real idea on what the orientation is, i really only have some Longitude Latitude pairs. They are also not rectangle, its just that i can ascosiate between them and certain points on the image.

convex path - how to?

Could someone explain me how convex path is calculated? I need to draw some cubic and additionally some lines but then path is shown as non convex. However when I leave only lines or just cubic it is then convex. The problem is that I need some non regular shaped background and need Convex path for shadow outline but can't get how I could connect drawing cubic with some lines to make convex path if it is even possible
A path is convex if it has a single contour, and only ever curves in a single direction.
Convex means it keeps bending / rotating in one direction, and one direction only. You really have to make sure that all your angles and curves add up. If your curve connects to a line it has to have the same angle or be "more convex", I hope the following 2 images will clear this up.
The picture below is not convex. That's also likely your problem. The line connects to a curve, but the curve has a different angle than the line and it will change the direction where it connects. See where the line goes down but instead of continuing the downwards-motion it suddenly goes up again. Instead of keeping one direction it will change for a moment where line and curve meet.
The above Image is exaggerated for clarity, but even small errors in the connection between the line and curve will trigger an error.
The next line connects to a curve with a steeper angle. This is convex and won't be a problem. See how the whole contour keeps a single motion in one direction, depending in which direction you follow it it keeps turning left/right.
I answered because I was facing a similar issue recently and I feel your pain. I recommend pen and paper to double and triple check the math and to use a small epsilon value to account for rounding errors etc... You really have to nail the math, because if your line and curve connection is just off by very little it will throw that exception.
Sorry for my bad paint skills

Draw many (250 k) polylines (a trail)

I have to draw a trail that contains more than 250.000 polylines with more than 500.000 coordinates. For my mobile deca core (10) and android 6.0 it takes more 1 minute to draw trail and the map become very slowly.
Is there a solution to draw it more quickly with a fast map ?
Note:
The same approach is executed in iOS speedly without problem, it takes 3 seconds to draw and the map is super fast.
The same question exists, but the proposed solutions do not work for me.
That is, perhaps, iOS doesn't draw all of them, obly approximated part, fitting current screen scale. You can do the same.
Take maximal area, fitting current zoom and suggest, that there should not be more than 100 lines. Add approximation algorithm, using fewer key points and calculate new lines

How to solve precision errors in GLES2.0

I have a map of Brazil composed of about 5000 polygons that each represent it's cities.
Although they share points, they are each their own polygon.
The problem is, that when i draw them all, they form holes in between them, which i assume comes from rounding errors, since these holes disappear/move when zooming/moving the camera.
The problem is even worse when the map is zoomed out.
How do i solve this kind of problem in GLES2.0 (Android)?
Unfortunately i can't enlarge each polygon, and although i could fuse them all into a 'Brazil' polygon and draw it below them, i'd rather avoid doing so since the frame rate is already lower than what i need it to be.
I also tried to add 'precision highp float;' to the start of the shaders, but that didn't change a thing
Two images to illustrate the problem. The first is the zoomed in map, and the other is a zoomed out map, both images are cropped to show only the map

Touch events are dropped in android

I am using FingerPaint example available in ApiDemos for drawing my finger movement on screen.
Now instead of line, I am adding circles in my path object and this path with circle will be drawn when onDraw method is called.
Now my issue is when I slowly move my finger it draws circles at the points given by onTouchEvent properly but when I move my finger with some speed, unlike line, it draws only few circles.
After debugging, I found that while moving finger rapidly, some of the touch events are dropped by the view and on that points circles are not drawn.
Can anyone give some pointers on this. Why this is happening?
Two things I can think of without seeing code.
First, are you getting the historical points recorded between touchEvents and using them also? If not, that would cause some serious jerkiness like you are talking about.
If you are, and it's just not picking them up, the best you'll be able to do might be to cheat it some. Check the distance between the current and last circle drawn. If it exceeds the circle's diameter too much, draw a line with the same thickness as the circle, with a circle on both ends.

Categories

Resources