         listOfUnits = document.createElement('div')
         listOfUnits.id = 'list-of-units';
         document.getElementsByTagName('body')[0].appendChild(listOfUnits);
+
+        # Counter for printed markers
         vid = (() ->
             num = 0
             inc = () -> ++num

                    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)
                    unitNames = getClusteredUnits(marker)
                    for name in unitNames
                        div = document.createElement 'div'
                        div.className = 'printed-unit-name'
                        div.textContent = name
                        l.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')
        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
            # Settings altered for printing. These will be reset after printing.
            printStore = {storeAttributes: ['iconSize', 'iconAnchor'] }
            for att in printStore.storeAttributes
                if marker.options.icon.options[att]
                    printStore[att] = marker.options.icon.options[att]
            marker.options.icon.options.printStore = printStore

            # Icon size smaller than 70 causes clusters to misbehave when zooming in after printing
            iconSize = 70
            marker.options.icon.options.iconSize = new L.Point(iconSize, iconSize)
            # Adjust the icon anchor to correct place
            marker.options.icon.options.iconAnchor = new L.Point(3*iconSize/4, iconSize/4)

            #
            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()
                # Don't throw the actual icon away
                marker._iconStore = marker._icon

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

                # With this kind of marker Firefox doesn't miss markers but creating the leaflet-image
                # takes much longer
                #marker._icon = document.createElement 'img'
                #marker._icon.src = 'http://localhost:8000/leaflet/images/marker-icon-2x.png'

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

                getClusteredUnits = (markerCluster) ->
                    unitNames = []
