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