@@ -24,16 +24,29 @@ $("#address-input").typeahead(
24
24
process_cb (ret)
25
25
)
26
26
)
27
- find_nearby_addresses = (coords ) ->
28
- url = API_PREFIX + " v1/address/?format=json&lat=#{ coords[0 ] } &lon=#{ coords[1 ] } "
27
+
28
+ nearby_markers = []
29
+
30
+ find_nearby_addresses = (target_coords ) ->
31
+ url = API_PREFIX + " v1/address/?format=json&lat=#{ target_coords[0 ]} &lon=#{ target_coords[1 ]} "
29
32
$ .getJSON (url, (data ) ->
30
33
objs = data .objects
31
34
el = $ (" #nearby-addr-list" )
32
35
el .empty ()
36
+ for m in nearby_markers
37
+ map .removeLayer m
38
+ nearby_markers = []
39
+ index = 1
33
40
for addr in objs
34
41
name = addr .name
35
42
distance = Math .round (addr .distance )
36
- el .append ($ (" <li>#{ addr .name } #{ distance } m</li>" ))
43
+ coords = addr .location .coordinates
44
+ m = new L.Marker [coords[1 ], coords[0 ]],
45
+ icon : new L.NumberedDivIcon {number : index .toString ()}
46
+ m .addTo map
47
+ nearby_markers .push m
48
+ el .append ($ (" <li>#{ addr .name } #{ distance} m</li>" ))
49
+ index++
37
50
)
38
51
$ (" #address-input" ).on ' change' , ->
39
52
match_obj = null
@@ -87,13 +100,6 @@ $("#district-input").on 'change', ->
87
100
map .fitBounds borders .getBounds ()
88
101
89
102
show_plans = false
90
- $ (" #show-plans" ).on ' click' , ->
91
- show_plans = true
92
- if map .getZoom () < 13
93
- map .setZoom 13
94
- # refresh_plans() will be called automatically through the 'moveend' event.
95
- else
96
- refresh_plans ()
97
103
98
104
map .on ' moveend' , (ev ) ->
99
105
if not show_plans
@@ -117,8 +123,6 @@ hover_style =
117
123
color : " orange"
118
124
119
125
plan_click = (ev ) ->
120
- console .log ev
121
- console .log this
122
126
123
127
plan_hover_start = (ev ) ->
124
128
@ .setStyle hover_style
@@ -145,6 +149,7 @@ draw_plans = (new_plans) ->
145
149
geom .on ' mouseover' , plan_hover_start
146
150
geom .on ' mouseout' , plan_hover_end
147
151
geom .addTo map
152
+ obj .geom = geom
148
153
149
154
plan_refresher = null
150
155
refresh_plans = ->
@@ -174,8 +179,24 @@ class PlanRefresher
174
179
return
175
180
draw_plans data .objects
176
181
next = data .meta .next
177
- console .log data .meta
178
182
if next
179
183
@current_xfer = $ .getJSON next, receive_plans
180
184
181
185
@current_xfer = $ .getJSON url, params, receive_plans
186
+
187
+ $ (" #show-plans" ).on ' click' , ->
188
+ if show_plans
189
+ for plan_id of plans
190
+ plan = plans[plan_id]
191
+ map .removeLayer plan .geom
192
+ plans = {}
193
+ show_plans = false
194
+ $ (" #show-plans" ).html ' Show plans'
195
+ return
196
+ show_plans = true
197
+ if map .getZoom () < 13
198
+ map .setZoom 13
199
+ # refresh_plans() will be called automatically through the 'moveend' event.
200
+ else
201
+ refresh_plans ()
202
+ $ (" #show-plans" ).html ' Hide plans'
0 commit comments