                     for own mcid, mc of markerCluster._childClusters
                         unitNames = unitNames.concat getClusteredUnits(mc)
                     unitNames
+
                 if marker instanceof L.MarkerCluster
                     # Adjust the icon anchor position for clusters with these magic numbers
-                    marker.options.icon.options.iconAnchor = new L.Point(iconSize/2, iconSize/6)
+                    marker.options.icon.options.iconAnchor = new L.Point(5*iconSize/6, iconSize / 6)
                     unitNames = getClusteredUnits(marker)
                     for name in unitNames
                         div = document.createElement 'div'
                         div.className = 'printed-unit-name'
                         div.textContent = name
-                        l.appendChild div
+                        markerLegend.appendChild div
 
                 else
                     div = document.createElement 'div'
                     div.className = 'printed-unit-name'
                     div.textContent = marker.unit.attributes.name.fi
-                    l.appendChild div
-                listOfUnits.appendChild(l)
-                window.printedMarkers.push(marker);
-
-        console.log leafletImage
-        #console.time('print')
+                    markerLegend.appendChild div
+                listOfUnits.appendChild(markerLegend)
+            else # Markers outside the current view
+
         leafletImage map, (err, canvas) =>
             # now you have canvas
             # example thing to do with that canvas:
             console.log canvas, err
             img = document.createElement 'img'
-            dimensions = map.getSize()
-            #img.width = dimensions.x
-            #img.height = dimensions.y
             img.src = canvas.toDataURL()
-            #document.getElementById('images').innerHTML = ''
             document.getElementById('images').appendChild img
             window.makingPrint = false
-            #alert 'Print now :)'
-            #window.print()
-            #window.print()
-            #console.timeEnd('print')
-
 
     window.onAfterPrint = () =>
         if window.makingPrint

        window.printedMarkers = [];
        window.printIcons = [];
        for own id, marker of markers

            printStore = {
                iconSize: marker.options.iconSize,
                iconAnchor: marker.options.iconAnchor
            }
            marker.options.icon.options.printStore = printStore
            #marker.options.icon
            iconSize = mapView.getIconSize();
            # Make icons smaller on print to avoid overlap
            marker.options.icon.options.iconSize = new L.Point(2*iconSize/3, 2*iconSize/3)
            # Adjust the icon anchor to the smaller icon size
            marker.options.icon.options.iconAnchor = new L.Point(iconSize/3, iconSize/3)

            bounds = map.getPixelBounds()
            sw = map.unproject(bounds.getBottomLeft())
            ne = map.unproject(bounds.getTopRight())
            if(new L.LatLngBounds(sw, ne).contains(marker.getLatLng()))
                marker.vid = vid()
                marker._iconStore = marker._icon
                # Lines below break canvas sizes for makers when zooming after printing
                #ctor = widgets.NumberCircleCanvasIcon
                #icon = new ctor marker.vid, 100 #window.mapView.getIconSize()
                #iconCanvas = document.createElement('canvas')
                #iconCanvas.width = mapView.getIconSize();
                #iconCanvas.height = mapView.getIconSize();
                #icon.draw(iconCanvas.getContext('2d'))
                #marker._icon = iconCanvas

                canvasIcon = document.createElement('canvas')
                canvasIcon.height = iconSize
                canvasIcon.width = iconSize
                ctx = canvasIcon.getContext('2d')
                drawer = new draw.NumberCircleMaker(iconSize);
                drawer.drawNumberedCircle(ctx, marker.vid)
                marker._icon = canvasIcon

                l = document.createElement 'div'
                l.innerHTML = "<div>" + marker.vid + ": " + "</div>";

                getClusteredUnits = (markerCluster) ->
                    unitNames = []

        listOfUnits?.remove()
        window.printed = true

    # Add print event listeners
    (() ->
        # webkit
        if window.matchMedia
            mediaQueryList = window.matchMedia('print')
            mediaQueryList.addListener (mql) ->
