I'm having two sets of polygon coordinates selected from leaflet geoJSON map. The parent and child coordinates are coordinates are:
var parentCoordinates=[
[
32.05898221582174,
-28.31004731142091
],
[
32.05898221582174,
-28.308044824292978
],
[
32.06134255975485,
-28.308044824292978
],
[
32.06134255975485,
-28.31004731142091
],
[
32.05898221582174,
-28.31004731142091
]
]
var childCoordinates=[
[
32.059904895722866,
-28.30970726909422
],
[
32.059904895722866,
-28.308743809931784
],
[
32.06089194864035,
-28.308743809931784
],
[
32.06089194864035,
-28.30970726909422
],
[
32.059904895722866,
-28.30970726909422
]
]
The child is drawn inside the parent area as shown in the picture:
Using Ray Casting algorithm to determine if the point lies inside polygon I 'm not able to determine as the result I'm getting is false. Please let me know where I'm doing wrong or any other way to determine the solution.Thanks
Click on the map or the markers and a pop-up will show indicating if the point you clicked on, or the marker, is in the polygon. Leaflet.
One simple way of finding whether the point is inside or outside a simple polygon is to test how many times a ray, starting from the point and going in any fixed direction, intersects the edges of the polygon. If the point is on the outside of the polygon the ray will intersect its edge an even number of times.
To determine the status of a point (xp,yp) consider a horizontal ray emanating from (xp,yp) and to the right. If the number of times this ray intersects the line segments making up the polygon is even then the point is outside the polygon.
You can try Leaflet's api for that - contains
. You create a parent polygon with LatLngBounds and then child too.
parentPolygon.contains(childPolygon)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With