首页 > 解决方案 > 带有马丁内斯交集的传单:无效的 LatLng 对象:(-8.39,37.08,-8.39,37.08)

问题描述

我有一张传单地图,我在其中添加了一些由(docs)函数FeatureCollection生成的多边形。现在我正在尝试将这些多边形与代表一个国家/地区相交,以便 Voronoi 多边形仅在所述国家/地区内显示。对于我正在使用martinez的十字路口。voronoiturfjsMultiPolygon

Voronoi 多边形:

var voronoiPolygons = turf.voronoi(poll1); //Creating the Polygons
voronoiPolygons.features.map((f, i) => {
    f.properties = poll1.features[i].properties; //Adding the original properties to the new Polygons
});

与国家边界的交汇处:

voronoiPolygons.features.forEach(trimBorder);

function trimBorder(value,index,array){
    //Intersection using Martinez, returns set of coordinates
    let newPolygon = martinez.intersection(value.geometry.coordinates, borderPT.geometry.coordinates);

    //Change the feature type to MultiPolygon if the intersection generates a MultiPolygon
    voronoiPolygons.features[index].geometry.coordinates = newPolygon;
    if (newPolygon.length > 1) voronoiPolygons.features[index].geometry.type = "MultiPolygon"; 
}

但是,当我运行它时,我收到以下错误:

Uncaught Error: Invalid LatLng object: (-8.395214820999854,37.08713944100005, -8.395575540353551,37.08710300941793)
    at new D (LatLng.js:32)
    at We (GeoJSON.js:235)
    at He (GeoJSON.js:248)
    at He (GeoJSON.js:247)
    at De (GeoJSON.js:203)
    at i.addData (GeoJSON.js:117)
    at i.addData (GeoJSON.js:107)
    at initialize (GeoJSON.js:92)
    at new i (Class.js:22)
    at Object.Ke (GeoJSON.js:439)

据我了解,该对象中不应有两组坐标。这是什么原因造成的?

标签: javascriptleafletvoronoiturfjs

解决方案


推荐阅读