简体   繁体   English

iPhone,地图,可点击的非矩形区域

[英]iPhone, Map, Clickable non-rectangular areas

Anyone have any ideas on how I could implement the following on the iPhone? 任何人对如何在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 编辑:区域可能像这个... 链接文本一样难

How are these regions defined? 这些地区是如何定义的? If you can get the point data, then create a CGPath using: 如果可以获取点数据,则使用以下命令创建CGPath:

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. 请注意,您可以在一个CGPathRef中创建多个单独的子路径,并在检查包含时检查所有子路径。

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. 如果你愿意,你可以尝试使用弧线或曲线来获得正确的线条,但这是我不太熟悉的东西。

Maybe you need a color coded bitmap to do your hit testing against. 也许你需要一个颜色编码的位图来进行你的命中测试。

You would have one bitmap to display, but another bitmap that has single-color-coded regions. 您可以显示一个位图,但另一个位图具有单色编码区域。 When the user clicks on the display map you check out what color that pixel is in your hit test map, and then perform the approriate action. 当用户单击显示地图时,您可以检查该命中测试图中该像素的颜色,然后执行相应的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM