Beispiel #1
0
  private void renderText(
      MapSurface surface, int layer, Rule rule, Draw draw, final List<Way> mapData) {
    Graphics2D graphics = surface.getGraphics();
    Draw d = draw;

    while (d != null) {
      Font font = getFont((int) (d.getWidth() * linesize(surface.zoomLevel)));

      if (d.type == Draw.TEXT && font != null) {
        if (draw.getMinZoom() <= surface.zoomLevel && surface.zoomLevel <= draw.getMaxZoom()) {

          for (Way way : mapData) {
            // Only objects on current layer
            if (way.getLayer() != layer || way.getName() == null) continue;

            Map<String, String> tags = way.getTags();
            if (tags != null) {
              if (RuleSet.checkRule(rule, tags)) {
                // TODO: verify if there is a path and render text along the path? or see how
                // osmarender does it?
                graphics.setFont(font);
                graphics.setPaint(d.getColor());
                Node nd = way.getWayNode().get(0);
                Coordinate xy = coord2xy(nd.getLat(), nd.getLon(), surface.zoomLevel, resolution);

                graphics.drawString(
                    way.getName(),
                    (int) (xy.x - surface.offset.x),
                    (int) (xy.y - surface.offset.y));
              }
            }
          }
        }
        break;
      }
      d = d.next();
    }
  }