/**
   * Initialize scale bar.
   *
   * @param unitType how are units shown (english/metric/crs)
   * @param unitLength length of a unit in meter
   * @param position coordinate where scalebar should be drawn on the graphics context
   */
  public void initialize(UnitType unitType, double unitLength, Coordinate position) {
    if (null == unitType) {
      throw new IllegalArgumentException("please provide a unitType");
    }

    this.unitType = unitType;
    this.unitLength = unitLength;

    backGround = new Rectangle((null == getId() ? "" : getId() + "-bg"));
    backGround.setBounds(new Bbox(0, 0, 5, MARKER_HEIGHT + 2 * VERTICAL_PADDING));
    backGround.setStyle(STYLE_BACKGROUND);
    leftMarker = new Rectangle((null == getId() ? "" : getId() + "-lm"));
    leftMarker.setStyle(STYLE_MARKER);
    leftMarker.setBounds(new Bbox(0, 0, 1, MARKER_HEIGHT));

    rightMarker = new Rectangle((null == getId() ? "" : getId() + "-rm"));
    rightMarker.setStyle(STYLE_MARKER);
    rightMarker.setBounds(new Bbox(0, 0, 1, MARKER_HEIGHT));
    bottomLine = new Rectangle((null == getId() ? "" : getId() + "-bm"));
    bottomLine.setStyle(STYLE_MARKER);
    bottomLine.setBounds(new Bbox(0, 0, 0, 1));
    distance = new Text((null == getId() ? "" : getId() + "-text"));
    distance.setStyle(STYLE_FONT);

    dummy = new Rectangle(getId() + "-dummy");
    dummy.setStyle(new ShapeStyle("#FFFFFF", 0, "#FFFFFF", 0, 0));
    dummy.setBounds(new Bbox(0, 0, 1, 1));
  }
 /**
  * Set map size.
  *
  * @param mapWidth map width
  * @param mapHeight map height
  */
 public void setMapSize(int mapWidth, int mapHeight) {
   super.setMapSize(mapWidth, mapHeight);
   if (null == unitType) {
     throw new IllegalStateException("Please initialize scale bar before using");
   }
   backGround.getBounds().setX(getUpperLeftCorner().getX());
   backGround.getBounds().setY(getUpperLeftCorner().getY());
   bottomLine.getBounds().setX(getUpperLeftCorner().getX() + HORIZONTAL_PADDING);
   bottomLine.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING + MARKER_HEIGHT);
   leftMarker.getBounds().setX(getUpperLeftCorner().getX() + HORIZONTAL_PADDING);
   leftMarker.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING);
   rightMarker.getBounds().setY(getUpperLeftCorner().getY() + VERTICAL_PADDING);
   distance.setPosition(
       new Coordinate(
           getUpperLeftCorner().getX() + HORIZONTAL_PADDING + 6,
           getUpperLeftCorner().getY() + VERTICAL_PADDING));
 }
 private void updatePaintables() {
   distance.setContent(formatUnits(widthInUnits));
   backGround.getBounds().setWidth(widthInPixels + 2 * HORIZONTAL_PADDING);
   rightMarker.getBounds().setX(leftMarker.getBounds().getX() + widthInPixels - 1);
   bottomLine.getBounds().setWidth(widthInPixels);
 }
  @Override
  public void accept(PainterVisitor visitor, Object group, Bbox bounds, boolean recursive) {
    map.getVectorContext().drawGroup(group, this);
    adjustScale(map.getMapModel().getMapView().getCurrentScale());
    // Draw a dummy at 0,0 so that Internet Explorer knows where coordinate 0,0 is. If this is not
    // drawn, the text
    // will disappear, because the parent group will have coordinate 0,0 at the upper left corner of
    // the union of
    // all the rectangles that are drawn here.
    map.getVectorContext()
        .drawRectangle(this, dummy.getId(), dummy.getBounds(), (ShapeStyle) dummy.getStyle());

    map.getVectorContext()
        .drawRectangle(this, backGround.getId(), backGround.getBounds(), backGround.getStyle());
    map.getVectorContext()
        .drawRectangle(this, bottomLine.getId(), bottomLine.getBounds(), bottomLine.getStyle());
    map.getVectorContext()
        .drawRectangle(this, leftMarker.getId(), leftMarker.getBounds(), leftMarker.getStyle());
    map.getVectorContext()
        .drawRectangle(this, rightMarker.getId(), rightMarker.getBounds(), rightMarker.getStyle());
    map.getVectorContext()
        .drawText(
            this,
            distance.getId(),
            distance.getContent(),
            distance.getPosition(),
            distance.getStyle());
  }