派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-30 8d755b0755dac542cc092ab8e40e65ba8d664bc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<template>
    <div class="location-lon-and-lat">
        <!--        <el-row>-->
        <!--            <el-form :model="lonlatpos" label-width="60px">-->
        <!--                <el-col :span="12">-->
        <!--                    <el-form-item label="经度:">-->
        <!--                        <el-input type="text" v-model="lonlatpos.longPos"></el-input>-->
        <!--                    </el-form-item>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12">-->
        <!--                    <el-form-item label="纬度:">-->
        <!--                        <el-input type="text" v-model="lonlatpos.latPos"></el-input>-->
        <!--                    </el-form-item>-->
        <!--                </el-col>-->
        <!--            </el-form>-->
        <!--            <el-row>-->
        <!--                <el-col :span="12" style="text-align: center;margin: 5px 0">-->
        <!--                    <el-button type="primary" size="small" @click="mapPoints">精确定位</el-button>-->
        <!--                </el-col>-->
        <!--                <el-col :span="12" style="text-align: center;margin: 5px 0">-->
        <!--                    <el-button type="primary" size="small" @click="dataPoints">数据识取</el-button>-->
        <!--                </el-col>-->
        <!--            </el-row>-->
        <!--        </el-row>-->
        <el-form :model="lonlatpos" label-width="60px">
            <el-row class="pipe-line-search">
                <el-col :span="12">
                    <el-form-item label="经度:">
                        <el-input v-model="lonlatpos.longPos"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="纬度:">
                        <el-input v-model="lonlatpos.latPos"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-row>
            <el-col :span="12" style="text-align: center;margin: 5px 0">
                <el-button type="primary" size="small" @click="mapPoints">精确定位</el-button>
            </el-col>
            <el-col :span="12" style="text-align: center;margin: 5px 0">
                <el-button type="primary" size="small" @click="dataPoints">数据识取</el-button>
            </el-col>
        </el-row>
        <el-row class="place-bottom" style="text-align: right;margin: 5px">
            <el-button type="primary" @click="confirm" size="small">确认</el-button>
        </el-row>
    </div>
</template>
 
<script>
import { pulseEffect } from '../../../../utils/utils'
import iconUrl from '../../../../../public/assets/images/map/marker-icon.png'
import eventBus from '../../../../eventBus'
 
export default {
  name: 'ReportLocationPoint',
  data () {
    return {
      // 经纬度定位
      lonlatpos: {
        longPos: '',
        latPos: ''
      },
      marker: null
    }
  },
  methods: {
    // 精确定位
    mapPoints () {
      window.map.on('click', (e) => {
        this.lonlatpos.longPos = parseFloat(e.latlng.lng).toFixed(8)
        this.lonlatpos.latPos = parseFloat(e.latlng.lat).toFixed(8)
        const as = [e.latlng.lat, e.latlng.lng]
        // console.log(as)
        window.map.setView(as, 17)
        pulseEffect(as)
        this.marker = window.L.marker(as, {
          icon: window.L.icon({
            iconUrl: iconUrl,
            iconSize: [26, 40],
            iconAnchor: [13, 20]
          })
        })
        window.map.addLayer(this.marker)
        window.map.off('click')
      })
    },
    // 通过数据定位
    dataPoints () {
      // this.lonlatpos.latPos = ''
      // this.lonlatpos.longPos = ''
      if (this.lonlatpos.latPos !== '' && this.lonlatpos.longPos !== '') {
        const as = [this.lonlatpos.latPos, this.lonlatpos.longPos]
        window.map.setView(as, 17)
        pulseEffect(as)
        this.marker = window.L.marker(as, {
          icon: window.L.icon({
            iconUrl: iconUrl,
            iconSize: [30, 40],
            iconAnchor: [15, 20]
          })
        })
        window.map.addLayer(this.marker)
      } else {
        this.$message('请输入识取经纬度')
      }
    },
    // 点击确认按钮事件
    confirm () {
      window.mapManager.clearHighlight()
      window.map.removeLayer(this.marker)
      eventBus.$emit('location-setChange', true)
      this.lonlatpos.longPos = ''
      this.lonlatpos.latPos = ''
    }
  }
}
</script>
 
<style lang="less" scoped>
    .place-box {
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
 
    .place {
        text-align: center;
 
        .place-top {
            display: flex;
            align-items: center;
            justify-content: space-around;
 
            .place-right {
                .el-button {
                    margin: 15px;
                }
            }
        }
    }
</style>