     for callback in @afterRenderQueue
       result = callback.call render, render
       onResult? result
+
+beforeRender = (fn) ->
+  unless currentMapping?
+    throw new SVGTilerError "svgtiler.beforeRender called outside mapping file"
+  currentMapping.beforeRender fn
+afterRender = (fn) ->
+  unless currentMapping?
+    throw new SVGTilerError "svgtiler.afterRender called outside mapping file"
+  currentMapping.afterRender fn
 
 class ASCIIMapping extends Mapping
   @title: "ASCII mapping file"

class Styles extends ArrayWrapper
  @itemClass: Style

getMapping = ->
  ## Returns current `Mapping` object,
  ## when used at top level of a JS/CS mapping file.
  currentMapping
runWithMapping = (mapping, fn) ->
  ## Runs the specified function `fn` as if it were called
  ## at the top level of the specified mapping.
  oldMapping = currentMapping
  currentMapping = mapping
  try
    fn()
  finally
    currentMapping = oldMapping

beforeRender = (fn) ->
  unless currentMapping?
    throw new SVGTilerError "svgtiler.beforeRender called outside mapping file"
  currentMapping.beforeRender fn
afterRender = (fn) ->
  unless currentMapping?
    throw new SVGTilerError "svgtiler.afterRender called outside mapping file"
  currentMapping.afterRender fn

class Mapping extends Input
  ###
  Base Mapping class.

    missing = new Set
    cache = new Map
    symbolIds = new Set
    @tiles =
      for row, i in @drawing.keys
        for key, j in row
