From 635816d68e5f45e8c144beb955e1a698a69d6829 Mon Sep 17 00:00:00 2001 From: quanyawei <401863037@qq.com> Date: Wed, 10 Jan 2024 17:05:35 +0800 Subject: [PATCH] 添加经纬度选择 --- src/views/toCarryOutLegislativeReforms/components/locationMap.vue | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/views/toCarryOutLegislativeReforms/components/locationMap.vue b/src/views/toCarryOutLegislativeReforms/components/locationMap.vue index 7d6e68e..55060e6 100644 --- a/src/views/toCarryOutLegislativeReforms/components/locationMap.vue +++ b/src/views/toCarryOutLegislativeReforms/components/locationMap.vue @@ -23,8 +23,25 @@ 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> </div> <div id="mapd" /> </div> @@ -45,7 +62,8 @@ marker: null, placeSearchName: null, mapPlaceSearch: null, - position: [] + position: [], + positionInput: '' } }, mounted () { @@ -82,20 +100,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) @@ -109,6 +133,7 @@ map: map, position: that.$parent.position }) + that.positionInput = that.$parent.position.join(',') that.marker.setMap(map) that.map.setCenter(that.$parent.position) that.marker.setAnimation('AMAP_ANIMATION_BOUNCE') @@ -121,12 +146,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() @@ -147,6 +193,7 @@ position: relative; .searchBox{ position: absolute; + display: flex; z-index: 100; width: 100%; } -- Gitblit v1.8.0