Making a clickable United States map

Black_Mc_Jack

New member
Joined
Nov 21, 2006
Messages
3
Programming Experience
Beginner
For my Computer Information System class, I'm trying to make a map in VB.Net so that I can click on the individual states to change to state bird at the bottom. This is for fun so is not it's in our books and I have tried to research image maps, like I use in html and asp.net, but I could not find any. I need help. My use in VB.net is at a good level but I just don't know.
 
Why not put in an image of a map on your form or in a picture box then put a button or probably better yet a link label control on each state with the state 2 letter name over each state.

The user would have to click on the button or label and not anywhere in the state, but atleast you'd have a click event to work with.
 
oh ya, alternatively you can use the forms mousedown event and it returns the X and Y location of the mouse click, so if you knew washington, for example, had a X coordinate of 125 to 212 and a Y coordinate of 55 to 118 you could create 50 if/then statements in your mouse_down event.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_MouseDown([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.MouseEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].MouseDown[/SIZE]
[SIZE=2]MsgBox(e.X & [/SIZE][SIZE=2][COLOR=#008000]" "[/COLOR][/SIZE][SIZE=2] & e.Y)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
The x and y coordinate should work, but for that you work I would have to use an if statement for every coordinate and I don't want the code to get too messy. Almost all languages seem to have something like image maps, does anyone know?
 
Imagemaps in Vb.Net winforms can be made by recording the Point data to a list of GraphicsPaths, which can be used by Region class to see if a Point within this path region.

Included is a rough sketch of an application (RegionGenerator) that generates such map data. You can load an image and record regions with menu choice 'Start new'/'Close new' - click Start, click all the points in picture and click Close. There is also some preview functionality from same GP menu. The data is loaded/saved with binary serialization.

The saved data can be imported into application that use it to provide active map functionality, included is an example project (UsingRegions), run it and click the image to see it.

Both applications reference the common class library (GPInfos) used as storage for data and is required for serialization of custom class type between different assemblies, ie the generator app and the 'client' app.

This is all very unrefined (I did it in about an hour now just for fun), but you get for free a functional map generator and demo map app, hope you find it a useful base and understandable.
 

Attachments

  • vbnet20-gps.zip
    111.6 KB · Views: 64
You can also create a web page image map and display it in a WebBrowser control in winforms application, but I'm not sure how easy that would be to interact with the application.. probably have to set hidden page field with Javascript and read it through the DHtml DOM.
 
Thanks for your help, I'll try to firgure it out, but while messing around in class I had an Idea. Could I possbile make a shape with the Graphics class and then make it clickable? Then I could just make the shapes transparent.
 
That's what it does. You just have to run the 'UsingRegions' project to see that in action.
 
Back
Top