Blame view

wenjuan/src/components/MapContainer/index.vue 5.14 KB
e5b57447   杨鑫   '分包问卷'
1
  <template>
d64cd58f   wesley88   上传验收小程序
2
    <div ref="map" style="width: 100%;height: 100%;margin: 0 auto;" />
e5b57447   杨鑫   '分包问卷'
3
4
5
6
  </template>
  
  <script>
  export default {
e5b57447   杨鑫   '分包问卷'
7
8
9
    props: {
      // 回显数据传值
      list: {
d64cd58f   wesley88   上传验收小程序
10
        type: Array,
e5b57447   杨鑫   '分包问卷'
11
12
        default: [],
      },
d64cd58f   wesley88   上传验收小程序
13
14
      stutype: {
  	  type: Number,
e5b57447   杨鑫   '分包问卷'
15
  	  default: 1,
d64cd58f   wesley88   上传验收小程序
16
17
18
19
20
21
22
23
24
25
26
27
28
      }
    },
    data () {
      return {
        map: null,
        box: [
          {
            longitude: '',
            latitude: '',
            buildName: ''
          }
        ]
      };
e5b57447   杨鑫   '分包问卷'
29
30
    },
  
d64cd58f   wesley88   上传验收小程序
31
    mounted () {
e5b57447   杨鑫   '分包问卷'
32
33
34
      // console.log('list',this.list)
      this.getPosition1();
    },
d64cd58f   wesley88   上传验收小程序
35
36
37
    beforeDestroy () {
      this.destroyMap();
    },
e5b57447   杨鑫   '分包问卷'
38
    methods: {
d64cd58f   wesley88   上传验收小程序
39
      setlist (e) {
e5b57447   杨鑫   '分包问卷'
40
41
42
        this.list = e
        this.getPosition(e);
      },
d64cd58f   wesley88   上传验收小程序
43
      getPosition1 () { // 地图初始化
e5b57447   杨鑫   '分包问卷'
44
  	  console.log('地图初始化')
d64cd58f   wesley88   上传验收小程序
45
  	  const T = window.T;// 全局引入后T被注册到window里,在从这儿拿到T。T包含了天地图提供的各种方法等。
e5b57447   杨鑫   '分包问卷'
46
  	  this.map = new T.Map(this.$refs.map);
d64cd58f   wesley88   上传验收小程序
47
48
49
50
  	  console.log('this.map', this.map)
  	  this.map.centerAndZoom(new T.LngLat(104.134082, 29.99563), 14);// 三个参数分别为经度,纬度,缩放等级。
      },
      getPosition (e) { // 地图初始化
e5b57447   杨鑫   '分包问卷'
51
52
        console.log(e)
        console.log('地图初始化1111')
d64cd58f   wesley88   上传验收小程序
53
54
55
        const longitude = e.length > 0 ? e[0].longitude : 104.134082
        const latitude = e.length > 0 ? e[0].latitude : 29.99563
        const T = window.T;// 全局引入后T被注册到window里,在从这儿拿到T。T包含了天地图提供的各种方法等。
e5b57447   杨鑫   '分包问卷'
56
        this.map = new T.Map(this.$refs.map);
d64cd58f   wesley88   上传验收小程序
57
58
59
60
        console.log('this.map', this.map)
        this.map.centerAndZoom(new T.LngLat(longitude, latitude), 14);// 三个参数分别为经度,纬度,缩放等级。
        if (this.stutype == 1) {
          var ctrl = new T.Control.MapType([
e5b57447   杨鑫   '分包问卷'
61
  		  {
d64cd58f   wesley88   上传验收小程序
62
63
64
  		    title: '地图', // 地图控件上所要显示的图层名称
  		    icon: 'http://api.tianditu.gov.cn/v4.0/image/map/maptype/vector.png', // 地图控件上所要显示的图层图标(默认图标大小80x80)
  		    layer: TMAP_NORMAL_MAP, // 地图类型对象,即MapType。
e5b57447   杨鑫   '分包问卷'
65
66
  		  },
  		  {
d64cd58f   wesley88   上传验收小程序
67
68
  		    title: '卫星',
  		    icon: 'http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellite.png',
e5b57447   杨鑫   '分包问卷'
69
70
71
  		    layer: TMAP_SATELLITE_MAP,
  		  },
  		  {
d64cd58f   wesley88   上传验收小程序
72
73
  		    title: '卫星混合',
  		    http: 'http://api.tianditu.gov.cn/v4.0/image/map/maptype/satellitepoi.png',
e5b57447   杨鑫   '分包问卷'
74
75
76
  		    layer: TMAP_HYBRID_MAP,
  		  },
  		  {
d64cd58f   wesley88   上传验收小程序
77
78
  		    title: '地形',
  		    icon: ' http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrain.png',
e5b57447   杨鑫   '分包问卷'
79
80
81
  		    layer: TMAP_TERRAIN_MAP,
  		  },
  		  {
d64cd58f   wesley88   上传验收小程序
82
83
  		    title: '地形混合',
  		    icon: ' http://api.tianditu.gov.cn/v4.0/image/map/maptype/terrainpoi.png',
e5b57447   杨鑫   '分包问卷'
84
85
  		    layer: TMAP_TERRAIN_HYBRID_MAP,
  		  },
d64cd58f   wesley88   上传验收小程序
86
87
          ]);
          this.map.addControl(ctrl);
e5b57447   杨鑫   '分包问卷'
88
89
  	  }
  
d64cd58f   wesley88   上传验收小程序
90
91
92
93
94
95
        //   var lineconfig={
        // 		color: "red",            //线的颜色
        // 		weight: 2,               //线的宽度
        // 		opacity: 1,             //线的透明度
        // 		lineStyle:"solid"        //线的样式
        // 	};
e5b57447   杨鑫   '分包问卷'
96
  
d64cd58f   wesley88   上传验收小程序
97
98
99
100
        //     var points = new Array();
        //    points[0]=new T.LngLat(104.1002, 30.01831);
        //     points[1]=new T.LngLat(104.2002, 30.019);
        //     points[2]=new T.LngLat(104.3002, 30.02);
e5b57447   杨鑫   '分包问卷'
101
  
d64cd58f   wesley88   上传验收小程序
102
103
        //     var line = new T.Polyline(points,lineconfig);//创建线条的对象
        //  this.map.addOverLay(line);
e5b57447   杨鑫   '分包问卷'
104
105
  
        for (let index = 0; index < e.length; index++) {
d64cd58f   wesley88   上传验收小程序
106
          const box1 = e[index]
e5b57447   杨鑫   '分包问卷'
107
108
          var position = new T.LngLat(box1.longitude, box1.latitude)
          var icon = new T.Icon({
d64cd58f   wesley88   上传验收小程序
109
110
111
            iconUrl: 'https://api1.hmed1991.com/image/ly/dw.png', // 请求图标图片的URL
            iconSize: new T.Point(30, 30), // 图标可视区域的大小。
            iconAnchor: new T.Point(30, 30) // 图标的定位锚点
e5b57447   杨鑫   '分包问卷'
112
113
          });
          var label = new T.Label({
d64cd58f   wesley88   上传验收小程序
114
115
116
            text: box1.buildName, // 文本标注的内容
            position: position, // 文本标注的地理位置
            offset: new T.Point(-50, 20), // 文本标注的位置偏移值
e5b57447   杨鑫   '分包问卷'
117
            // backgroundColor:'#000',
d64cd58f   wesley88   上传验收小程序
118
            opacity: 0.7
e5b57447   杨鑫   '分包问卷'
119
120
121
122
123
124
125
126
127
          })
          label.setBackgroundColor('#000')
          label.setFontColor('#fff')
          // label.setOpacity(0.5)
          var marker = new T.Marker(position, {
            icon: icon
          })
          this.map.addOverLay(label);
          this.map.addOverLay(marker);
d64cd58f   wesley88   上传验收小程序
128
129
          const num = index
          label.addEventListener('click', (e) => {
e5b57447   杨鑫   '分包问卷'
130
            console.log(e)
d64cd58f   wesley88   上传验收小程序
131
            this.$emit('changeicon', num);
e5b57447   杨鑫   '分包问卷'
132
          })
e5b57447   杨鑫   '分包问卷'
133
        }
e5b57447   杨鑫   '分包问卷'
134
      },
d64cd58f   wesley88   上传验收小程序
135
136
137
138
      destroyMap () {
        if (this.map) {
          this.map.destroy();
          this.map = null;
e5b57447   杨鑫   '分包问卷'
139
        }
e5b57447   杨鑫   '分包问卷'
140
      }
d64cd58f   wesley88   上传验收小程序
141
    }
e5b57447   杨鑫   '分包问卷'
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
  };
  </script>
  
  <style lang="scss">
  .topmenu-container.el-menu--horizontal > .el-menu-item {
    float: left;
    height: 50px !important;
    line-height: 50px !important;
    color: #999093 !important;
    padding: 0 5px !important;
    margin: 0 10px !important;
  }
  
  .topmenu-container.el-menu--horizontal > .el-menu-item.is-active, .el-menu--horizontal > .el-submenu.is-active .el-submenu__title {
    border-bottom: 2px solid #{'var(--theme)'} !important;
    color: #303133;
  }
  
  /* submenu item */
  .topmenu-container.el-menu--horizontal > .el-submenu .el-submenu__title {
    float: left;
    height: 50px !important;
    line-height: 50px !important;
    color: #999093 !important;
    padding: 0 5px !important;
    margin: 0 10px !important;
  }
  </style>