Beispiel #1
0
 private String getName(final int edge) {
   final String name = graph.getEdgeProperties(edge).getName();
   final String number = graph.getEdgeProperties(edge).getRoadRef();
   if (name == null && number == null) {
     return null;
   }
   if (name != null) {
     return name;
   } else {
     return number;
   }
 }
Beispiel #2
0
  @Override
  public BufferedImage renderTile(final int x, final int y, final int zoom) {
    ProfileMapCombination debugCurrent;
    EdgeBasedGraph debugEbg;
    Weights debugWeights;
    ArcFlags debugAF;
    if (DEBUG_VIS != 0) {
      debugCurrent = ProfileMapManager.getInstance().getCurrentCombination();
      debugEbg = debugCurrent.getStreetMap().getEdgeBasedGraph();
      debugWeights = debugCurrent.getWeights();
      debugAF = debugCurrent.getArcFlags();
    }
    GraphIndex index = graph.getIndex(zoom);

    final Set<Integer> edges = getEdgesOnTile(x, y, zoom, index);

    final BufferedImage tile = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB);
    final Graphics2D g = tile.createGraphics();
    g.setColor(new Color(210, 210, 210));
    g.fillRect(0, 0, 256, 256);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    final Stroke oldStroke = g.getStroke();
    // Draw border
    EdgeIterator it = new EdgeIterator(edges.iterator(), zoom, x, y, index);
    while (it.next()) {
      g.setColor(getMainStreetColor(it.p.getType(), true));
      g.setStroke(
          new BasicStroke(
              getStreetWidth(zoom, it.p) + 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.drawLine(it.xstart, it.ystart, it.xtarget, it.ytarget);
    }

    // Draw street
    it = new EdgeIterator(edges.iterator(), zoom, x, y, index);
    while (it.next()) {
      g.setColor(getMainStreetColor(it.p.getType(), false));
      g.setStroke(
          new BasicStroke(
              getStreetWidth(zoom, it.p), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
      g.drawLine(it.xstart, it.ystart, it.xtarget, it.ytarget);
    }

    g.setStroke(oldStroke);

    // Draw name of street – must be above all streets
    final Font font = new Font(Font.SANS_SERIF, 0, 12);
    g.setColor(Color.BLACK);
    g.setFont(font);
    it = new EdgeIterator(edges.iterator(), zoom, x, y, index);
    while (it.next()) {
      final String name = getName(it.edge);
      final double streetLength =
          Math.sqrt(Math.pow((it.xtarget - it.xstart), 2) + Math.pow((it.ytarget - it.ystart), 2));

      if (DEBUG_VIS != 0) {
        String debugData;
        int tturn = debugEbg.getOutgoingTurns(it.edge).iterator().next();
        if (DEBUG_VIS == 1) {
          debugData = Integer.toHexString(debugAF.getFlag(tturn));
        } else if (DEBUG_VIS == 4) {
          debugData = Integer.toString(it.edge);
        } else { // 2,3
          debugData =
              Integer.toString(
                  DEBUG_VIS == 2
                      ? debugWeights.getWeight(tturn)
                      : graph.getEdgeProperties(it.edge).getMaxSpeed(debugCurrent.getProfile()));
        }
        g.drawString(debugData, (it.xstart + it.xtarget) / 2, (it.ystart + it.ytarget) / 2);
      }
      if (name != null && (it.xstart != -1) && getStreetWidth(zoom, it.p) > 7) {
        final AffineTransform old = g.getTransform();

        final Rectangle2D r = font.getStringBounds(name, g.getFontRenderContext());
        double angle = getAngle(it.xstart, it.ystart, it.xtarget, it.ytarget, streetLength);

        // Pfeil <-
        if (zoom > 15 && streetLength > 40) {
          if (graph.getCorrespondingEdge(it.edge) == -1) {
            g.setColor(Color.LIGHT_GRAY);
            double angle2 = angle;
            if (it.xtarget < it.xstart || (it.xstart == it.xtarget && it.ystart > it.ytarget)) {
              angle2 -= Math.PI;
            }
            AffineTransform rotateInstance =
                AffineTransform.getRotateInstance(angle2, it.xstart, it.ystart);
            rotateInstance.translate(15 + it.xstart, it.ystart);
            g.setTransform(rotateInstance);
            drawArrow(zoom, g);
            g.setColor(Color.BLACK);
          }
        }

        int xstart;
        int ystart;
        if (it.xstart < it.xtarget || (it.xstart == it.xtarget && it.ystart < it.ytarget)) {
          xstart = it.xstart;
          ystart = it.ystart;
        } else {
          xstart = it.xtarget;
          ystart = it.ytarget;
        }
        final AffineTransform at = AffineTransform.getRotateInstance(angle, xstart, ystart);
        g.setTransform(at);
        if (r.getWidth() + 5 * space < streetLength) {
          g.drawString(
              name,
              (int) (xstart + streetLength / 2 - r.getWidth() / 2),
              (int) (ystart - r.getY() / 2 - r.getY() - r.getHeight()) + 1);
        }
        g.setTransform(old);
      }
    }
    return tile;
  }