示例#1
0
  private void renderPaths(
      MapSurface surface, int layer, Rule rule, Draw draw, final List<Way> mapData) {
    int paths = 0;
    Draw d = draw;
    surface.path.reset();

    // Loop through ways for
    for (Way way : mapData) {
      // perform geometry culling. If an object is not on the current layer or
      // inside the tile bounding box, it can be skipped
      if (way.getLayer() != layer) continue;
      Map<String, String> tags = way.getTags();
      if (tags != null) {
        if (RuleSet.checkRule(rule, tags)) {
          paths += buildPath(surface, way.getWayNode());
        }
      }
    }
    if (paths != 0) {

      Graphics2D graphics = surface.getGraphics();

      while (d != null) {
        if (d.getMinZoom() > surface.zoomLevel || d.getMaxZoom() < surface.zoomLevel) {
          d = d.next();
          continue;
        }
        switch (d.type) {
          case Draw.POLYGONE:
            graphics.setPaint(getPaint(d.getPattern(), d.getColor()));
            graphics.fill(surface.path);
            break;
          case Draw.LINE:
            float strokeWidth = d.getWidth() * linesize(surface.zoomLevel);
            if (strokeWidth > 0.5f) {
              Stroke stroke =
                  new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

              graphics.setPaint(d.getColor());
              graphics.setStroke(stroke);
              graphics.draw(surface.path);
            }
            break;
          case Draw.TEXT:
            break; /* ignore since we will process it in other step */
        }
        d = d.next();
      }
    }
  }
示例#2
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();
    }
  }