checkDeviceLoaction.vue 3.88 KB
Newer Older
1 2 3 4
<template>
  <el-dialog
    title="拾取坐标"
    :visible.sync="dialogTableVisible"
5
    :before-close="handleClose"
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
  >

    <el-row class="lt">
      经纬度:
      <el-input
        placeholder="经度"
        v-model.number="lnglat.lng"
        type="number"
      ></el-input>
      <el-input
        placeholder="纬度"
        v-model.number="lnglat.lat"
        type="number"
      ></el-input>
      <el-button type="primary" size="small" @click="confirmFun">确定</el-button
      >
      <el-button size="small" @click="$emit('dialogcancelFun')">取消</el-button
      >
    </el-row>
yaqizhang's avatar
yaqizhang committed
25
    <div style="width: 47vw; height: 65vh" id="container1"></div>
26 27

    <el-col :span="8" class="button">
28
      <el-input id="ss" placeholder="输入地址" v-model="keyWorld" size="small" ></el-input>
29 30 31 32 33 34
      <el-button size="small" type="primary" icon="el-icon-search" @click="search" style="position: fixed;margin-left: 3px;">搜索</el-button>
    </el-col>

  </el-dialog>
</template>
<script>
35
  import gaodeMap from "./js/gaodeMapDialog.js";
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  export default {
    props: {
      dialogTableVisible: false,
      slat: 0,
      slng: 0
    },
    data(){
      return{
        lnglat: {
          lat: "",
          lng: ""
        },
        keyWorld: ""
      }
    },
    watch:{
      dialogTableVisible:{
        handler(value) {
          if(value){
            let that = this;
            that.$nextTick(() => {
              //初始化地图
58
              /*let map = new AMap.Map("container1", {
59 60 61 62 63 64 65
                center: [114.72995, 38.37417],
                // resizeEnable: true,
                disableSocket: true,
                viewMode: "3D",
                showLabel: true,
                pitch: 8,
                zoom: 12
66 67
              });*/
              let gaode = new gaodeMap(process.env.VUE_APP_MAP_CENTER);
68 69 70 71 72 73 74 75
              var overlays = [];
              //坐标回显
              if (typeof that.slng == "number" && that.slng != 0) {
                that.lnglat.lng = that.slng;
                that.lnglat.lat = that.slat;
                let marker = new AMap.Marker({
                  position: [that.slng,that.slat]
                });
76 77
                marker.setMap(gaode.myMap);
                gaode.myMap.setCenter([that.slng,that.slat]);
78 79 80 81
                overlays.push(marker);
              }

              //点击获取坐标点
82
              var mouseTool = new AMap.MouseTool(gaode.myMap);
83 84
              //监听draw事件可获取画好的覆盖物
              mouseTool.on('draw',function(e){
85
                gaode.myMap.remove(overlays);
86 87 88 89 90 91 92 93 94
                overlays.push(e.obj);
                that.lnglat.lat = e.obj._position.lat;
                that.lnglat.lng = e.obj._position.lng;
              })
              that.draw(mouseTool);

              //搜索功能
              AMap.plugin(["AMap.AutoComplete","AMap.PlaceSearch"], function() {
                that.placeSearch = new AMap.PlaceSearch({
95
                  map: gaode.myMap
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                });
              });
            })
          }
        },
        // 代表在wacth里声明了firstName这个方法之后立即先去执行handler方法
        immediate: true

      }
    },
    methods:{
      confirmFun(){
        this.$emit('confirmFun',this.lnglat);
        this.$emit('dialogcancelFun');
      },
      draw(mouseTool){
        mouseTool.marker({
          //同Marker的Option设置
        });
      },
116 117 118
      handleClose(){
        this.$emit('dialogcancelFun');
      },
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
      search(){
        this.placeSearch.search(this.keyWorld);  //关键字查询查询
      }
    }
  }

</script>

<style scoped lang="scss">
  .lt{
    margin-bottom: 10px;
  }
  .lt .el-input {
    width: 180px;
    margin-right: 15px;
    display: inline-block;
  }

  .button{
138 139 140
    position: absolute;
    top: 140px;
    left: 35px;
141 142 143 144 145 146 147 148
  }

  .button .el-input{
    width: 180px;
    margin-right: 10px;
    display: inline-block;
  }
</style>