コード例 #1
0
ファイル: OsmandRenderer.java プロジェクト: Flocki1982/Osmand
  private void drawPolygon(
      BinaryMapDataObject obj,
      RenderingRuleSearchRequest render,
      Canvas canvas,
      RenderingContext rc,
      TagValuePair pair) {
    if (render == null || pair == null) {
      return;
    }
    float xText = 0;
    float yText = 0;
    int zoom = rc.zoom;
    Path path = null;

    // rc.main.color = Color.rgb(245, 245, 245);
    render.setInitialTagValueZoom(pair.tag, pair.value, zoom, obj);
    boolean rendered = render.search(RenderingRulesStorage.POLYGON_RULES);
    if (!rendered || !updatePaint(render, paint, 0, true, rc)) {
      return;
    }
    rc.visible++;
    int len = obj.getPointsLength();
    for (int i = 0; i < obj.getPointsLength(); i++) {

      PointF p = calcPoint(obj, i, rc);
      xText += p.x;
      yText += p.y;
      if (path == null) {
        path = new Path();
        path.moveTo(p.x, p.y);
      } else {
        path.lineTo(p.x, p.y);
      }
    }
    int[][] polygonInnerCoordinates = obj.getPolygonInnerCoordinates();
    if (polygonInnerCoordinates != null && path != null) {
      path.setFillType(FillType.EVEN_ODD);
      for (int j = 0; j < polygonInnerCoordinates.length; j++) {
        for (int i = 0; i < polygonInnerCoordinates[j].length; i += 2) {
          PointF p =
              calcPoint(polygonInnerCoordinates[j][i], polygonInnerCoordinates[j][i + 1], rc);
          if (i == 0) {
            path.moveTo(p.x, p.y);
          } else {
            path.lineTo(p.x, p.y);
          }
        }
      }
    }

    if (path != null && len > 0) {
      canvas.drawPath(path, paint);
      if (updatePaint(render, paint, 1, false, rc)) {
        canvas.drawPath(path, paint);
      }
      textRenderer.renderText(obj, render, rc, pair, xText / len, yText / len, null, null);
    }
  }
コード例 #2
0
ファイル: TextRenderer.java プロジェクト: quorry/Osmand
 private void createTextDrawInfo(
     BinaryMapDataObject o,
     RenderingRuleSearchRequest render,
     RenderingContext rc,
     TagValuePair pair,
     float xMid,
     float yMid,
     Path path,
     PointF[] points,
     String name,
     String tagName) {
   render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom, o);
   render.setIntFilter(render.ALL.R_TEXT_LENGTH, name.length());
   render.setStringFilter(render.ALL.R_NAME_TAG, tagName);
   if (render.search(RenderingRulesStorage.TEXT_RULES)) {
     if (render.getIntPropertyValue(render.ALL.R_TEXT_SIZE) > 0) {
       TextDrawInfo text = new TextDrawInfo(name);
       text.fillProperties(render, xMid, yMid);
       paintText.setTextSize(rc.getDensityValue(text.textSize));
       Rect bs = new Rect();
       paintText.getTextBounds(name, 0, name.length(), bs);
       text.bounds = new RectF(bs);
       text.bounds.inset(-rc.getDensityValue(3), -rc.getDensityValue(10));
       boolean display = true;
       if (path != null) {
         text.drawOnPath = path;
         display =
             calculatePathToRotate(
                 rc, text, points, render.getIntPropertyValue(render.ALL.R_TEXT_ON_PATH, 0) != 0);
       }
       if (text.drawOnPath == null) {
         text.bounds.offset(text.centerX, text.centerY);
         // shift to match alignment
         text.bounds.offset(-text.bounds.width() / 2, 0);
       } else {
         text.bounds.offset(
             text.centerX - text.bounds.width() / 2, text.centerY - text.bounds.height() / 2);
       }
       if (display) {
         rc.textToDraw.add(text);
       }
     }
   }
 }
コード例 #3
0
ファイル: OsmandRenderer.java プロジェクト: Flocki1982/Osmand
  private void drawPoint(
      BinaryMapDataObject obj,
      RenderingRuleSearchRequest render,
      Canvas canvas,
      RenderingContext rc,
      TagValuePair pair,
      boolean renderText) {
    if (render == null || pair == null) {
      return;
    }
    render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom, obj);
    render.search(RenderingRulesStorage.POINT_RULES);

    String resId = render.getStringPropertyValue(render.ALL.R_ICON);
    if (resId == null && !renderText) {
      return;
    }
    int len = obj.getPointsLength();
    rc.visible++;
    PointF ps = new PointF(0, 0);
    for (int i = 0; i < len; i++) {
      PointF p = calcPoint(obj, i, rc);
      ps.x += p.x;
      ps.y += p.y;
    }
    if (len > 1) {
      ps.x /= len;
      ps.y /= len;
    }

    if (resId != null) {
      IconDrawInfo ico = new IconDrawInfo();
      ico.x = ps.x;
      ico.y = ps.y;
      ico.resId = resId;
      rc.iconsToDraw.add(ico);
    }
    if (renderText) {
      textRenderer.renderText(obj, render, rc, pair, ps.x, ps.y, null, null);
    }
  }
コード例 #4
0
ファイル: OsmandRenderer.java プロジェクト: Flocki1982/Osmand
  private void drawPolyline(
      BinaryMapDataObject obj,
      RenderingRuleSearchRequest render,
      Canvas canvas,
      RenderingContext rc,
      TagValuePair pair,
      int layer,
      boolean drawOnlyShadow) {
    if (render == null || pair == null) {
      return;
    }
    int length = obj.getPointsLength();
    if (length < 2) {
      return;
    }
    render.setInitialTagValueZoom(pair.tag, pair.value, rc.zoom, obj);
    render.setIntFilter(render.ALL.R_LAYER, layer);
    boolean rendered = render.search(RenderingRulesStorage.LINE_RULES);
    if (!rendered || !updatePaint(render, paint, 0, false, rc)) {
      return;
    }
    int oneway = 0;
    if (rc.zoom >= 16 && "highway".equals(pair.tag)) { // $NON-NLS-1$
      if (obj.containsAdditionalType(obj.getMapIndex().onewayAttribute)) {
        oneway = 1;
      } else if (obj.containsAdditionalType(obj.getMapIndex().onewayReverseAttribute)) {
        oneway = -1;
      }
    }

    rc.visible++;

    Path path = null;
    float xMid = 0;
    float yMid = 0;
    int middle = obj.getPointsLength() / 2;
    PointF[] textPoints = null;
    if (!drawOnlyShadow) {
      textPoints = new PointF[length];
    }

    for (int i = 0; i < length; i++) {
      PointF p = calcPoint(obj, i, rc);
      if (textPoints != null) {
        textPoints[i] = new PointF(p.x, p.y);
      }
      if (path == null) {
        path = new Path();
        path.moveTo(p.x, p.y);
      } else {
        if (i == middle) {
          xMid = p.x;
          yMid = p.y;
        }
        path.lineTo(p.x, p.y);
      }
    }
    if (path != null) {
      if (drawOnlyShadow) {
        int shadowColor = render.getIntPropertyValue(render.ALL.R_SHADOW_COLOR);
        int shadowRadius = render.getIntPropertyValue(render.ALL.R_SHADOW_RADIUS);
        if (shadowColor == 0) {
          shadowColor = rc.shadowRenderingColor;
        }
        drawPolylineShadow(canvas, rc, path, shadowColor, shadowRadius);
      } else {
        boolean update = false;
        if (updatePaint(render, paint, -2, false, rc)) {
          update = true;
          canvas.drawPath(path, paint);
        }
        if (updatePaint(render, paint, -1, false, rc)) {
          update = true;
          canvas.drawPath(path, paint);
        }
        if (update) {
          updatePaint(render, paint, 0, false, rc);
        }
        canvas.drawPath(path, paint);
        if (updatePaint(render, paint, 1, false, rc)) {
          canvas.drawPath(path, paint);
        }
        if (updatePaint(render, paint, 2, false, rc)) {
          canvas.drawPath(path, paint);
        }
      }

      if (oneway != 0 && !drawOnlyShadow) {
        Paint[] paints = oneway == -1 ? getReverseOneWayPaints() : getOneWayPaints();
        for (int i = 0; i < paints.length; i++) {
          canvas.drawPath(path, paints[i]);
        }
      }
      if (textPoints != null) {
        textRenderer.renderText(obj, render, rc, pair, xMid, yMid, path, textPoints);
      }
    }
  }