How to detect if polygons overlap in leaflet

user1533947 picture user1533947 · Sep 18, 2014 · Viewed 7.5k times · Source

I am using leaflet draw to create polygons. My requirement is when a user draws a polygon ,it should not intersect/overlap with existing polygons. I have used point in polygon leaflet to detect if point falls within the polygon and it is working, but the problem is i am not able to detect if a line crosses another polygons.In this case points lie outside the existing polygons but overlapping exists.

Below attached image can give a better picture!Polygons overlap in this

Answer

kmandov picture kmandov · Apr 9, 2015

You can also probably use Turf.js. Turf is a new js GIS engine developed by the guys at Mapbox.

Here are few examples that may do the job: