Merging overlays to display on MKMapView (iOS) or MapView (android) - android

I'm working on creating a mobile app which overlays images on top of a google map.
I have a large number of image overlays ('GroundOverlay' objects in KML-speak). I'm running into several issues (mainly performance) when the map is scrolled or zoomed
Having tried several options, I think my next approach will be to combine all the image overlays into one image beforehand, and then simply display that image as a single overlay on the map. Problem is, I'm not sure where to start.
Does anyone have any experience in combining overlay images?
I think there are two problems that need to be solved
1) Calculate the larger 'bounding box' that will contain the final image. I have the bounding box for each overlay ('LatLngBox' in KML-speak), and I think the final box can be calculated by simply examining the values of each LatLngBox and generating the final box based on the min/max values. Anyone have any insight as to whether this will work?
2) Merge all the overlay images into a single final image. I have no idea where to start here such here. Generating the actual image isn't the problem, but rather where to place each overlay (ie pixel level) so that the resulting image is accurate.
Any tips/hints would be greatly appreciated.
Thanks

the static overlay images can be combined and drawn. but the moving(regularly updated) overlay images would be an issue if you still want to combine them and post as one. the best option i believe would be to combine the static overlay resources and keep them in one set and other moving images drawn separately.

Managed to figure this out on my own.
Answer to (1): The technique I outlined in my question works perfectly
Answer to (2): You can convert between lat/lng and x/y pixels of an image as described here: Convert Lat/Longs to X/Y Co-ordinates

Related

Android - Get touch point coordinates relative to zoomed image

I'm looking for the best way(s) of getting the position of a point I touched on an image and get it's coordinates relative to the image size.
For example, I get, as the parent image, the map of a building floor. And the user need to be able to zoom in and point on the map a point that will be registered in a database in order to be retreived later.
I never really had to work with images and canvases on Android so I'm a bit confused. What might be the best approach. I already found a lot of document but couldn't find one that would fit the idea I need to develop.
Thanks in advance for you help,
Matthieu

Android game board with irregular board spaces

I'm creating an Android board game with several differently shaped board spaces (like Risk).
I want to be sure that my board appears correct and that OnTouchListeners stay in place on the GUI regardless of screen size/resolution.
Possible solutions I have thought of and their problems:
Create a single image for the board and assign OnTouchListeners based upon pixel geometry. Problem: If the user's display is a different resolution, my Listener might not be under the same pixels as my image (right?)
Create several ImageButtons and arrange them together. Problem: the ImageButtons might get rearranged based upon the display and I would end up with overlapping spaces or gaps.
Use Android custom drawing. If I do this, how would I link my Listeners to my Canvas and be sure that they are synced?
Basic question:
How to be sure that listeners sync with graphics in a GUI that uses irregular geometry?
I worked on an app with irregular touch areas so I can give you guidance on one way to achieve this.
Start with a single image for your entire board. This image is going to have a certain ("intrinsic") width and height regardless of any device resolutions.
Now here comes the tedious part. You (or maybe your graphic designer) will need to plot out coordinates of an irregular polygon for each touch area. These will be constants to your application.
When you are displaying your board, if you are zooming and panning on the image, you want to keep track of the transform matrix for the display. When the user touches the screen, you will get x,y coordinates from OnTouchListener and for those to be useful, you will have to "de-transform" the x,y to normalize it against the intrinsic dimensions of the board and your polygons.
We rolled our own hit-testing logic using an algorithm from http://alienryderflex.com/polygon/, but you can also try this: Create a Path out of your polygon coordinates (using moveTo(), lineTo(), and close()), then assign the Path to a Region using Region.setPath(). Once you have that, supposedly you should be able to hit-test using Region.contains(x,y), but I've never tried it so I can't guarantee that's going to work.

How to show a map which is a big image?

I got a png image which is 5000x5000. This image is some sort of map. I wanted to display the image in an imageview and this gave me an outOfMemoryException(of course). So i tried to set a sampleSize, but this decreased the resolution which makes the map not very usefull.
So basically I want to show this image and be able to zoom and scroll without resolution loses. What would be the best approach?
I am a fan of Dave Morrissey's SubsamplingScaleImageView, which seems to cover what you want. Quoting the project documentation, it is:
A custom image view for Android, designed for photo galleries and displaying huge images (e.g. maps and building plans) without OutOfMemoryErrors. Includes pinch to zoom, panning, rotation and animation support, and allows easy extension so you can add your own overlays and touch event detection.

Positioning images based on detecting reference points within another image

Let's say for example I have a bitmap image of a tree, and I want to position other images (such as bitmaps of apples) on the tree leaves. Is there a way that I could put markers on the leaves... red dots for instance... and then and then programmatically place apple images centered on those dots?
As a very basic test, I have image with a white background with one red pixel in the center. I'd like to calculate the coordinates of this red point, and then set an ImageView to be placed on those coordinates.
How might I go about this?
It depends, where your 'red point' marker is. If it's in the center or in any specific point (like 2/3 of width, 1/3 of height), you can just divide layout width and height to get right coordinates.
In other cases it would be better to set white background and draw markers manually in overriden dispatchDraw method. In such case you would just know the coordinates of the marker.
You want to position an image over the red dot, right?
I'm thinking of two different ways:
A-> You could make the red dot to be an ImageView itself, and then centering it by using gravity in order to transform it into another kind of image.
Or...
B-> Make a container that uses the white background with red dot as background resource. Then center it by using gravity too, and finally, positioning your image to the center of the container so it will be over the red dot.
No calculation is needed if you thing this could help.
It sounds like you are the one putting the markers onto your bitmaps.
If that is the case, is there a really good reason why you would want to be trying to embed the markers as data in the bitmap itself? That leads you to the problem of having to rediscover the locations. This could be a fuzzy task...what if there is a red barn next to the tree? Are you going to put an apple image on every red pixel making up the barn?
What you might actually want is to define a format which has a bitmap with no markers on it, and then a separate list of coordinates for where you want the apples to go. That doesn't require discovery of any kind...you just ship the image along with the list and you are done.
There are some cases where there is no "place on the side" that you can put information, and you actually need it to go into the bitmap file. If so, consider also that there are some hidden places you can put data in bitmaps... metadata like Exif:
http://en.wikipedia.org/wiki/Exchangeable_image_file_format
So that's a middle-ground, where you can manage to get the list of points to "stow away" into the file containing the image without actually requiring the modification of the pixels.
If you find you are really stuck in a situation where you must put these coordinate specifications into the image data, then something a little bit more unique than a red dot would be easier to detect with certainty. Maybe there's something you know about your images... for instance, that they are PNG files and do not have any transparency. You could make transparent dots indicate substitution points.
The larger and weirder the pattern, the more rare it is...so if you know your objects being pasted are always going to be bigger than 3x3 you could come up with a very unusual 3x3 pixel imprint for your markers that would be unlikely to occur in nature. Uncompressed in 24-bit color, a sufficiently random pattern would only happen 1/(2^24^9) by accident. Small number; although compression would create more gray areas.
But greater point being: if you don't have a good reason to turn a simple problem into a complex image-recognition exercise, don't. Just keep the list of points on the side somewhere so you don't have to hunt for them in the image.

create map shopping center (for example) on android

I Never faced with the task to create a map of the shopping center (for example)
I did a project using a single image as a map, image was maximum size, but the image quality is not enough. I understand i need many small images. if user scrolling or zoom or fling map i programmatically change images...
but,I do not know where to begin, please help me your solutions

Categories

Resources