right.js
1.27 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
export default function ContextMenu(map) {
var me = this
//地图中添加鼠标工具MouseTool插件
this.mouseTool = new AMap.MouseTool(map)
this.contextMenuPositon = null
var content = []
content.push("<div class='info context_menu'>")
content.push(" <p onclick='menu.addMarkerMenu()'>新增车位标记</p>")
content.push('</div>')
//通过content自定义右键菜单内容
this.contextMenu = new AMap.ContextMenu({ isCustom: true, content: content.join('') })
//地图绑定鼠标右击事件——弹出右键菜单
map.on('rightclick', function(e) {
me.contextMenu.open(map, e.lnglat)
me.contextMenuPositon = e.lnglat //右键菜单位置
})
}
ContextMenu.prototype.zoomMenu = function zoomMenu(tag) {
//右键菜单缩放地图
if (tag === 0) {
map.zoomOut()
}
if (tag === 1) {
map.zoomIn()
}
this.contextMenu.close()
}
ContextMenu.prototype.distanceMeasureMenu = function() {
//右键菜单距离量测
this.mouseTool.rule()
this.contextMenu.close()
}
ContextMenu.prototype.addMarkerMenu = function() {
//右键菜单添加Marker标记
this.mouseTool.close()
var marker = new AMap.Marker({
map: map,
position: this.contextMenuPositon || map.getCenter() //基点位置
})
this.contextMenu.close()
}