Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

imagemap - iPhone, Map, Clickable non-rectangular areas

Anyone have any ideas on how I could implement the following on the iPhone? We have a map of the US, and it has different regions (climate regions, I believe) that are different colors. They are not rectangular, and don't follow state or zip or county or any other defined lines. So, our areas a very round-y and not even necessarily contiguous.

I would LOVE to give our users the ability to click on their region and I would be able to tell from where they touched what region it was, but for the life of me, short of making many many many rectangles to do a best fit on the curves, I can't figure out how to do this.

Any ideas?

EDIT: The regions could be as hard as this... link text

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How are these regions defined? If you can get the point data, then create a CGPath using:

CGPathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,null,xpoints[0],ypoints[0])
for (int i = 1; i < numpoints; ++i) {
  CGPathAddLineToPoint(path,null,xpoints[i],ypoints[i]);
}
CGPathCloseSubpath(path);

Then whenever the user touches, for each region, check whether it contains the touch point:

if (CGPathContainsPoint(path,null,touchPoint,false)) ...

And don't forget to release when you're done with the regions:

CGPathRelease(path);

Note that you can create several separate subpaths in one CGPathRef and it will check all the subpaths when you check for containment.

If you want to, you can try using arcs or curves to get the lines right, but that's something I'm not too familiar with.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...