zhouwx
2025-03-24 3f6bf89b1985b6668f02ffcc9af577b412e92e45
src/views/safetyReview/projectManage/components/mapLocation.vue
@@ -17,15 +17,29 @@
      </div>
      <div class="mapLocation_latlng">
        <span>经度:</span>
        <el-input class="mapLocation_latlng_input" id="lng" v-model="state.longitude"></el-input>
        <el-input class="mapLocation_latlng_input" id="lng" v-model.trim="state.longitude" @change="getAdress"></el-input>
      </div>
      <div class="mapLocation_latlng">
        <span>纬度:</span>
        <el-input class="mapLocation_latlng_input" id="lat" v-model="state.latitude"></el-input>
        <el-input class="mapLocation_latlng_input" id="lat" v-model.trim="state.latitude" @change="getAdress"></el-input>
      </div>
      <div class="mapLocation_latlng">
        <span>地址:</span>
        <el-input class="mapLocation_latlng_input" id="lat" v-model.trim="state.BAddress"></el-input>
      </div>
    </div>
    <div class="mapLocation_body">
      <baidu-map class="map" ak="BkZdiHBj9aGrMdVFM48r2njNiMzsekga" v="3.0" type="API" :center="state.center" :zoom="15" scroll-wheel-zoom @ready="initMap" @click="getPosition">
      <baidu-map class="map"  @ready="getAdress" ak="BkZdiHBj9aGrMdVFM48r2njNiMzsekga" v="3.0" type="API" :center="state.center" :zoom="state.zoom" scroll-wheel-zoom  @click="getPosition">
        <div style="position: absolute;z-index: 999;margin-top: -495px">
          <label>搜索:<input v-model="state.keyword"></label>
          <bm-local-search
              :keyword="state.keyword"
              :auto-viewport="true"
              location="新疆"
              :pageCapacity="3"
          ></bm-local-search>
        </div>
        <bm-marker :position="{lng: state.longitude, lat: state.latitude}" :dragging="true" animation="BMAP_ANIMATION_BOUNCE">
          <bm-label content="选择地点" :labelStyle="{color: 'red', fontSize : '24px'}" :offset="{width: -35, height: 30}"/>
        </bm-marker>
@@ -39,17 +53,21 @@
</template>
<script setup>
import {ref, onMounted, reactive, toRefs, defineComponent,defineExpose,defineEmits} from 'vue';
import { BaiduMap,BmMarker } from 'vue-baidu-map-3x'
import {ref, onMounted, reactive, toRefs, defineComponent, defineExpose, defineEmits, watch} from 'vue';
import { BaiduMap,BmMarker,BmLocalSearch } from 'vue-baidu-map-3x'
const state = reactive({
  title: '',
  longitude: '',
  latitude: '',
  mapLocationVisible: false,
  zoom: 7,
  center: {
    lng: '116.404',
    lat: '39.915'
  }
    lng: '116.42585576793277',
    lat: '39.88973394962104'
  },
  keyword:'',
  location: '',
  BAddress: ''
})
const emit = defineEmits(['giveLatLng'])
@@ -62,11 +80,27 @@
const getPosition = ({type, target, point, pixel, overlay})=>{
  state.longitude = point.lng
  state.latitude = point.lat
  getAdress()
}
const openMapLocation=(longitude,latitude)=>{
  state.longitude = longitude
  state.latitude = latitude
  if(longitude != ""){
    state.longitude = longitude
    state.latitude = latitude
    state.zoom = 13
    state.center = {
      lng: longitude,
      lat: latitude
    }
  }else {
    state.zoom = 7
    state.center = {
      lng: '87.61552721758208',
      lat: '43.839018284106565'
    }
  }
  state.mapLocationVisible = true
}
@@ -78,6 +112,16 @@
const initMap=()=>{
}
const myGeo = ref(null)
const getAdress = () => {
  myGeo.value = new BMap.Geocoder();
  const pt = new BMap.Point(state.longitude, state.latitude);
  myGeo.value.getLocation(pt,function(result){
      state.BAddress = result.address; //获取到当前定位的详细地址信息
    },
      { enableHighAccuracy: true }
  );
}
defineExpose({
  openMapLocation