# Class MapCanvas.Renderer

Object
Renderer

Direct Known Subclasses:
  `MapCanvasAWT​.Renderer`

Enclosing class:
  `MapCanvas`

protected abstract static class MapCanvas.Renderer extends Object
A snapshot of `MapCanvas` state to render as a map, together with rendering code. This class is instantiated and used as below:

1. `MapCanvas` invokes `MapCanvas​.createRenderer()` in the JavaFX thread. That method shall take a snapshot of every information needed for performing the rendering in a background thread.
2. `MapCanvas` invokes `render()` in a background thread. That method creates or updates the nodes to show in the canvas but without reading or writing any canvas property; that method should use only the snapshot taken in step 1.
3. `MapCanvas` invokes `commit(MapCanvas)` in the JavaFX thread. The nodes prepared at step 2 can be transferred to `MapCanvas​.floatingPane` in that method.

Since:
  1.1

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Renderer()`
  Creates a new renderer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected abstract boolean`
  `commit(MapCanvas canvas)`
  Invoked in JavaFX thread after `render()` completion.
  `int`
  `getHeight()`
  Returns the height (number of rows) of the view, in pixels.
  `int`
  `getWidth()`
  Returns the width (number of columns) of the view, in pixels.
  `protected abstract void`
  `render()`
  Invoked in a background thread for rendering the map.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Renderer

    protected Renderer()
    Creates a new renderer. The width and height are initially zero; they will get a non-zero values before `render()` is invoked.

- ## Method Details

  - ### getWidth

    public int getWidth()
    Returns the width (number of columns) of the view, in pixels.
    Returns:
      number of pixels to render horizontally.

  - ### getHeight

    public int getHeight()
    Returns the height (number of rows) of the view, in pixels.
    Returns:
      number of pixels to render vertically.

  - ### render

    protected abstract void render() throws Exception
    Invoked in a background thread for rendering the map. This method should not access any `MapCanvas` property; if some canvas properties are needed, they should have been copied at construction time.
    Throws:
      `Exception` - if an error occurred while preparing data or rendering them.

  - ### commit

    protected abstract boolean commit(MapCanvas canvas)
    Invoked in JavaFX thread after `render()` completion. This method can update the `MapCanvas​.floatingPane` children with the nodes (images, shaped, etc.) created by `render()`.
    Parameters:
      `canvas` - the canvas where drawing has been done.
    Returns:
      `true` on success, or `false` if the rendering should be redone (for example because a change has been detected in the data).