1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 try:
17 from cStringIO import StringIO
18 except ImportError:
19 from StringIO import StringIO
20
21 from muntjac.addon.google_maps.overlay.marker_source \
22 import IMarkerSource
23
24
26
30
31
34
35
37 if newMarker in self._markers:
38 return False
39 self._markers.append(newMarker)
40 return True
41
42
44 markerJSON = StringIO()
45
46 for i, marker in enumerate(self._markers):
47 markerJSON.write('{\"mid\":\"')
48 markerJSON.write(str(marker.getId()))
49
50 markerJSON.write('\",\"lat\":')
51 markerJSON.write(str(marker.getLatLng()[1]))
52
53 markerJSON.write(',\"lng\":')
54 markerJSON.write(str(marker.getLatLng()[0]))
55
56
57 markerJSON.write(',\"title\":\"')
58 markerJSON.write(marker.getTitle().replace('\'', "\\'").replace('\"', '\\\\\"'))
59
60 markerJSON.write('\",\"visible\":')
61 markerJSON.write('true' if marker.isVisible() else 'false')
62
63 markerJSON.write(',\"info\":')
64 markerJSON.write('true' if marker.getInfoWindowContent() is not None else 'false')
65
66 markerJSON.write(',\"draggable\":')
67 markerJSON.write('true' if marker.isDraggable() else 'false')
68
69 if marker.getIconUrl() is not None:
70 markerJSON.write(',\"icon\":\"')
71 markerJSON.write(marker.getIconUrl() + '\"')
72
73 if marker.getIconAnchor() is not None:
74 markerJSON.write(',\"iconAnchorX\":')
75 markerJSON.write(str(marker.getIconAnchor()[0]))
76
77 markerJSON.write(',\"iconAnchorY\":')
78 markerJSON.write(str(marker.getIconAnchor()[1]))
79 else:
80 markerJSON.write(',\"iconAnchorX\":')
81 markerJSON.write(str(marker.getLatLng()[0]))
82
83 markerJSON.write(',\"iconAnchorY\":')
84 markerJSON.write(str(marker.getLatLng()[1]))
85
86 markerJSON.write('}')
87
88 if i != len(self._markers) - 1:
89 markerJSON.write(',')
90
91 try:
92 json = ('[' + markerJSON.getvalue() + ']').encode('utf-8')
93 except Exception:
94 json = ('[' + markerJSON.getvalue() + ']').encode()
95
96 markerJSON.close()
97
98 return json
99
100
104
105
112