예제 #1
0
 private void render(final MapSurface surface, final List<Way> mapData) {
   // Start checking osm from bottom layer.
   for (int layer = -5; layer <= 5; layer++) {
     // Process Rule by Rule
     for (Rule rule = rules.root(); rule != null; rule = rule.next()) {
       if (rule.getDraw() != null) {
         renderPaths(surface, layer, rule, rule.getDraw(), mapData);
         // FIXME: Text Rendering
         // renderText(surface, layer, rule, rule.getDraw(), mapData);
       }
     }
   }
 }
예제 #2
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();
      }
    }
  }
예제 #3
0
  public void drawTile(final OutputStream out, final int x, final int y, final int zoom_level)
      throws IOException {

    int c_zoom_level = clamp(zoom_level, MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
    Coordinate crd = tile2latlon(x, y, c_zoom_level);

    Coordinate offset = coord2xy(crd.x, crd.y, c_zoom_level, resolution);
    BoundingBox bbox = Mercator.tileEdges(x, y, c_zoom_level);

    MapSurface surface =
        new MapSurface(resolution, resolution, rules.getBgColor(), c_zoom_level, offset, bbox);
    List<Way> mapData = map.getWaysInBoundingBox(bbox);
    render(surface, mapData);

    surface.write(out);
    surface.flush();
  }
예제 #4
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();
    }
  }