智慧农业后台管理页面
guoshilong
2022-09-13 d4a7ff209253655b044397d50fcb6e5480220a78
地图模式地块未绘制时报错
1 files modified
30 ■■■■■ changed files
src/components/map/plotMap.vue 30 ●●●●● patch | view | raw | blame | history
src/components/map/plotMap.vue
@@ -474,18 +474,7 @@
        // 经纬度测算中心位置
        getCenter (arr) {
            var positionArr = []
            arr.forEach(e=>{
                // e = new global.DC.Namespace.Cesium.Cartesian3(e[0]-0, e[1]-0, 0)
                e[0] = e[0]-0
                e[1] = e[1]-0
                positionArr.push(e)
            })
            positionArr.push(arr[0])
            var positionTurf = [positionArr]
            var polygon = turf.polygon(positionTurf);
            var centroid = turf.centroid(polygon);
            let centerLonLat = []
            // if (arr.length) {
            //     const lon = []
            //     const lat = []
@@ -509,7 +498,22 @@
            //     centerLonLat = [Number(centerLongitude), Number(centerLatitude)]
            //     console.log("中心",centerLonLat)
            // }
            centerLonLat = [centroid.geometry.coordinates[0],centroid.geometry.coordinates[1]]
            let centerLonLat = []
            if(arr.length >= 3 ){
                var positionArr = []
                arr.forEach(e=>{
                    // e = new global.DC.Namespace.Cesium.Cartesian3(e[0]-0, e[1]-0, 0)
                    e[0] = e[0]-0
                    e[1] = e[1]-0
                    positionArr.push(e)
                })
                positionArr.push(arr[0])
                var positionTurf = [positionArr]
                var polygon = turf.polygon(positionTurf);
                var centroid = turf.centroid(polygon);
                centerLonLat = [centroid.geometry.coordinates[0],centroid.geometry.coordinates[1]]
            }
            return centerLonLat
        }
    }