Search code examples
leafletqgisturfjs

turf + leaflet, trouble getting positive result from booleanContains/booleanWithin


I've found that intersect works as expected when polygon edges overlap, but I can't seem to identify when one polygon wholly contains another. I created an example here:Stackblitz code example

As expected intersection returns null, but within/contains/overlap all return false. It's a pretty straightforward case, so I'm thinking I must be missing something, given how mature and widely used Turf is. If anyone sees the flaw or has another approach I'd be much obliged. Hit the Compare Features button for the results in the console.


Solution

  • You can use the function contains from leaflet

    let contains = this.geoRegion['_layers'][Object.keys(this.geoRegion['_layers'])[1]].getBounds().contains(this.geoRegion['_layers'][Object.keys(this.geoRegion['_layers'])[0]].getBounds()); 
    console.log("Contains",contains);