1
+ class Dashing.Map extends Dashing.Widget
2
+
3
+ ready : ->
4
+ $ (@node ).removeClass (' widget' )
5
+ color = $ (@node ).data (" color" )
6
+
7
+ if color
8
+ style = [
9
+ {
10
+ " featureType" : " water" ,
11
+ " stylers" : [
12
+ { " color" : color }
13
+ ]
14
+ },{
15
+ " featureType" : " road" ,
16
+ " stylers" : [
17
+ { " color" : color },
18
+ { " weight" : 0.5 }
19
+ ]
20
+ },{
21
+ " featureType" : " poi.government" ,
22
+ " stylers" : [
23
+ { " lightness" : 95 },
24
+ { " visibility" : " off" }
25
+ ]
26
+ },{
27
+ " featureType" : " transit" ,
28
+ " stylers" : [
29
+ { " color" : " #ffffff" }
30
+ ]
31
+ },{
32
+ " featureType" : " transit" ,
33
+ " elementType" : " geometry" ,
34
+ " stylers" : [
35
+ { " weight" : 0.5 }
36
+ ]
37
+ },{
38
+ " featureType" : " transit" ,
39
+ " elementType" : " labels" ,
40
+ " stylers" : [
41
+ { " visibility" : " off" }
42
+ ]
43
+ },{
44
+ " featureType" : " road" ,
45
+ " elementType" : " labels" ,
46
+ " stylers" : [
47
+ { " visibility" : " off" }
48
+ ]
49
+ },{
50
+ " featureType" : " poi" ,
51
+ " elementType" : " labels" ,
52
+ " stylers" : [
53
+ { " visibility" : " off" }
54
+ ]
55
+ },{
56
+ " featureType" : " administrative.land_parcel" },{
57
+ " featureType" : " poi.park" ,
58
+ " stylers" : [
59
+ { " lightness" : 90 },
60
+ { " color" : " #ffffff" }
61
+ ]
62
+ },{
63
+ " featureType" : " landscape" ,
64
+ " stylers" : [
65
+ { " color" : " #ffffff" },
66
+ { " visibility" : " on" }
67
+ ]
68
+ },{
69
+ " featureType" : " poi.park" ,
70
+ " stylers" : [
71
+ { " color" : " #ffffff" }
72
+ ]
73
+ },{
74
+ " featureType" : " landscape.man_made" ,
75
+ " stylers" : [
76
+ { " color" : color },
77
+ { " lightness" : 95 }
78
+ ]
79
+ },{
80
+ " featureType" : " poi" ,
81
+ " stylers" : [
82
+ { " visibility" : " on" },
83
+ { " color" : " #ffffff" }
84
+ ]
85
+ },{
86
+ " featureType" : " poi" ,
87
+ " elementType" : " labels" ,
88
+ " stylers" : [
89
+ { " visibility" : " off" }
90
+ ]
91
+ },{
92
+ " featureType" : " landscape" ,
93
+ " elementType" : " labels" ,
94
+ " stylers" : [
95
+ { " visibility" : " off" }
96
+ ]
97
+ },{
98
+ " featureType" : " administrative.province" ,
99
+ " elementType" : " labels" ,
100
+ " stylers" : [
101
+ { " visibility" : " off" }
102
+ ]
103
+ },{
104
+ " elementType" : " administrative.locality" ,
105
+ " elementType" : " labels" ,
106
+ " stylers" : [
107
+ { " color" : " #000000" },
108
+ { " weight" : 0.1 }
109
+ ]
110
+ },{
111
+ " featureType" : " administrative.country" ,
112
+ " elementType" : " labels.text" ,
113
+ " stylers" : [
114
+ { " color" : " #000000" },
115
+ { " weight" : 0.1 }
116
+ ]
117
+ },{
118
+ " featureType" : " administrative.country" ,
119
+ " elementType" : " geometry" ,
120
+ " stylers" : [
121
+ { " color" : color },
122
+ { " weight" : 1.0 }
123
+ ]
124
+ },{
125
+ " featureType" : " administrative.province" ,
126
+ " elementType" : " geometry" ,
127
+ " stylers" : [
128
+ { " color" : color },
129
+ { " weight" : 0.5 }
130
+ ]
131
+ },{
132
+ " featureType" : " water" ,
133
+ " elementType" : " labels" ,
134
+ " stylers" : [
135
+ { " visibility" : " off" }
136
+ ]
137
+ }
138
+ ]
139
+ else
140
+ []
141
+
142
+ options =
143
+ zoom : 2
144
+ center : new google.maps.LatLng (30 , - 98 )
145
+ disableDefaultUI : true
146
+ draggable : false
147
+ scrollwheel : false
148
+ disableDoubleClickZoom : true
149
+ styles : style
150
+
151
+ mapTypeId : google .maps .MapTypeId .ROADMAP
152
+ @map = new google.maps.Map $ (@node )[0 ], options
153
+ @heat = []
154
+ @markers = []
155
+
156
+ onData : (data ) ->
157
+ return unless @map
158
+ if $ (@node ).data (" type" ) == ' heat'
159
+ marker .set (' map' , null ) for marker in @heat
160
+ @markers = []
161
+
162
+ @markers .push new google.maps.LatLng (marker[0 ],marker[1 ]) for marker in data .markers
163
+
164
+ pointArray = new google.maps.MVCArray @markers
165
+ @heat .push new google.maps.visualization.HeatmapLayer
166
+ data : pointArray
167
+ map : @map
168
+
169
+ else
170
+ marker .set (' map' , null ) for marker in @markers
171
+ @markers = []
172
+ for marker in data .markers
173
+ marker_object = new google.maps.Marker
174
+ position : new google.maps.LatLng (marker[0 ],marker[1 ])
175
+ map : @map
176
+ @markers .push marker_object
177
+
178
+ if @markers .length == 1
179
+ @map .set (' zoom' , 9 )
180
+ @map .set (' center' , @markers [0 ].position )
181
+ else
182
+ bounds = new google.maps.LatLngBounds
183
+ bounds .extend (marker .position || marker) for marker in @markers
184
+ @map .panToBounds (bounds)
185
+ @map .fitBounds (bounds)
0 commit comments