Search code examples
javadictionaryimagemap

image map in java?


I'm creating a small kids game, where I have a map of ireland in a Panel, and a question will pop up asking the user to click a certain County. what's the best way of going about dividing the map up into individual sections for each county?

so i'll have a question pop up at random asking "Where is Dublin?" then the use clicks on the black point at dublin.

i have an idea how i'll go about the questions coming up at random(if not i'll be back later), but any suggestions of assigning hotspots to my image?

Map of Ireland


Solution

  • I assume this is one image and it is shown non-rescaled

    So you can

    1. Pre-calculate and write down in file or data structure locations of black dots (i.e. Photoshop)
    2. When a user clicks get coordinates
    3. Find a nearest black dot to point clicked by user

    UPD: With step 1 you can decide some radius of accuracy for each black point. If clicked point is not within radius of accuracy of nearest black point, you can ask user to clarify.

    UPD2: One more approach to improve accuracy is to remember color of area for each black point. If color of clicked point is not same of color of area of nearest black point then ask user to click again.