             @plants = _.map [1..@count], (i) =>
                 new draw.Plant(@dimension, @colors[(i-1) % @colors.length],
                     id, rotations[i-1], translations[i-1])
-        createIcon: ->
-            el = document.createElement 'canvas'
-            # If the IE Canvas polyfill is installed, the element needs to be specially
-            # initialized.
-            if G_vmlCanvasManager?
-                G_vmlCanvasManager.initElement el
-            @_setIconStyles el, 'icon'
-            s = @options.iconSize
-            el.width = s.x + 20
-            el.height = s.y + 20
+        draw: (ctx) ->
+            for plant in @plants
+                plant.draw ctx
 
-            for plant, i in @plants
-                plant.draw el.getContext('2d')
-            return el
+    PointCanvasClusterIcon = CanvasIcon.extend
+        initialize: (count, @dimension, @colors, id) ->
+            CanvasIcon.prototype.initialize.call this, @dimension
+            @count = (Math.min(20, count) / 5) * 5
+            @radius = 2
+            range = =>
+                @radius + Math.random() * (@dimension - 2 * @radius)
+            @positions = _.map [1..@count], (i) =>
+                [range(), range()]
+            @cluster_drawer = new draw.PointCluster @dimension, @colors, @positions, @radius
+        draw: (ctx) ->
+            @cluster_drawer.draw ctx
 
     LeftAlignedPopup = L.Popup.extend
         _updatePosition: ->


    exports =
        CanvasIcon: CanvasIcon
        CanvasClusterIcon: CanvasClusterIcon
        LeftAlignedPopup: LeftAlignedPopup
    exports

                G_vmlCanvasManager.initElement el
            @_setIconStyles el, 'icon'
            s = @options.iconSize
            el.width = s.x
            el.height = s.y
            el
        createIcon: ->
            el = @setupCanvas()
            @draw el.getContext('2d')
            el
        createShadow: ->
            return null
        iconAnchor: ->
            anchor @options.iconSize

    PlantCanvasIcon = CanvasIcon.extend
        initialize: (@dimension, @color, id) ->
            CanvasIcon.prototype.initialize.call this, @dimension
            @plant = new draw.Plant @dimension, @color, id
        draw: (ctx) ->
            @plant.draw ctx

    PointCanvasIcon = CanvasIcon.extend
        initialize: (@dimension, @color, id) ->
            CanvasIcon.prototype.initialize.call this, @dimension
            @drawer = new draw.PointPlant @dimension, @color, 2
        draw: (ctx) ->
            @drawer.draw ctx

    CanvasClusterIcon = CanvasIcon.extend
        initialize: (@count, @dimension, @colors, id) ->
            CanvasIcon.prototype.initialize.call this, @dimension
            @options.iconSize = new L.Point @dimension + 30, @dimension + 30
            if @count > 5
                @count = 5
            rotations = [130,110,90,70,50]
