map.vue
8.46 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<template>
<div id="app">
<div style="width:100%;height: calc(100vh - 50px);display: flex;flex-direction: column;">
<div id="container"></div>
<div id="toolControl">
<div class="toolItem active" id="marker" title="默认"></div>
<div class="toolItem" id="polyline" title="����" style="display: none;"></div>
<div class="toolItem" id="polygon" title="选择区域"></div>
<div class="toolItem" id="circle" title="Բ��" style="display: none;"></div>
<div class="toolItem" id="rectangle" title="����" style="display: none;"></div>
<div class="toolItem" id="ellipse" title="��Բ" style="display: none;"></div>
</div>
<div style="width: 300px;background: #EEEEEE;position: absolute;z-index: 99999;top: 10px;left:10px">
<ul class="AreaList" v-for="(item,i) in datalist">
<li><label class="el-icon-position"></label>{{item.RegionName}}<label
class="el-icon-delete delClass" @click="ReservationAreaDeleteHeadler(item.id,i)"></label>
</li>
</ul>
</div>
</div>
<el-dialog title="请为该区域命名" :visible.sync="dialogAreaVisible" width="400px" :close-on-click-modal="false">
<el-input v-model="ReservationAreaInfo.RegionName" placeholder="请输入区域名称"></el-input>
<el-button @click="AddReservationAreaInfo()" style="float: right;margin-top: 10px;">确定</el-button>
<div style="clear: both;"></div>
</el-dialog>
</div>
</template>
<script>
import {
AddReservationArea,
ReservationAreaList,
ReservationAreaDelete
} from '@/api/ReservationArea'
export default {
data() {
return {
activeType: "marker",
dialogAreaVisible: false,
datalist: [{
RegionName: "",
Region: "",
State: 1
}],
ReservationAreaInfo: {
RegionName: "",
Region: "",
State: 1
},
parameter: {
pageIndex: 1,
pageSize: 30,
sort: "id",
sortOrder: 1,
keyword: "",
status: 1
},
map: '',
polygon: null
}
},
created() {},
mounted() {
this.initMap();
},
methods: {
ReservationAreaDeleteHeadler(id, index) {
this.$confirm('确定移除该区域?', '消息', {
confirmButtonText: '确认',
cancelButtonText: '取消',
callback: (action) => {
if (action == "confirm") {
var MapId = "P" + id;
ReservationAreaDelete(id).then(res => {
if (res.data.code == 200) {
this.datalist.splice(index, 1);
this.polygon.remove([MapId]);
}
});
}
},
})
},
ReservationAreaList(map, center) {
//多边形轮廓点串(LatLng数组)
let geometriesInfo = [];
let that = this;
ReservationAreaList(this.parameter).then(res => {
var center = new window.TMap.LatLng(30.65787, 104.06584)
this.datalist = res.data.data;
this.datalist.forEach(function(item, i) {
var path = [];
var RegionList = JSON.parse(item.Region);
RegionList.forEach(function(Ritem) {
path.push(new window.TMap.LatLng(Ritem.lat, Ritem.lng))
})
geometriesInfo.push({
'id': 'P' + item.id, //该多边形在图层中的唯一标识(删除、更新数据时需要)
'styleId': 'polygon', //绑定样式名
'paths': path, //多边形轮廓
});
});
console.log('geometriesInfo', geometriesInfo);
let polygon = new window.TMap.MultiPolygon({
id: 'polygon-layer', //图层id
map: map, //设置多边形图层显示到哪个地图实例中
//多边形样式
styles: {
'polygon': new TMap.PolygonStyle({
'color': 'rgba(0,125,255,0.3)', //面填充色
'showBorder': false, //是否显示拔起面的边线
'borderColor': '#00FFFF' //边线颜色
})
},
//多边形数据
geometries: geometriesInfo
});
console.log('polygon', polygon);
that.polygon = polygon;
console.log('wanggeshabi', this.polygon);
});
},
AddReservationAreaInfo() {
if (this.ReservationAreaInfo.RegionName == "") {
this.$message('区域名称不能为空');
} else {
AddReservationArea(this.ReservationAreaInfo).then(res => {
if (res.data.code == 200) {
this.$confirm('添加区域成功', '消息', {
confirmButtonText: '确认',
cancelButtonText: '取消',
callback: (action) => {
this.initMap();
this.dialogAreaVisible = false;
},
})
}
});
}
},
initMap() {
let _this = this;
document.getElementById('toolControl').addEventListener('click', (e) => {
var id = e.target.id;
if (id !== 'toolControl') {
document.getElementById(this.activeType).className = 'toolItem';
document.getElementById(id).className = 'toolItem active';
this.activeType = id;
editor.setActiveOverlay(id);
}
});
var center = new window.TMap.LatLng(30.65787, 104.06584)
// 定义map变量,调用 TMap.Map() 构造函数创建地图
var map = new window.TMap.Map(document.getElementById("container"), {
center: center, // 设置地图中心点坐标
zoom: 13 // 设置地图缩放级别
});
this.map = map;
this.ReservationAreaList(map, center);
var editor = new window.TMap.tools.GeometryEditor({
// TMap.tools.GeometryEditor �ĵ���ַ��https://lbs.qq.com/webApi/javascriptGL/glDoc/glDocEditor
map: map, // �༭���ĵ�ͼ����
overlayList: [
// �ɱ༭ͼ�� �ĵ���ַ��https://lbs.qq.com/webApi/javascriptGL/glDoc/glDocEditor#4
{
overlay: new window.TMap.MultiMarker({
map: map,
}),
id: 'marker',
},
{
overlay: new window.TMap.MultiPolyline({
map: map,
}),
id: 'polyline',
},
{
overlay: new window.TMap.MultiPolygon({
map: map,
}),
id: 'polygon',
},
{
overlay: new window.TMap.MultiCircle({
map: map,
}),
id: 'circle',
},
{
overlay: new window.TMap.MultiRectangle({
map: map,
}),
id: 'rectangle',
},
{
overlay: new window.TMap.MultiEllipse({
map: map,
}),
id: 'ellipse',
},
],
actionMode: window.TMap.tools.constants.EDITOR_ACTION.DRAW, //
activeOverlayId: 'marker', //
snappable: true, //
});
editor.on('draw_complete', (geometry) => {
console.log(geometry);
if (geometry.paths != undefined) {
_this.ReservationAreaInfo.Region = JSON.stringify(geometry.paths);
_this.dialogAreaVisible = true;
}
// console.log(geometry[0])
});
}
}
}
</script>
<style>
#container {
width: 100%;
display: flex;
flex: 1;
}
#marker {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker_editor.png');
}
#polyline {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/polyline.png');
}
#polygon {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/polygon.png');
}
#circle {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/circle.png');
}
#rectangle {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/rectangle.png');
}
#ellipse {
background-image: url('https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/ellipse.png');
}
#toolControl {
position: absolute;
top: 10px;
left: 0px;
right: 0px;
margin: auto;
width: 110px;
z-index: 1001;
}
.toolItem {
width: 50px;
height: 50px;
float: left;
margin: 1px;
padding: 4px;
border-radius: 3px;
background-size: 40px 40px;
background-position: 4px 4px;
background-repeat: no-repeat;
box-shadow: 0 1px 2px 0 #e4e7ef;
background-color: #ffffff;
border: 1px solid #ffffff;
}
.toolItem:hover {
border-color: #789cff;
}
.active {
border-color: #d5dff2;
background-color: #d5dff2;
}
.AreaList {
list-style: none;
padding: 0px;
margin: 0px;
background: none;
}
.AreaList li {
padding: 0 10px;
line-height: 40px;
height: 40px;
font-size: 14px;
font-weight: bold;
margin-bottom: 10px;
border-radius: 5px;
background: #304156;
color: #fff;
box-shadow: 0 0 5px #cdcdcd;
}
.AreaList li label {
margin-right: 10px;
}
/* .AreaList li:hover {
background-color: #409EFF;
color: #FFF;
} */
.delClass {
float: right;
line-height: 40px;
cursor: pointer;
text-align: center;
width: 20px;
}
.delClass:hover {
color: #FFF;
font-size: 20px;
font-weight: bold;
text-shadow: 0 0 1px #FFF;
}
</style>