智慧农业绘制地图
guoshilong
2022-09-03 b47e4c935112f10f60ea31e009c00a32597f5ce2
src/components/leafletDraw.vue
@@ -95,6 +95,12 @@
        },
        initDate () {
            var str = window.location.search.substring(1)
            var obj = this.getUrlParams(str)
            if(obj.latitude&&obj.longitude){
                this.lat = obj.latitude
                this.lng = obj.longitude
            }
            this.map = this.$L.map("map", {
                center: [this.lat, this.lng], // 地图中心
                zoom: 14, //缩放比列
@@ -188,7 +194,7 @@
            var str = window.location.search.substring(1)
            var parmasObj = this.getUrlParams(str)
            if(parmasObj.status!=""){//后台截图
            if(parmasObj.status){//后台截图
                domtoimage.toPng(document.getElementById('map'), { width: 970, height: 400 })
                .then( (dataUrl) => {
@@ -219,7 +225,7 @@
                    wx.miniProgram.navigateBack()
                })
                .catch(function (error) {
@@ -296,6 +302,21 @@
                e.layer.on('pm:vertexadded', e => {
                    console.log(e, "添加顶点")
                })
                var arr = []
                this.polygons.forEach(item => {
                    arr.push([item.lng, item.lat])
                })
                arr.push([this.polygons[0].lng, this.polygons[0].lat])
                let area = this.$turf.area(this.$turf.polygon([arr]))
                window.parent.postMessage(area,"*")
                this.map.flyToBounds(this.rectangleLayer.getBounds());
            })
        },