guanqb
2022-10-15 88a309b2b962a9b9824be5af622df48d290fac28
获取中心点坐标
4 files modified
19504 ■■■■■ changed files
package-lock.json 19419 ●●●●● patch | view | raw | blame | history
package.json 1 ●●●● patch | view | raw | blame | history
src/main.js 3 ●●●●● patch | view | raw | blame | history
src/views/home/index.vue 81 ●●●●● patch | view | raw | blame | history
package-lock.json
Diff too large
package.json
@@ -9,6 +9,7 @@
    },
    "dependencies": {
        "@dvgis/dc-sdk": "^2.16.2",
        "@turf/turf": "^6.5.0",
        "axios": "^0.22.0",
        "core-js": "^3.6.5",
        "echarts": "^5.2.1",
src/main.js
@@ -40,7 +40,10 @@
import DcS3M from '@dvgis/dc-sdk/dist/dc.s3m.min' //s3m包
import '@dvgis/dc-sdk/dist/dc.core.min.css' // 主要样式
import * as turf from '@turf/turf'
Vue.prototype.$echarts = echarts
Vue.prototype.$turf = turf
global.DC = DC
global.echarts = echarts
src/views/home/index.vue
@@ -667,22 +667,19 @@
                        }
                    })
                    let titleLng = center[0] - 0.01
                    let titleLat = center[1] - 0.03
                    this.$EventBus.$emit('layerPointAdd', {
                        layerName: 'policeStationLayer',
                        type: 'label',
                        params: {
                            lng: titleLng,
                            lat: titleLat,
                            lng: center[0],
                            lat: center[1],
                            alt: 0,
                            text: item.policeStationName
                        },
                        distanceDisplayCondition: {
                            near: 20000, //最近距离
                            far: 200000 //最远距离
                        }
                        // distanceDisplayCondition: {
                        //     near: 20000, //最近距离
                        //     far: 200000 //最远距离
                        // }
                    })
                    let cylinder = new global.DC.LightCylinderPrimitive(new global.DC.Position(center[0], center[1]), 1200, 1, 600)
@@ -702,6 +699,19 @@
            this.initAreaCheckoptions(this.BMareaCheckoptions)
            this.initAreaCheckoptions(this.LXareaCheckoptions)
            this.houseChange(true)
            let points = []
            this.policeStationOptions[1].position.forEach(item => {
                let jin = Number(item[0])
                let wei = Number(item[1])
                let cartesian3 = global.DC.T.transformWGS84ToCartesian(new global.DC.Position(jin, wei))
                points.push(cartesian3)
            })
            console.log('points11111', points)
            let areaCenter = global.DC.Namespace.Cesium.BoundingSphere.fromPoints(points).center
            console.log('areaCenter222222', areaCenter)
            let position3 = global.DC.T.transformCartesianToWGS84(areaCenter)
            console.log('position3', position3)
        })
        // axios.get('/user/getUserList').then((res) => {
@@ -733,8 +743,10 @@
            } else {
                if (item.policeStationName == '车站派出所') {
                    this.$EventBus.$emit('toPosition', {
                        siteJd: 116.082737,
                        siteWd: 28.724034,
                        // siteJd: 116.082737,
                        // siteWd: 28.724034,
                        siteJd: 115.963097,
                        siteWd: 28.669357,
                        siteGd: 18000,
                        siteHeading: -3,
                        sitePitch: -90
@@ -745,7 +757,7 @@
                    this.areaOptions.push({ name: "责任区" + (i + 1) })
                }
                console.log(this.areaOptions)
                // console.log(this.areaOptions)
            }
        },
@@ -775,30 +787,15 @@
        },
        getCenter (arr) {
            let centerLonLat = []
            if (arr.length) {
                const lon = []
                const lat = []
                const poly = []
                for (let i = 0, len = arr.length; i < len; i++) {
                    lon.push(arr[i][0])
                    lat.push(arr[i][1])
                }
                for (let i = 0, len = lon.length; i < len; i++) {
                    poly.push({
                        x: parseFloat(lon[i]),
                        y: parseFloat(lat[i]),
                        z: 0
                    })
                }
                const sortedLongitudeArray = poly.map(item => item.x).sort()
                const sortedLatitudeArray = poly.map(item => item.y).sort()
                const centerLongitude = ((parseFloat(sortedLongitudeArray[0]) + parseFloat(sortedLongitudeArray[sortedLongitudeArray.length - 1])) / 2).toFixed(14)
                const centerLatitude = ((parseFloat(sortedLatitudeArray[0]) + parseFloat(sortedLatitudeArray[sortedLatitudeArray.length - 1])) / 2).toFixed(14)
                // console.log(centerLongitude, centerLatitude)
                centerLonLat = [Number(centerLongitude), Number(centerLatitude)]
            }
            return centerLonLat
            let positions = []
            arr.forEach((item, index) => {
                positions[index] = [item[0], item[1]]
            })
            positions.push([arr[0][0], arr[0][1]])
            let polygon = this.$turf.polygon([positions])
            let center = this.$turf.centroid(polygon)
            console.log([positions], polygon, center, 123)
            return [center.geometry.coordinates[0], center.geometry.coordinates[1]]
        },
        navClick (e) {
@@ -896,6 +893,7 @@
                landMyChart.resize()
            })
        },
        initLandOptions (xDate, y1Date, y2Date) {
            return {
@@ -959,6 +957,7 @@
            }
        },
        landTabClick (type) {
            this.tabTypeTwo = type
@@ -1301,11 +1300,7 @@
                this.$EventBus.$emit('layerPolygonAdd', {
                    layerName: 'polygonLayer',
                    positions: str,
                    material: this.positionColor[index],
                    distanceDisplayCondition: {
                        near: 0, //最近距离
                        far: 20000 //最远距离
                    }
                    material: this.positionColor[index]
                })
                const center = this.getCenter(item.position)
@@ -1317,10 +1312,6 @@
                        lat: center[1],
                        alt: 0,
                        text: item.areaCheckName
                    },
                    distanceDisplayCondition: {
                        near: 0, //最近距离
                        far: 20000 //最远距离
                    }
                })
            })