socmap_adf 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. data/.gitignore +10 -0
  2. data/.rvmrc +81 -0
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +17 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +3 -0
  7. data/Rakefile +36 -0
  8. data/lib/assets/.gitkeep +0 -0
  9. data/lib/assets/javascripts/.DS_Store +0 -0
  10. data/lib/assets/javascripts/socmap_adf/.DS_Store +0 -0
  11. data/lib/assets/javascripts/socmap_adf/init.js.coffee.erb +9 -0
  12. data/lib/assets/javascripts/socmap_adf/lib/adf_delegate.js.coffee +13 -0
  13. data/lib/assets/javascripts/socmap_adf/lib/adf_view.js.coffee +7 -0
  14. data/lib/assets/javascripts/socmap_adf/modules/.DS_Store +0 -0
  15. data/lib/assets/javascripts/socmap_adf/modules/cluster/init.js.coffee +11 -0
  16. data/lib/assets/javascripts/socmap_adf/modules/cluster/lib/elycharts.js +3769 -0
  17. data/lib/assets/javascripts/socmap_adf/modules/cluster/lib/raphael.js +5815 -0
  18. data/lib/assets/javascripts/socmap_adf/modules/cluster/templates/chart.jst.eco +6 -0
  19. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/chart.js.coffee +107 -0
  20. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/chart_icon.js.coffee +106 -0
  21. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/cluster.js.coffee +127 -0
  22. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/default_icon.js.coffee +170 -0
  23. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/main.js.coffee +10 -0
  24. data/lib/assets/javascripts/socmap_adf/modules/cluster/views/marker_clusterer.js.coffee +358 -0
  25. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/init.js.coffee +7 -0
  26. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/templates/existing_file.jst.eco +10 -0
  27. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/templates/file.jst.eco +3 -0
  28. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/templates/main.jst.eco +7 -0
  29. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/templates/uploading.jst.eco +3 -0
  30. data/lib/assets/javascripts/socmap_adf/modules/file_uploader/views/main.js.coffee +76 -0
  31. data/lib/assets/javascripts/socmap_adf/modules/form/init.js.coffee +9 -0
  32. data/lib/assets/javascripts/socmap_adf/modules/form/models/base.js.coffee +73 -0
  33. data/lib/assets/javascripts/socmap_adf/modules/form/models/error.js.coffee +12 -0
  34. data/lib/assets/javascripts/socmap_adf/modules/form/models/field_binder.js.coffee +104 -0
  35. data/lib/assets/javascripts/socmap_adf/modules/form/models/validator.js.coffee +65 -0
  36. data/lib/assets/javascripts/socmap_adf/modules/form/templates/error_field.jst.eco +7 -0
  37. data/lib/assets/javascripts/socmap_adf/modules/form/templates/field_set.jst.eco +6 -0
  38. data/lib/assets/javascripts/socmap_adf/modules/form/templates/field_set_button.jst.eco +1 -0
  39. data/lib/assets/javascripts/socmap_adf/modules/form/templates/field_sets.jst.eco +2 -0
  40. data/lib/assets/javascripts/socmap_adf/modules/form/views/base.js.coffee +9 -0
  41. data/lib/assets/javascripts/socmap_adf/modules/form/views/field_set.js.coffee +88 -0
  42. data/lib/assets/javascripts/socmap_adf/modules/form/views/field_set_with_button.js.coffee +38 -0
  43. data/lib/assets/javascripts/socmap_adf/modules/form/views/field_sets.js.coffee +81 -0
  44. data/lib/assets/javascripts/socmap_adf/modules/gmap/.DS_Store +0 -0
  45. data/lib/assets/javascripts/socmap_adf/modules/gmap/init.js.coffee +6 -0
  46. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/.DS_Store +0 -0
  47. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/custom_marker.js.coffee +36 -0
  48. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/marker.js.coffee +72 -0
  49. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/marker_with_label.js +566 -0
  50. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/overlay.js.coffee +237 -0
  51. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/overlay_view.js.coffee +143 -0
  52. data/lib/assets/javascripts/socmap_adf/modules/gmap/views/polygon.js.coffee +107 -0
  53. data/lib/assets/javascripts/socmap_adf/modules/image_uploader/init.js.coffee +7 -0
  54. data/lib/assets/javascripts/socmap_adf/modules/image_uploader/templates/main.jst.eco +10 -0
  55. data/lib/assets/javascripts/socmap_adf/modules/image_uploader/views/main.js.coffee +69 -0
  56. data/lib/assets/javascripts/socmap_adf/modules/map/.DS_Store +0 -0
  57. data/lib/assets/javascripts/socmap_adf/modules/map/init.js.coffee +9 -0
  58. data/lib/assets/javascripts/socmap_adf/modules/map/models/custom_map.js.coffee +1 -0
  59. data/lib/assets/javascripts/socmap_adf/modules/map/models/map.js.coffee +63 -0
  60. data/lib/assets/javascripts/socmap_adf/modules/map/templates/main.jst.eco +1 -0
  61. data/lib/assets/javascripts/socmap_adf/modules/map/templates/moving_pin.jst.eco +11 -0
  62. data/lib/assets/javascripts/socmap_adf/modules/map/templates/tooltip.jst.eco +1 -0
  63. data/lib/assets/javascripts/socmap_adf/modules/map/views/google_marker_clusterer.js.coffee +11 -0
  64. data/lib/assets/javascripts/socmap_adf/modules/map/views/main.js.coffee +79 -0
  65. data/lib/assets/javascripts/socmap_adf/modules/map/views/moving_pin.js.coffee +47 -0
  66. data/lib/assets/javascripts/socmap_adf/modules/map/views/tooltip.js.coffee +46 -0
  67. data/lib/assets/javascripts/socmap_adf/modules/marker/init.js.coffee +6 -0
  68. data/lib/assets/javascripts/socmap_adf/modules/marker/views/.DS_Store +0 -0
  69. data/lib/assets/javascripts/socmap_adf/modules/marker/views/main.js.coffee +132 -0
  70. data/lib/assets/javascripts/socmap_adf/modules/minimap/init.js.coffee +9 -0
  71. data/lib/assets/javascripts/socmap_adf/modules/minimap/models/minimap.js.coffee +36 -0
  72. data/lib/assets/javascripts/socmap_adf/modules/minimap/templates/moving_pin.jst.eco +11 -0
  73. data/lib/assets/javascripts/socmap_adf/modules/minimap/templates/tooltip.jst.eco +1 -0
  74. data/lib/assets/javascripts/socmap_adf/modules/minimap/views/main.js.coffee +68 -0
  75. data/lib/assets/javascripts/socmap_adf/modules/minimap/views/moving_pin.js.coffee +55 -0
  76. data/lib/assets/javascripts/socmap_adf/modules/minimap/views/tooltip.js.coffee +47 -0
  77. data/lib/assets/javascripts/socmap_adf/modules/mvc/init.js.coffee +6 -0
  78. data/lib/assets/javascripts/socmap_adf/modules/mvc/views/base.js.coffee +5 -0
  79. data/lib/assets/javascripts/socmap_adf/modules/overlay/.DS_Store +0 -0
  80. data/lib/assets/javascripts/socmap_adf/modules/overlay/init.js.coffee +10 -0
  81. data/lib/assets/javascripts/socmap_adf/modules/overlay/models/overlay.js.coffee +4 -0
  82. data/lib/assets/javascripts/socmap_adf/modules/overlay/templates/main.jst.eco +1 -0
  83. data/lib/assets/javascripts/socmap_adf/modules/overlay/templates/polygon_label.jst.eco +1 -0
  84. data/lib/assets/javascripts/socmap_adf/modules/overlay/views/.DS_Store +0 -0
  85. data/lib/assets/javascripts/socmap_adf/modules/overlay/views/main.js.coffee +6 -0
  86. data/lib/assets/javascripts/socmap_adf/modules/overlay/views/overlay.js.coffee +55 -0
  87. data/lib/assets/javascripts/socmap_adf/modules/overlay/views/polygon_label.js.coffee +17 -0
  88. data/lib/assets/javascripts/socmap_adf/modules/overlay_push/init.js.coffee +8 -0
  89. data/lib/assets/javascripts/socmap_adf/modules/overlay_push/templates/colibration.jst.eco +4 -0
  90. data/lib/assets/javascripts/socmap_adf/modules/overlay_push/views/new.js.coffee +32 -0
  91. data/lib/assets/javascripts/socmap_adf/modules/popup/init.js.coffee +7 -0
  92. data/lib/assets/javascripts/socmap_adf/modules/popup/templates/base.jst.eco +5 -0
  93. data/lib/assets/javascripts/socmap_adf/modules/popup/templates/basic.jst.eco +5 -0
  94. data/lib/assets/javascripts/socmap_adf/modules/popup/views/base.js.coffee +98 -0
  95. data/lib/assets/javascripts/socmap_adf/modules/popup/views/basic.js.coffee +86 -0
  96. data/lib/assets/javascripts/socmap_adf/modules/sidebar/collections/empty +0 -0
  97. data/lib/assets/javascripts/socmap_adf/modules/sidebar/init.js.coffee +11 -0
  98. data/lib/assets/javascripts/socmap_adf/modules/sidebar/models/slice.js.coffee +0 -0
  99. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/bottomlink.jst.eco +1 -0
  100. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/bottomlinkaction.jst.eco +2 -0
  101. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/content.jst.eco +2 -0
  102. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/sidebar.jst.eco +3 -0
  103. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/tab.jst.eco +3 -0
  104. data/lib/assets/javascripts/socmap_adf/modules/sidebar/templates/tabs.jst.eco +3 -0
  105. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/bottomlink.js.coffee +41 -0
  106. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/content.js.coffee +63 -0
  107. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/sidebar.js.coffee +163 -0
  108. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/tab.js.coffee +52 -0
  109. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/tabcontent.js.coffee +23 -0
  110. data/lib/assets/javascripts/socmap_adf/modules/sidebar/views/tabs.js.coffee +63 -0
  111. data/lib/assets/javascripts/socmap_adf/modules/zone/collections/points.js.coffee +1 -0
  112. data/lib/assets/javascripts/socmap_adf/modules/zone/collections/zones.js.coffee +2 -0
  113. data/lib/assets/javascripts/socmap_adf/modules/zone/init.js.coffee +11 -0
  114. data/lib/assets/javascripts/socmap_adf/modules/zone/models/polygon.js.coffee +72 -0
  115. data/lib/assets/javascripts/socmap_adf/modules/zone/templates/main.jst.eco +0 -0
  116. data/lib/assets/javascripts/socmap_adf/modules/zone/views/main.js.coffee +6 -0
  117. data/lib/assets/javascripts/socmap_adf/modules/zone/views/test.js.coffee +17 -0
  118. data/lib/assets/javascripts/socmap_adf/requiress.js.coffee.erb +3 -0
  119. data/lib/generators/install_generator.rb +15 -0
  120. data/lib/generators/templates/socmap.rb.erb +9 -0
  121. data/lib/socmap_adf/engine.rb +5 -0
  122. data/lib/socmap_adf/version.rb +3 -0
  123. data/lib/socmap_adf.rb +17 -0
  124. data/lib/tasks/socmap-adf_tasks.rake +4 -0
  125. data/socmap_adf.gemspec +26 -0
  126. data/test/socmap-adf_test.rb +7 -0
  127. data/test/test_helper.rb +15 -0
  128. metadata +202 -0
@@ -0,0 +1,6 @@
1
+ <div class="chart_wrap">
2
+ <div class="chart"></div>
3
+ <% if @reports_count: %>
4
+ <div class="label"><strong><%= @reports_count.text %></strong><br/><%= @objectName %></div>
5
+ <% end %>
6
+ </div>
@@ -0,0 +1,107 @@
1
+ class ADF.Cluster.Views.Chart extends ADF.MVC.Views.Base
2
+
3
+ template: JST['socmap_adf/modules/cluster/templates/chart']
4
+ position: null
5
+ labelWidht: 15
6
+ labelHeight: 15
7
+ bigSize: 160
8
+ mediumSize: 120
9
+ smallSize: 80
10
+ upLimit: 50
11
+ currentSize: 120
12
+ objectName: ""
13
+ events:
14
+ "mouseenter .chart_wrap": "onChartMouseOver"
15
+ "mouseleave .chart_wrap": "onChartMouseOut"
16
+
17
+ initialize: () ->
18
+ @data = @options.data
19
+ @reports_count = @options.sum
20
+ @setSize()
21
+ @objectName = @options.objectName if @options.objectName
22
+ $.elycharts.templates['pie_basic_1'] =
23
+ type: "pie"
24
+ defaultSeries:
25
+ plotProps:
26
+ stroke: "white"
27
+ "stroke-width": 1
28
+ opacity: 0.9
29
+
30
+ setSize: () ->
31
+ count = if @reports_count then @reports_count.text else 1
32
+ if count >= @upLimit
33
+ @currentSize = @bigSize
34
+ else
35
+ @currentSize = @mediumSize
36
+
37
+ onChartMouseOver: () =>
38
+ @$(".chart").animate({opacity: 1}, 100)
39
+ @$el.css({"z-index":10})
40
+
41
+ onChartMouseOut: () =>
42
+ @$(".chart").animate({opacity: 0.7}, 100)
43
+ @$el.css({"z-index":5})
44
+
45
+ render: () =>
46
+ $(@el).html(@template({reports_count: @reports_count, objectName: @objectName }))
47
+ @$(".chart_wrap").css
48
+ position:"relative"
49
+ @$(".chart").css
50
+ height: @currentSize
51
+ width: @currentSize
52
+ opacity: 0.7
53
+ lTop = (@currentSize / 2) - (@labelHeight / 2)
54
+ lLeft = (@currentSize / 2) - (@labelWidht / 2)
55
+ @$(".label").css
56
+ position: "absolute"
57
+ top: lTop
58
+ left: lLeft
59
+ background: "#000000"
60
+ opacity: 0.8
61
+ color:"#ffffff"
62
+ "text-align": "center"
63
+ "border-radius": 4
64
+ "-moz-border-radius": 4
65
+ "-webkit-border-radius": 4
66
+ "font-size" : "13px"
67
+ "line-height": "13px"
68
+ "padding": "4px 6px"
69
+
70
+ @hide()
71
+ @onRenderCompleted()
72
+ @
73
+
74
+ onRenderCompleted: () ->
75
+ @draw() if @position?
76
+ @$(".chart").chart
77
+ template: "pie_basic_1",
78
+ values:
79
+ serie1: @data
80
+ defaultSeries:
81
+ values: [
82
+ {plotProps: { fill: "#ff6700" }},
83
+ {plotProps: { fill: "#0094ff" }},
84
+ {plotProps: { fill: "#529900" }}
85
+ ]
86
+
87
+ setPosition: (position, draw = false) ->
88
+ @position = position
89
+ @draw() if draw
90
+
91
+ draw: () ->
92
+ if @position
93
+ @$el.css
94
+ cursor:"pointer"
95
+ top: @position.y - (@currentSize / 2)
96
+ left: @position.x - (@currentSize / 2)
97
+ position:"absolute"
98
+ @show()
99
+
100
+ hide: () ->
101
+ @$el.hide()
102
+
103
+ show: () ->
104
+ @$el.show() if @position
105
+
106
+
107
+
@@ -0,0 +1,106 @@
1
+ class ADF.Cluster.Views.ChartIcon extends google.maps.OverlayView
2
+
3
+ constructor : (cluster, styles, opt_padding) ->
4
+ @styles_ = styles
5
+ @padding_ = opt_padding or 0
6
+ @cluster_ = cluster
7
+ @center_ = null
8
+ @map_ = cluster.getMap()
9
+ @chartView = null
10
+ @sums_ = null
11
+ @visible_ = false
12
+ @setMap @map_
13
+
14
+ triggerClusterClick : ->
15
+ @clickHandler(@cluster_) if @clickHandler
16
+ markerClusterer = @cluster_.getMarkerClusterer()
17
+ google.maps.event.trigger markerClusterer, "clusterclick", @cluster_
18
+ if markerClusterer.isZoomOnClick() and markerClusterer.getMaxZoomOnClick() > @map_.getZoom()
19
+ @map_.fitBounds @cluster_.getBounds()
20
+ if @map_.getZoom() > markerClusterer.getMaxZoomOnClick()
21
+ @map_.setZoom(markerClusterer.getMaxZoomOnClick())
22
+
23
+ onAdd : ->
24
+ return unless @isNeedToCluster()
25
+ @chartView = new ADF.Cluster.Views.Chart({ data: @sumData(), sum: @sums_ })
26
+
27
+ if @visible_
28
+ pos = @getPosFromLatLng_(@center_)
29
+ @chartView.setPosition( pos )
30
+
31
+ panes = @getPanes()
32
+ panes.overlayMouseTarget.appendChild @chartView.render().el
33
+
34
+ google.maps.event.addDomListener @chartView.el, "click", =>
35
+ @triggerClusterClick()
36
+
37
+ draw : ->
38
+ if @visible_
39
+ pos = @getPosFromLatLng_(@center_)
40
+ @chartView.setPosition(pos, true) if @chartView
41
+
42
+ hide : ->
43
+ if @chartView?
44
+ @chartView.hide()
45
+ @visible_ = false
46
+
47
+ show : ->
48
+ if @chartView?
49
+ pos = @getPosFromLatLng_(@center_)
50
+ @chartView.setPosition(pos, true)
51
+ @chartView.show()
52
+ else if @cluster_.getMarkers() && @cluster_.getMarkers().length == 1
53
+ marker = @cluster_.getMarkers()[0]
54
+ marker.setMap @map_
55
+ marker.getMarker().setMap @map_ if marker.getMarker()
56
+ @visible_ = true
57
+
58
+ showOrShowMarker : ->
59
+
60
+ sumData : ->
61
+ dataHash = { 1 : 0, 2 : 0, 3 : 0 }
62
+ markers = @cluster_.getMarkers()
63
+ for marker in markers
64
+ dataHash[ marker.getData() ] = if dataHash[ marker.getData() ]? then dataHash[ marker.getData() ] + 1 else 1
65
+ @result = []
66
+ $.each dataHash, (data, i) =>
67
+ @result.push i
68
+ @result
69
+
70
+ getPosFromLatLng_ : (latlng) ->
71
+ pos = @getProjection().fromLatLngToDivPixel(latlng)
72
+ pos.x -= parseInt(@width_ / 2, 10) if pos
73
+ pos.y -= parseInt(@height_ / 2, 10) if pos
74
+ pos
75
+
76
+ isNeedToCluster: () ->
77
+ markers = @cluster_.getMarkers()
78
+ if markers.length > 1 then true else false
79
+
80
+ remove : ->
81
+ @setMap null
82
+
83
+ onRemove : ->
84
+ if @chartView and @chartView.$el.parent()
85
+ @hide()
86
+ @chartView.$el.remove()
87
+ @chartView = null
88
+
89
+ setSums : (sums) ->
90
+ @sums_ = sums
91
+ @text_ = sums.text
92
+ @index_ = sums.index
93
+ @useStyle()
94
+
95
+ useStyle : ->
96
+ index = Math.max(0, @sums_.index - 1)
97
+ index = Math.min(@styles_.length - 1, index)
98
+ style = @styles_[index]
99
+ @height_ = style["height"]
100
+ @width_ = style["width"]
101
+
102
+ setCenter : (center) ->
103
+ @center_ = center
104
+
105
+ addClickHandler: (handler) ->
106
+ @clickHandler = handler
@@ -0,0 +1,127 @@
1
+ class ADF.Cluster.Views.Cluster
2
+
3
+ constructor : (markerClusterer) ->
4
+ @markerClusterer_ = markerClusterer
5
+ @map_ = markerClusterer.getMap()
6
+ @gridSize_ = markerClusterer.getGridSize()
7
+ @minClusterSize_ = markerClusterer.getMinClusterSize()
8
+ @averageCenter_ = markerClusterer.isAverageCenter()
9
+ @center_ = null
10
+ @markers_ = []
11
+ @bounds_ = null
12
+ if @markerClusterer_.getClusterShowType() == "chart"
13
+ @clusterIcon_ = new ADF.Cluster.Views.ChartIcon(this, markerClusterer.getStyles(), markerClusterer.getGridSize())
14
+ else
15
+ @clusterIcon_ = new ADF.Cluster.Views.DefaultIcon(this, markerClusterer.getStyles(), markerClusterer.getGridSize())
16
+
17
+ isMarkerAlreadyAdded : (marker) ->
18
+ if @markers_.indexOf
19
+ return @markers_.indexOf(marker) isnt -1
20
+ else
21
+ i = 0
22
+ m = undefined
23
+
24
+ while m = @markers_[i]
25
+ return true if m is marker
26
+ i++
27
+ false
28
+
29
+ addMarker : (marker) ->
30
+ return false if @isMarkerAlreadyAdded(marker)
31
+ unless @center_
32
+ @center_ = marker.getPosition()
33
+ @calculateBounds_()
34
+ else
35
+ if @averageCenter_
36
+ l = @markers_.length + 1
37
+ lat = (@center_.lat() * (l - 1) + marker.getPosition().lat()) / l
38
+ lng = (@center_.lng() * (l - 1) + marker.getPosition().lng()) / l
39
+ @center_ = new google.maps.LatLng(lat, lng)
40
+ @calculateBounds_()
41
+ marker.isAdded = true
42
+ @markers_.push marker
43
+ len = @markers_.length
44
+
45
+ # Min cluster size not reached so show the marker.
46
+ marker.setMap @map_ if len < @minClusterSize_ and marker.getMap() isnt @map_
47
+ marker.getMarker().setMap @map_ if len < @minClusterSize_ and marker.getMarker() and marker.getMarker().getMap() isnt @map_
48
+ if len is @minClusterSize_
49
+
50
+ # Hide the markers that were showing.
51
+ i = 0
52
+
53
+ while i < len
54
+ @markers_[i].setMap null
55
+ @markers_[i].getMarker().setMap null if @markers_[i].getMarker()
56
+ i++
57
+ marker.setMap null if len >= @minClusterSize_
58
+ marker.getMarker().setMap null if len >= @minClusterSize_ and marker.getMarker()
59
+ @updateIcon()
60
+ true
61
+
62
+ getMarkerClusterer : ->
63
+ @markerClusterer_
64
+
65
+ getBounds : ->
66
+ bounds = new google.maps.LatLngBounds(@center_, @center_)
67
+ markers = @getMarkers()
68
+ i = 0
69
+ marker = undefined
70
+
71
+ while marker = markers[i]
72
+ bounds.extend marker.getPosition()
73
+ i++
74
+ bounds
75
+
76
+ remove : ->
77
+ @clusterIcon_.remove()
78
+ @markers_.length = 0
79
+ delete @markers_
80
+
81
+ getClusterIcon: () ->
82
+ @clusterIcon_
83
+
84
+ getSize : ->
85
+ @markers_.length
86
+
87
+ getMarkers : ->
88
+ @markers_
89
+
90
+ getCenter : ->
91
+ @center_
92
+
93
+ calculateBounds_ : ->
94
+ bounds = new google.maps.LatLngBounds(@center_, @center_)
95
+ @bounds_ = @markerClusterer_.getExtendedBounds(bounds)
96
+
97
+ isMarkerInClusterBounds : (marker) ->
98
+ @bounds_.contains marker.getPosition()
99
+
100
+ getMap : ->
101
+ @map_
102
+
103
+ updateIcon : ->
104
+ zoom = @map_.getZoom()
105
+ mz = @markerClusterer_.getMaxZoom()
106
+ if mz and zoom > mz
107
+
108
+ # The zoom is greater than our max zoom so show all the markers in cluster.
109
+ i = 0
110
+ marker = undefined
111
+
112
+ while marker = @markers_[i]
113
+ marker.setMap @map_
114
+ marker.getMarker().setMap @map_ if marker.getMarker()
115
+ i++
116
+ return
117
+
118
+ if @markers_.length < @minClusterSize_
119
+
120
+ # Min cluster size not yet reached.
121
+ @clusterIcon_.hide()
122
+ return
123
+ numStyles = @markerClusterer_.getStyles().length
124
+ sums = @markerClusterer_.getCalculator()(@markers_, numStyles)
125
+ @clusterIcon_.setCenter @center_
126
+ @clusterIcon_.setSums sums
127
+ @clusterIcon_.show()
@@ -0,0 +1,170 @@
1
+ class ADF.Cluster.Views.DefaultIcon extends google.maps.OverlayView
2
+
3
+ constructor : (cluster, styles, opt_padding) ->
4
+ @styles_ = styles
5
+ @padding_ = opt_padding or 0
6
+ @cluster_ = cluster
7
+ @center_ = null
8
+ @map_ = cluster.getMap()
9
+ @div_ = null
10
+ @sums_ = null
11
+ @visible_ = false
12
+ @setMap @map_
13
+
14
+ ###
15
+ Triggers the clusterclick event and zoom's if the option is set.
16
+ ###
17
+ triggerClusterClick : ->
18
+ markerClusterer = @cluster_.getMarkerClusterer()
19
+
20
+ # Trigger the clusterclick event.
21
+ google.maps.event.trigger markerClusterer, "clusterclick", @cluster_
22
+
23
+ # Zoom into the cluster.
24
+ @map_.fitBounds @cluster_.getBounds() if markerClusterer.isZoomOnClick()
25
+
26
+
27
+ ###
28
+ Adding the cluster icon to the dom.
29
+ @ignore
30
+ ###
31
+ onAdd : ->
32
+ @div_ = document.createElement("DIV")
33
+ if @visible_
34
+ pos = @getPosFromLatLng_(@center_)
35
+ @div_.style.cssText = @createCss(pos)
36
+ @div_.innerHTML = @sums_.text
37
+ panes = @getPanes()
38
+ panes.overlayMouseTarget.appendChild @div_
39
+ that = this
40
+ google.maps.event.addDomListener @div_, "click", ->
41
+ that.triggerClusterClick()
42
+
43
+ ###
44
+ Returns the position to place the div dending on the latlng.
45
+
46
+ @param {google.maps.LatLng} latlng The position in latlng.
47
+ @return {google.maps.Point} The position in pixels.
48
+ @private
49
+ ###
50
+ getPosFromLatLng_ : (latlng) ->
51
+ pos = @getProjection().fromLatLngToDivPixel(latlng)
52
+ pos.x -= parseInt(@width_ / 2, 10)
53
+ pos.y -= parseInt(@height_ / 2, 10)
54
+ pos
55
+
56
+
57
+ ###
58
+ Draw the icon.
59
+ @ignore
60
+ ###
61
+ draw : ->
62
+ if @visible_
63
+ pos = @getPosFromLatLng_(@center_)
64
+ @div_.style.top = pos.y + "px"
65
+ @div_.style.left = pos.x + "px"
66
+
67
+
68
+ ###
69
+ Hide the icon.
70
+ ###
71
+ hide : ->
72
+ @div_.style.display = "none" if @div_
73
+ @visible_ = false
74
+
75
+
76
+ ###
77
+ Position and show the icon.
78
+ ###
79
+ show : ->
80
+ if @div_
81
+ pos = @getPosFromLatLng_(@center_)
82
+ @div_.style.cssText = @createCss(pos)
83
+ @div_.style.display = ""
84
+ @visible_ = true
85
+
86
+
87
+ ###
88
+ Remove the icon from the map
89
+ ###
90
+ remove : ->
91
+ @setMap null
92
+
93
+
94
+ ###
95
+ Implementation of the onRemove interface.
96
+ @ignore
97
+ ###
98
+ onRemove : ->
99
+ if @div_ and @div_.parentNode
100
+ @hide()
101
+ @div_.parentNode.removeChild @div_
102
+ @div_ = null
103
+
104
+
105
+ ###
106
+ Set the sums of the icon.
107
+
108
+ @param {Object} sums The sums containing:
109
+ 'text': (string) The text to display in the icon.
110
+ 'index': (number) The style index of the icon.
111
+ ###
112
+ setSums : (sums) ->
113
+ @sums_ = sums
114
+ @text_ = sums.text
115
+ @index_ = sums.index
116
+ @div_.innerHTML = sums.text if @div_
117
+ @useStyle()
118
+
119
+
120
+ ###
121
+ Sets the icon to the the styles.
122
+ ###
123
+ useStyle : ->
124
+ index = Math.max(0, @sums_.index - 1)
125
+ index = Math.min(@styles_.length - 1, index)
126
+ style = @styles_[index]
127
+ @url_ = style["url"]
128
+ @height_ = style["height"]
129
+ @width_ = style["width"]
130
+ @textColor_ = style["textColor"]
131
+ @anchor_ = style["anchor"]
132
+ @textSize_ = style["textSize"]
133
+ @backgroundPosition_ = style["backgroundPosition"]
134
+
135
+
136
+ ###
137
+ Sets the center of the icon.
138
+
139
+ @param {google.maps.LatLng} center The latlng to set as the center.
140
+ ###
141
+ setCenter : (center) ->
142
+ @center_ = center
143
+
144
+
145
+ ###
146
+ Create the css text based on the position of the icon.
147
+
148
+ @param {google.maps.Point} pos The position.
149
+ @return {string} The css style text.
150
+ ###
151
+ createCss : (pos) ->
152
+ style = []
153
+ style.push "background-image:url(" + @url_ + ");"
154
+ backgroundPosition = (if @backgroundPosition_ then @backgroundPosition_ else "0 0")
155
+ style.push "background-position:" + backgroundPosition + ";"
156
+ if typeof @anchor_ is "object"
157
+ if typeof @anchor_[0] is "number" and @anchor_[0] > 0 and @anchor_[0] < @height_
158
+ style.push "height:" + (@height_ - @anchor_[0]) + "px; padding-top:" + @anchor_[0] + "px;"
159
+ else
160
+ style.push "height:" + @height_ + "px; line-height:" + @height_ + "px;"
161
+ if typeof @anchor_[1] is "number" and @anchor_[1] > 0 and @anchor_[1] < @width_
162
+ style.push "width:" + (@width_ - @anchor_[1]) + "px; padding-left:" + @anchor_[1] + "px;"
163
+ else
164
+ style.push "width:" + @width_ + "px; text-align:center;"
165
+ else
166
+ style.push "height:" + @height_ + "px; line-height:" + @height_ + "px; width:" + @width_ + "px; text-align:center;"
167
+ txtColor = (if @textColor_ then @textColor_ else "black")
168
+ txtSize = (if @textSize_ then @textSize_ else 11)
169
+ style.push "cursor:pointer; top:" + pos.y + "px; left:" + pos.x + "px; color:" + txtColor + "; position:absolute; font-size:" + txtSize + "px; font-family:Arial,sans-serif; font-weight:bold"
170
+ style.join ""
@@ -0,0 +1,10 @@
1
+ class ADF.Cluster.Views.Main extends ADF.MVC.Views.Base
2
+
3
+ initialize: ->
4
+ _.bindAll(this, 'render')
5
+
6
+ render: ->
7
+ @onRenderComplete()
8
+ return @
9
+
10
+ onRenderComplete: () =>