mapbox / leaflet-pip

point in polygon intersections for leaflet
https://mapbox.github.io/leaflet-pip/
BSD 2-Clause "Simplified" License
199 stars 46 forks source link

Leaflet-pip is not working with Leaflet-draw plugin #27

Open fab-girard opened 7 years ago

fab-girard commented 7 years ago

Hello, I've tried to update my app with leaflet 1.0.x and I'm facing up to an incompatibility between 2 plugins:

Since this commit in leaflet-pip, function is_poly is not anymore able to take into account polygons just created with leaflet-draw. I thought leaflet-draw created an incorrect polygon in this issue but I suspect now leaflet-pip is maybe not enough permissive. I would suggest a PR which updates the is_poly function from your plugin:

function isPoly(l) {
    if (l instanceof L.Polygon) return true;
    return l.feature && l.feature.geometry && l.feature.geometry.type &&
        ['Polygon', 'MultiPolygon'].indexOf(l.feature.geometry.type) !== -1;
}

Indeed layer created by leaflet-draw has no l.feature && l.feature.geometry && l.feature.geometry.type attribute...

And maybe rollback entirely https://github.com/mapbox/leaflet-pip/commit/ff2b2f43df3d4a539afb587e7fe033046f6e3b7f for is_poly:

function isPoly(l) {
    return L.MultiPolygon && l instanceof L.MultiPolygon ||
        l instanceof L.Polygon ||
        l.feature && l.feature.geometry && l.feature.geometry.type &&
        ['Polygon', 'MultiPolygon'].indexOf(l.feature.geometry.type) !== -1;
}

What do you thinking about it ?

Fabien