Module: Cloudkicker::MapEvents

Included in:
Map
Defined in:
lib/critical_juncture/map/map_events.rb

Instance Method Summary collapse

Instance Method Details

#add_events(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/critical_juncture/map/map_events.rb', line 4

def add_events(options={})
  ajax_markers       = options.delete(:ajax_markers)
  enable_bookmarking = options.delete(:enable_bookmarking)
  
  js = []
  js << <<-JS
        /*************************/
        /* add events to the map */
        /*************************/
  JS
  
  if ajax_markers
    js << ajax_markers_event
  end
  
  js << map_drag_event(enable_bookmarking)
  
  return js.join('\n')
end

#ajax_markers_eventObject

Fires on map load and uses the ajax markers module to get markers from server



26
27
28
29
30
31
32
33
34
35
# File 'lib/critical_juncture/map/map_events.rb', line 26

def ajax_markers_event
  js = <<-JS
    // get the markers for the area shown in the map (the bounds) on load
    CM.Event.addListener(map, 'load', function() {
      getMapPoints(map.getBounds());
    });
  JS
  
  return js
end

#map_drag_event(enable_bookmarking) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/critical_juncture/map/map_events.rb', line 37

def map_drag_event(enable_bookmarking)
  js = []
  
  js << <<-JS
        // we get markers dynamically from the server 
        // first turn on the loading indicator
        $('.mapMarkerLoader img').show();
  
        // show the map marker loading indicator and get the markers for the area shown in 
        // the map (the bounds)
        CM.Event.addListener(map, 'dragend', function() {
          $('.mapMarkerLoader img').show();
          getMapPoints(map.getBounds());
  JS
  
  # if we're bookmarking then add the location to the url
  if enable_bookmarking
    js << <<-JS
            //and add the new map location to the url so it's bookmarkable
            add_location_to_anchor(map);
    JS
  end
  
  # close our dragend map listener regarless
  js << <<-JS
          });
  JS
  
  return js.join('\n')
end