From 2c6d91d758241e1f97fe2790d92b754ea2cc860c Mon Sep 17 00:00:00 2001
From: quanyawei <401863037@qq.com>
Date: Thu, 28 Mar 2024 15:59:25 +0800
Subject: [PATCH] fix: 空气质量日报表显示
---
src/views/toCarryOutLegislativeReforms/components/locationMap.vue | 76 ++++++++++++++++++++++++++++++++++----
1 files changed, 68 insertions(+), 8 deletions(-)
diff --git a/src/views/toCarryOutLegislativeReforms/components/locationMap.vue b/src/views/toCarryOutLegislativeReforms/components/locationMap.vue
index fdda51b..4977b9b 100644
--- a/src/views/toCarryOutLegislativeReforms/components/locationMap.vue
+++ b/src/views/toCarryOutLegislativeReforms/components/locationMap.vue
@@ -23,8 +23,33 @@
prefix-icon="el-icon-search"
placeholder="���������������"
class="input-with-select"
+ style="margin-right: 10px"
@keyup.enter.native="searchPlace"
/>
+ <el-input
+ v-model="positionInput"
+ :disabled="$parent.mapType!=='edit'"
+ prefix-icon="el-icon-position"
+ placeholder="������������������"
+ class="input-with-select"
+ style="margin-right: 10px"
+ @keyup.enter.native="searchAddress"
+ />
+ <el-button
+ v-if="$parent.mapType==='edit'"
+ type="primary"
+ @click="search"
+ >
+ ������
+ </el-button>
+ <el-button
+ v-if="$parent.mapType==='edit'"
+ type="primary"
+ :disabled="placeSearchName===''"
+ @click="close"
+ >
+ ������
+ </el-button>
</div>
<div id="mapd" />
</div>
@@ -43,9 +68,10 @@
map: null,
geolocation: null,
marker: null,
- placeSearchName: null,
+ placeSearchName: '',
mapPlaceSearch: null,
- position: []
+ position: [],
+ positionInput: ''
}
},
mounted () {
@@ -82,20 +108,26 @@
let autoComplete = new AMap.Autocomplete(autoOptions)
AMap.event.addListener(autoComplete, 'select', function (e) {
that.map.clearMap()
- that.mapPlaceSearch.search(e.poi.name)
+ this.position = []
+ console.log('eee', e.poi.name)
+ console.log('eee', that.placeSearchName)
+ that.placeSearchName = e.poi.name
+ // that.mapPlaceSearch.search(e.poi.name)
})
AMap.event.addListener(that.mapPlaceSearch, 'markerClick', function (e) {
that.position = [e.data.location.lng, e.data.location.lat]
+ that.positionInput = e.data.location.lng + ',' + e.data.location.lat
this.placeSearchName = e.data.cityname + e.data.adname + e.data.address
console.log(e)
console.log(this.placeSearchName)
- document.getElementById('tipinput').value = e.data.name
+ document.getElementById('tipinput').value = e.data.cityname + e.data.adname + e.data.address
})
})
if (this.$parent.mapType === 'edit') {
map.on('click', function (ev) {
that.map.clearMap()
that.position = [ev.lnglat.lng, ev.lnglat.lat]
+ that.positionInput = ev.lnglat.lng + ',' + ev.lnglat.lat
that.marker = new AMap.Marker({
position: that.position,
offset: new AMap.Pixel(-13, -30)
@@ -105,14 +137,20 @@
})
} else {
this.map.clearMap()
- let marker = new AMap.Marker({
+ that.marker = new AMap.Marker({
map: map,
- position: this.$parent.position
+ position: that.$parent.position
})
- marker.setMap(map)
- marker.setAnimation('AMAP_ANIMATION_BOUNCE')
+ that.positionInput = that.toFixed(that.$parent.position[0], 8) + ',' + that.toFixed(that.$parent.position[1], 8)
+ that.marker.setMap(map)
+ that.map.setCenter(that.$parent.position)
+ that.marker.setAnimation('AMAP_ANIMATION_BOUNCE')
this.placeSearchName = this.$parent.address
}
+ },
+ toFixed (str, decimalPlaces) {
+ const num = parseFloat(str)
+ return num.toFixed(decimalPlaces)
},
getAddress (position) {
AMap.plugin('AMap.Geocoder', () => {
@@ -120,12 +158,33 @@
geocoder.getAddress(position, (status, result) => {
if (status === 'complete' && result.info === 'OK') {
this.placeSearchName = result.regeocode.formattedAddress
+ document.getElementById('tipinput').value = result.regeocode.formattedAddress
}
})
})
},
+ search () {
+ console.log('search', this.placeSearchName)
+ if (this.positionInput) {
+ this.searchAddress()
+ return
+ }
+ if (this.placeSearchName) {
+ this.searchPlace(this.placeSearchName)
+ }
+ },
searchPlace () {
this.mapPlaceSearch.search(this.placeSearchName)
+ },
+ searchAddress () {
+ this.map.clearMap()
+ this.marker = new AMap.Marker({
+ map: this.map,
+ position: this.positionInput.split(',')
+ })
+ this.marker.setMap(this.map)
+ this.map.setCenter(this.positionInput.split(','))
+ this.getAddress(this.positionInput.split(','))
},
close () {
this.map.destroy()
@@ -146,6 +205,7 @@
position: relative;
.searchBox{
position: absolute;
+ display: flex;
z-index: 100;
width: 100%;
}
--
Gitblit v1.8.0