Module: Cloudkicker::AjaxMarkers

Included in:
Map
Defined in:
lib/critical_juncture/markers/ajax_markers.rb

Instance Method Summary collapse

Instance Method Details

#add_ajax_marker_functions(url) ⇒ Object



4
5
6
7
8
9
# File 'lib/critical_juncture/markers/ajax_markers.rb', line 4

def add_ajax_marker_functions(url)
  js = []
  js << add_marker_function
  js << get_map_points_function(url)
  return js
end

#add_marker_functionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/critical_juncture/markers/ajax_markers.rb', line 11

def add_marker_function
  <<-JS
  function add_markers(markers) {
    $.each(addedMarkers, function(i, added_marker){
      map.removeOverlay(added_marker);
    });
    addedMarkers = [];
  
    $.each(markers, function(i, marker){
      var myMarkerLatLng = new CM.LatLng(marker.lat,marker.lng);

      var icon = new CM.Icon();
      if(marker.tower) {
        icon.image  = "/images/dot_med.png";
      }
      else
      {
        icon.image  = "/images/dot_med_blue.png";
      }
    
      icon.iconSize = new CM.Size(21, 21);
      //icon.shadow  = "/images/map_marker_shadow.png";
      //icon.shadowSize = new CM.Size(31, 48);
      //icon.iconAnchor = new CM.Point(20, 48);

      var myMarker = new CM.Marker(myMarkerLatLng, {
        title: marker.licensee,
        icon: icon
      });
    
      CM.Event.addListener(myMarker, 'click', function(latlng){
        if(marker.tower) {
          map.openInfoWindow(myMarkerLatLng, parseTemplate($("#cell_tower_template").html(), marker), {maxWidth: 400, pixelOffset: new CM.Size(0,-10)});
        }
        else
        {
          map.openInfoWindow(myMarkerLatLng, parseTemplate($("#cell_site_template").html(), marker), {maxWidth: 400, pixelOffset: new CM.Size(0,-10)});
        }
      });
    
    
      addedMarkers.push(myMarker);
      map.addOverlay(myMarker);
    });
  
    $('.mapMarkerLoader img').hide();
  }
  JS
end

#get_map_points_function(url) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/critical_juncture/markers/ajax_markers.rb', line 61

def get_map_points_function(url)
  <<-JS
  function getMapPoints(CMBounds) {
    var sw_CMLatLng = CMBounds.getSouthWest();
    var sw_point    = [sw_CMLatLng.lat(), sw_CMLatLng.lng()]
    var ne_CMLatLng = CMBounds.getNorthEast();
    var ne_point    = [ne_CMLatLng.lat(), ne_CMLatLng.lng()]  

    $.ajax({
      type:"GET",
      url:'#{url}',
      data:"per_page=200&fields=limited&search[conditions][descend_by_created_at]=1&search[conditions][within_bounds][sw_point][]=" + sw_point[0] + "&search[conditions][within_bounds][sw_point][]=" + sw_point[1] + "&search[conditions][within_bounds][ne_point][]=" + ne_point[0] + "&search[conditions][within_bounds][ne_point][]=" + ne_point[1],
      dataType:'json',
      success: add_markers
    });
  }

  JS
end