             @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: ->

        new L.Point size.x/3 - 7, size.y/2 - 4

    CanvasIcon = L.Icon.extend
        initialize: (@dimension, @color, id) ->
            @options.iconSize = new L.Point @dimension, @dimension
            @options.iconAnchor = anchor(@options.iconSize)
            @plant = new draw.Plant(@dimension, @color, id)
        options:
            className: 'leaflet-canvas-icon'
        createIcon: ->
            el = document.createElement 'canvas'
            # If the IE Canvas polyfill is installed, the element needs to be specially
            # initialized.


    exports =
        CanvasIcon: CanvasIcon
        PlantCanvasIcon: PlantCanvasIcon
        PointCanvasIcon: PointCanvasIcon
        CanvasClusterIcon: CanvasClusterIcon
        PointCanvasClusterIcon: PointCanvasClusterIcon
        LeftAlignedPopup: LeftAlignedPopup
    exports
