Jump to content

Find What Image Map Area A Pixel Is In


duncan_cowan

Recommended Posts

I have a map of the world and each country is an area on an image map.The user will select a start location and an end location and the script will cycle through each pixel in a direct line from the start to the end and i want to find out what country the pixel is in or if it is over sea.

Link to comment
Share on other sites

Correct, there's not a built-in way to do that. You would need to have a Javascript array or something similar where you define the regions and what pixels they cover that you can use to cross-reference a pixel with a region.

Link to comment
Share on other sites

You could devise an algorithm and mathematical formula to find out which pixels are in the area by the coordinates. I'm not going to tell you how to do that, though. I'd need to do some research myself, it's not something simple because it requires geometry.

Link to comment
Share on other sites

That would involve dividing the region into specific polygons like triangles and squares, and then computing the area of the parts. The formulas for computing the area of a triangle or square are well-known.

Link to comment
Share on other sites

hmmm, sounds complicated.May look into finding the pixels that lie along the lines of the edge of the polygon and finding if the path crosses one of these lines.Thanks for the posts.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...