1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, google, |
7
|
|
|
Coordinates, Lang, Markers |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
var ContextMenu = {}; |
11
|
|
|
ContextMenu.m_map = null; |
12
|
|
|
ContextMenu.m_div = null; |
13
|
|
|
ContextMenu.m_marker = null; |
14
|
|
|
ContextMenu.m_latlng = null; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
ContextMenu.init = function (map, div) { |
18
|
|
|
'use strict'; |
19
|
|
|
|
20
|
|
|
var self = this; |
21
|
|
|
|
22
|
|
|
this.m_map = map; |
23
|
|
|
this.m_div = div; |
24
|
|
|
|
25
|
|
|
$('#contextmenu-addmarker').click(function () { |
26
|
|
|
self.m_div.hide(); |
27
|
|
|
Markers.newMarker(self.m_latlng, -1, -1, null); |
28
|
|
|
return false; |
29
|
|
|
}); |
30
|
|
|
$('#contextmenu-deletemarker').click(function () { |
31
|
|
|
self.m_div.hide(); |
32
|
|
|
Markers.removeById(self.m_marker); |
33
|
|
|
return false; |
34
|
|
|
}); |
35
|
|
|
$('#contextmenu-centermap').click(function () { |
36
|
|
|
self.m_div.hide(); |
37
|
|
|
self.m_map.setCenter(self.m_latlng); |
38
|
|
|
return false; |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
google.maps.event.addListener(this.m_map, 'rightclick', function (event) { |
42
|
|
|
ContextMenu.showMapMenu(event); |
43
|
|
|
return false; |
44
|
|
|
}); |
45
|
|
|
}; |
46
|
|
|
|
47
|
|
|
ContextMenu.show = function (x, y) { |
48
|
|
|
'use strict'; |
49
|
|
|
|
50
|
|
|
var mapDiv = $(ContextMenu.m_map.getDiv()), |
51
|
|
|
menu = ContextMenu.m_div, |
52
|
|
|
y_offset = $('#map-wrapper').position().top; |
53
|
|
|
|
54
|
|
|
// Hide the context menu if its open |
55
|
|
|
menu.hide(); |
56
|
|
|
|
57
|
|
|
// Adjust the menu if clicked to close to the edge of the map |
58
|
|
|
if (x > mapDiv.width() - menu.width()) { |
59
|
|
|
x -= menu.width(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (y > mapDiv.height() - menu.height()) { |
63
|
|
|
y -= menu.height(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Set the location and fade in the context menu |
67
|
|
|
menu.css({top: y + y_offset, left: x}).fadeIn(200); |
68
|
|
|
|
69
|
|
|
// Hide context menu on several events |
70
|
|
|
/*jslint unparam: true*/ |
71
|
|
|
$.each(['click', 'dragstart', 'zoom_changed', 'maptypeid_changed', 'center_changed'], function (unused, name) { |
72
|
|
|
google.maps.event.addListener(ContextMenu.m_map, name, function () { |
73
|
|
|
menu.hide(); |
74
|
|
|
}); |
75
|
|
|
}); |
76
|
|
|
/*jslint unparam: false*/ |
77
|
|
|
}; |
78
|
|
|
|
79
|
|
|
ContextMenu.showMarkerMenu = function (event, marker) { |
80
|
|
|
'use strict'; |
81
|
|
|
|
82
|
|
|
$('#contextmenu-addmarker').hide(); |
83
|
|
|
$('#contextmenu-deletemarker').show(); |
84
|
|
|
$('#contextmenu-centermap').show(); |
85
|
|
|
|
86
|
|
|
ContextMenu.m_marker = marker.getId(); |
87
|
|
|
ContextMenu.m_latlng = marker.getPosition(); |
88
|
|
|
ContextMenu.show(event.pixel.x + $('#themap').width() / 2, event.pixel.y + $('#themap').height() / 2); |
89
|
|
|
}; |
90
|
|
|
|
91
|
|
|
ContextMenu.showMapMenu = function (event) { |
92
|
|
|
'use strict'; |
93
|
|
|
|
94
|
|
|
$('#contextmenu-addmarker').show(); |
95
|
|
|
$('#contextmenu-deletemarker').hide(); |
96
|
|
|
$('#contextmenu-centermap').show(); |
97
|
|
|
|
98
|
|
|
ContextMenu.m_marker = null; |
99
|
|
|
ContextMenu.m_latlng = event.latLng; |
100
|
|
|
ContextMenu.show(event.pixel.x, event.pixel.y); |
101
|
|
|
}; |
102
|
|
|
|