How to get particular touch Area?

前端 未结 3 787
北荒
北荒 2021-01-17 06:54

I am new to Iphone Development,

Given the following map. I want to raise a touch event whenever i select a particular part like \"Western Australia\". But that parti

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 07:12

    In your linked map, you can see that each region is defined by polygons, represented by an array of vertices. (If you don't see this, then look at the html source and you will see it then.) You can find a lot of discussion on the internet about algorithms that can determine if a point is inside a polygon described this way. Here is one discussion that may be worth looking at, and before you get to discouraged by it's length (it is very thorough), look at the section titled The "Crossing Count" Algorithm. It's a pretty simple method compared to some of the others that I have seen. It comes down to determining it lines intersect and counting how many edges of the polygon intersect with a ray.

    You need to check the touched point against every polygon until you find one that it is inside. One thing that might be worthwhile is to first check if the touch point is inside the bounding box, defined by the min x, max x, min y, and max y values of the each polygon vertex array. If it's not inside the bounding box, then it's not inside the polygon.

    As far as detecting the touch event and where it is, look at my answer to this question, which tells how to determine where on the screen that the touch occured (using touch:locationInView:).

    I don't know if you intend to zoom in and out of your images, but that will add some complications to how you go about this. If this response doesn't quite help, could you provide more info on what you are trying to do?

提交回复
热议问题