Return 与 Turf JS 库相交的 Leaflet GeoJSON 多边形

Return Leaflet GeoJSON polygons that intersect a point with Turf JS library

传单和草皮。当用户单击地图时,我正在尝试查找与点相交的 Leaflet 地图上的所有图层。我正在使用 turf 库对此进行测试。在控制台中,当我点击地图时 returns 这个错误:

var c = new L.GeoJSON.AJAX("http://127.0.0.1:8000/childcare_buff_data/",{
        style: color(c, "orange", 0.8)})
        ;
    c.addTo(map);

    map.on('click',function(e){
        lat = e.latlng.lat;
        lon = e.latlng.lng;
        ProcessClick(lat,lon)
    });

    var theMarker;
    var a;

    function ProcessClick(lat,lon){
        theMarker = L.marker([lat,lon]).addTo(map);
        c.eachLayer(function(layer) {
            intersects=turf.intersect(theMarker.toGeoJSON(),layer.toGeoJSON());
            if (intersects){
                a=layer.feature.properties.buff
                console.log(a);
                }
            })};

我收到这个错误

turf.min.js:1 Uncaught TypeError: Cannot read property 'length' of null
    at turf.min.js:1
    at turf.min.js:1
    at S (turf.min.js:1)
    at Pn (turf.min.js:1)
    at Object.Lo [as intersect] (turf.min.js:1)
    at js2.js:31
    at eachLayer (leaflet.js:5)
    at ProcessClick (js2.js:30)
    at e.<anonymous> (js2.js:22)
    at e.fire (leaflet.js:5)

这是 geojson http://www.mediafire.com/file/9fnbz32ib9n1aaj/childcare.geojson/file

更新

通过使用

turf.booleanWithin(theMarker.toGeoJSON(),geom.toGeoJSON());

我得到

turf.min.js:1 Uncaught Error: coordinates must only contain numbers
    at Y (turf.min.js:1)
    at Y (turf.min.js:1)
    at U (turf.min.js:1)
    at Pt (turf.min.js:1)
    at Object.Cn [as booleanWithin] (turf.min.js:1)
    at js2.js:33
    at eachLayer (leaflet.js:5)
    at ProcessClick (js2.js:31)
    at e.<anonymous> (js2.js:22)
    at e.fire (leaflet.js:5)

intersect 需要两个多边形作为它的参数,但你给它一个点因此缺少 length 属性 :

Takes two polygons and finds their intersection

请尝试 turf.booleanWithin(theMarker.toGeoJSON(), layer.toGeoJSON())

Boolean-within returns true if the first geometry is completely within the second geometry.