wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to draw US map ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to draw US map ?" Watch "How to draw US map ?" New topic
Author

How to draw US map ?

Bhaskar Gunturi
Greenhorn

Joined: Apr 03, 2002
Posts: 4
In my application, I have to show the US map in which if the user clicks on any state I have to identify the state and show some details accordingly. I dont know how to identify the individual states once the user clicks on the map. Does anyone have an idea how to proceed with this? Thanks in advance.
Bhaskar
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Hi Bhaskar,
A good starting point will be to check out the demo provided in your j2se installation. You'll find it here -
wherever_ur_java_is_installed\demo\applets\ImageMap
You take an image & do an image map sorta thing on it.
Merry deciphering the code
Ashish H.
Bhaskar Gunturi
Greenhorn

Joined: Apr 03, 2002
Posts: 4
I know how to use the Image maps, but once the US map is drawn and when a user clicks on a particular state I need to identify the portion where he has clicked. I am stuck on this part. Any help in this matter is highly appreciated.
Bhaskar
[ December 30, 2002: Message edited by: Bhaskar Gunturi ]
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
This one is totally outta the blue but I think it should work -
Take your image & use some image map drawing utility to draw a regular image map. Now you'll get your coordinates. Now whenever the mouse is clicked on the image you get the coordinates & see if it fits in a particular polygon(say the polygon that bounds nyc), do the routine you'd want for nyc (like maybe get detailed map for nyc). If your image is not positioned at (0,0) you might also wanna do some translation for the coordinates.
I know this sounds simple right now, but you might face some really trivial issues. Besides, there might be some other way aswell. Let's see if someone else can enlighten us.
Ashish H.
Bhaskar Gunturi
Greenhorn

Joined: Apr 03, 2002
Posts: 4
The real problem is getting the coordinates of the polygon shape say for some state like new york. There should be some way in identifying the states. I have seen some applets on net doing this. In one of the applet they took 2 images of US map and when the cursor is placed on one state, the image of the second is superimposed on the first one with only the state where the cursor is placed is being shown. I do want to implement in the same way. Any ideas...
Bhaskar
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Like I said, use some image-map drawing utility to get your co-ordinates. As for the superimposing stuff look into the setComposite() method of the Graphics2D class.
HTH
Ashish H.
 
 
subject: How to draw US map ?
 
Similar Threads
Some GUI help
displaying text in textArea
Marking the current Selected Table Row
Advice needed from Game Players
Find source of button click