Android: Custom region map - android

I am trying to implement a map(not Google maps) like in the below image, which will have a hypothetical regions(not administrative) with different colors to indicate the population density. The regions will also be clickable and cliking on that will open a small info overlay.
For now I have the sliced images for each region with multiple colors (which color to be used is determined from an API request). But I am not exactly sure how can I implement this in Android? I've been doing some research for past couple of days but couldn't find anything satisfactory so far.
Things that I am having trouble to implement:
Put together all those images and form the map
How can I detect "tap/click" event in the regions
In one brief conversation with a guy, he mentioned something of "greyscale overlay-map, that is not visible to the user and which determines the right area by testing against the greyscale color index", frankly I didn't understand what he meant.
Here's what I am trying to achieve:
Any help or pointer to the right direction would be of great help.
Thanks for your time.

Check out www.trimaps.com, I think this is what you want. Sadly it isn't free.

Related

OpenCV detecting hexagon grid on a map

I am trying to detect with OpenCv for Android hexagon fields of a map for a board game. The map looks something like that:
[Sample map]
I tried getting contours using only Value from HSV and I managed to get some of the hexagons, but unfortunately not all of them, I had mostly trouble detecting hexagons that had rivers or roads passing through them.
I managed to get something like that:
[Detected hexagons]
I even tried to make the borders thicker, but it didn't help a lot.
To detect all of the hexagons I thought of averaging the approximite size of the detected and then go on pixel by pixel trying to detect a change in the color (close to black). Later I would like to detect hexagons even on photos of a map, so then I couldn't really rely on the size of other hexagons.
What do you think would be the best way to solve this problem?
EDIT:
Thank you
I just began to implement your idea and it works great, for now i got the horizontal lines:
You deal with regular grid, so you just need to detect just a few, or even one, to compute all others. More will be better, because you'll be able to compute mean, and it will be more accurate. To find contours, it might be useful to find color gradient.

Android Game Development - Custom map leading to different activities

I'd like to create a custom map. It should be or look like one picture, but according to the part of which the user clicks, it should move the user to a different location (i.e. start a different activity). I've seen it done in several games but I don't know how to do it myself.
The part of the picture should have non-geometrical borders (obviously it would be easily done with many square images). Sadly, I don't even know what term describes what I want to do so I wasn't able to find any helpful tutorials or discussed topics.
Example:
Picture: http://i236.photobucket.com/albums/ff40/iathen/mapEx.png
If the user touches the purple slide, (s)he should be leaded to activity_1
If the user touches the blue slide, (s)he should be leaded to activity_2
If the user touches the green slide, (s)he should be leaded to activity_3
In my experience there are 2 main (most used) ways to achieve this.
The first (my favorite):
Get the data from a PNG
You should write multiple layers to a canvas. These layers constitute your "zones" (blue, green, purple in the image). To obtain the data of these areas, you get it from PNGs (with transparencies off course) to write the canvas with whatever you want. You must store the values where there can be a tap from the user (non-transparent areas). Notice that this values can be scaled up/down depending on the map size, screen resolution, map dimensions, etc.
Once you've written the layers to the canvas you should check for a match of the user tap and the stored areas you have. You should take into consideration here the order in which the user tap is processed in your code. For instance, in your image, the purple layer is on top so it must be processed first, the blue as second, and the green as the last one. This way you can have an "island" inside a bigger area.
The second way:
Generate the boundaries programmaticaly
I think this solution is self-explanatory. The only I've faced with this variant is that when the surfaces boundaries get messy, it's really complicated to generate the proper equations.
EDIT:
Using the first approach you can employ multiple PNGs to load data or use a single PNG with data coded into the bytes (i.e. RGB values). It's up to you to decide which one to implement.
Hope it helps!
Since a touchscreen itself isn't very accurate, your collision detection for the buttons doesn't need to be either. It would be a waste of time to try to make a complicated collision detection algorithm to detect a touch within those weird shapes.
Since you are making a game, I assume you know how to handle custom touch events, as well as canvas (at least). There are many ways to do what you want, but in the specific example image you linked is kind of a special case.
You could create a giant bounding circle around the three blobs, and then check if the user touched within the bounds of the circle (ie check if the distance from the touch to the center of the circle is less than or equal to the radius). Once you determine that it is, you could check which section of the circle it falls into by splitting it up into 3 equal sections. Requires some math, but shouldn't be that complicated.
It wouldn't be a perfect solution, but it should be good enough. Although, you might have to change the buttons a little so they aren't so stretched out horizontally, otherwise a bounding circle wouldn't be ideal.
Personally, in my games I always have "nodes" that represent the visual elements of the game, such as buttons. Instead of using a large image like you are doing, I would create separate images for each button, and then check their collisions with touch events independently. That way I could have each button check with their own individual bounding circles, or, if absolutely necessary, I could even have custom algorithms for each individual button.
These aren't perfect solutions. If you do want a pixel-perfect solution, you'll need to implement some polygon collision detection algorithms
One thing to consider is screen size and ratio. The only constants you should use are for percentages.

Mission impossible? google maps mask effects in iphone or android

i've come up with an idea that has a mask effects in google maps so that it can highlight a city .but i've searched the internet again and again found no document about this.
so ,is it possible to make mask effects in android or ios just like the effets below? and how to?
http://cadgis-blog.blogspot.com/2011/10/google-maps-create-cool-mask-effect-on.html
So there's two problems there. The first is where to get the boundary data from, and the second is how do you draw it on a map.
Answering the second part first, if you're using the iOS map view (MKMapView): you'll want to look into MKPolygonView. You can definitely highlight an arbitrary polygon, but the usual highlighting effect looks like a coloured overlay inside the polygon.
The thing to do, therefore, would be to make a huge polygon that encompasses the entire country, with your region as a hole in the polygon. That is, I believe, what your demo does. You can make an MKPolygon with the polygonWithPoints:count:interiorPolygons: method, and pass in your 'hole' as an interior polygon to be cut out.
Regarding the first part, how to get the data: what you need is a set of latitude/longitude pairs that make up the border for your region. Your example used this dataset, which is administrative borders for Switzerland. You'll need to find yourself a dataset that encompasses the borders for cities in the country you're interested in. I would imagine that you would store the coordinates of the borders in a database embedded in your app.

Android: Speedometer Style Layout

I have been trying to make a layout for an Android app that functions like a car Speedometer.
Something like this:
I basically want there to be 5 clickable Views across the radius of the dial, and have the dial point to the currently selected item. If possible it would be good to be able to click and drag the dial. I would also want this layout to work nicely with different screen sizes and resolutions, including tablets.
How could something like this be accomplished?
I don't know exactly how much this will help, but it goes over a similar design and shows how to place things at angles around a curve.
For each selectable view, I would also advise that you keep use keep track of the coordinates of each item, so you can use trig to calculate the proper angle for the dial to display (getting the dial to display at an angle is covered in that link).
So, you can set up OnClickListeners for each of your selectable items about the gauge, and in each instance, calculate the proper angle for the dial to spin to, and position it there using the information found in that link.
I'm not sure how much this helped, if at all, but it should at least give you an idea on creating custom Views and whatnot.
Good luck!

Custom layout in Android: scrollable graphic with selectable elements over top

I'm fairly new to the Android platform and was wondering if I could get some advice for my current head scratcher:
I'm making an app which in one view will need an image, which can be scrolled on one axis, with a load of selectable points over the top of it. Each point needs to be positionable on the x and y (unlikely to change once the app is running, but I'll need to fine tune the positions whilst I'm developing it).
I'd like to be able to let the user select each point and have a graphic drawn on the point the user has selected or just draw a graphic on one/more points without user intervention.
I though for the selectable points I could extend the checkbox with a custom image for the selected state - does that sounds right, or is there a better way of doing this? Is there any thing I can read up on doing this, I can't seem to find anything on the net about replacing the default images?
I was going to use the absolute layout, but see that it's been depreciated and I can't find anything to replace it.
Can anyone give me some code or advice on where to read up on what I need to do?
Thank you in advance
This really feels like something you should be doing with the Canvas and 2D graphics, rather than trying to twist the widget framework to fit.

Categories

Resources