Beispiel #1
0
  private TIntObjectHashMap<TIntArrayList> sortObjectsByProperOrder(
      RenderingContext rc, List<BinaryMapDataObject> objects, RenderingRuleSearchRequest render) {
    int sz = objects.size();
    TIntObjectHashMap<TIntArrayList> orderMap = new TIntObjectHashMap<TIntArrayList>();
    if (render != null) {
      render.clearState();

      for (int i = 0; i < sz; i++) {
        BinaryMapDataObject o = objects.get(i);
        int sh = i << 8;

        for (int j = 0; j < o.getTypes().length; j++) {
          // put(orderMap, BinaryMapDataObject.getOrder(o.getTypes()[j]), sh + j, init);
          int wholeType = o.getTypes()[j];

          int layer = 0;
          if (o.getPointsLength() > 1) {
            layer = o.getSimpleLayer();
          }

          TagValuePair pair = o.getMapIndex().decodeType(wholeType);
          if (pair != null) {
            render.setTagValueZoomLayer(pair.tag, pair.value, rc.zoom, layer, o);
            render.setBooleanFilter(render.ALL.R_AREA, o.isArea());
            render.setBooleanFilter(render.ALL.R_POINT, o.getPointsLength() == 1);
            render.setBooleanFilter(render.ALL.R_CYCLE, o.isCycle());
            if (render.search(RenderingRulesStorage.ORDER_RULES)) {
              int objectType = render.getIntPropertyValue(render.ALL.R_OBJECT_TYPE);
              int order = render.getIntPropertyValue(render.ALL.R_ORDER);
              put(orderMap, (order << 2) | objectType, sh + j);
              if (objectType == 3) {
                // add icon point all the time
                put(orderMap, (128 << 2) | 1, sh + j);
              }
              if (render.isSpecified(render.ALL.R_SHADOW_LEVEL)) {
                rc.shadowLevelMin = Math.min(rc.shadowLevelMin, order);
                rc.shadowLevelMax = Math.max(rc.shadowLevelMax, order);
                render.clearValue(render.ALL.R_SHADOW_LEVEL);
              }
            }
          }
        }

        if (rc.interrupted) {
          return orderMap;
        }
      }
    }
    return orderMap;
  }
Beispiel #2
0
 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);
       }
     }
   }
 }
Beispiel #3
0
 public void fillProperties(RenderingRuleSearchRequest render, float centerX, float centerY) {
   this.centerX = centerX;
   this.centerY = centerY + render.getIntPropertyValue(render.ALL.R_TEXT_DY, 0);
   // used only for draw on path where centerY doesn't play role
   this.vOffset = render.getIntPropertyValue(render.ALL.R_TEXT_DY, 0);
   textColor = render.getIntPropertyValue(render.ALL.R_TEXT_COLOR);
   if (textColor == 0) {
     textColor = Color.BLACK;
   }
   textSize = render.getIntPropertyValue(render.ALL.R_TEXT_SIZE);
   textShadow = render.getIntPropertyValue(render.ALL.R_TEXT_HALO_RADIUS, 0);
   textWrap = render.getIntPropertyValue(render.ALL.R_TEXT_WRAP_WIDTH, 0);
   bold = render.getIntPropertyValue(render.ALL.R_TEXT_BOLD, 0) > 0;
   minDistance = render.getIntPropertyValue(render.ALL.R_TEXT_MIN_DISTANCE, 0);
   if (render.isSpecified(render.ALL.R_TEXT_SHIELD)) {
     shieldRes = render.getStringPropertyValue(render.ALL.R_TEXT_SHIELD);
   }
   textOrder = render.getIntPropertyValue(render.ALL.R_TEXT_ORDER, 100);
 }
Beispiel #4
0
  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);
      }
    }
  }
Beispiel #5
0
  private boolean updatePaint(
      RenderingRuleSearchRequest req, Paint p, int ind, boolean area, RenderingContext rc) {
    RenderingRuleProperty rColor;
    RenderingRuleProperty rStrokeW;
    RenderingRuleProperty rCap;
    RenderingRuleProperty rPathEff;

    if (ind == 0) {
      rColor = req.ALL.R_COLOR;
      rStrokeW = req.ALL.R_STROKE_WIDTH;
      rCap = req.ALL.R_CAP;
      rPathEff = req.ALL.R_PATH_EFFECT;
    } else if (ind == 1) {
      rColor = req.ALL.R_COLOR_2;
      rStrokeW = req.ALL.R_STROKE_WIDTH_2;
      rCap = req.ALL.R_CAP_2;
      rPathEff = req.ALL.R_PATH_EFFECT_2;
    } else if (ind == -1) {
      rColor = req.ALL.R_COLOR_0;
      rStrokeW = req.ALL.R_STROKE_WIDTH_0;
      rCap = req.ALL.R_CAP_0;
      rPathEff = req.ALL.R_PATH_EFFECT_0;
    } else if (ind == -2) {
      rColor = req.ALL.R_COLOR__1;
      rStrokeW = req.ALL.R_STROKE_WIDTH__1;
      rCap = req.ALL.R_CAP__1;
      rPathEff = req.ALL.R_PATH_EFFECT__1;
    } else {
      rColor = req.ALL.R_COLOR_3;
      rStrokeW = req.ALL.R_STROKE_WIDTH_3;
      rCap = req.ALL.R_CAP_3;
      rPathEff = req.ALL.R_PATH_EFFECT_3;
    }
    if (area) {
      if (!req.isSpecified(rColor) && !req.isSpecified(req.ALL.R_SHADER)) {
        return false;
      }
      p.setShader(null);
      p.setColorFilter(null);
      p.clearShadowLayer();
      p.setStyle(Style.FILL_AND_STROKE);
      p.setStrokeWidth(0);
    } else {
      if (!req.isSpecified(rStrokeW)) {
        return false;
      }
      p.setShader(null);
      p.setColorFilter(null);
      p.clearShadowLayer();
      p.setStyle(Style.STROKE);
      p.setStrokeWidth(req.getFloatPropertyValue(rStrokeW));
      String cap = req.getStringPropertyValue(rCap);
      if (!Algoritms.isEmpty(cap)) {
        p.setStrokeCap(Cap.valueOf(cap.toUpperCase()));
      } else {
        p.setStrokeCap(Cap.BUTT);
      }
      String pathEffect = req.getStringPropertyValue(rPathEff);
      if (!Algoritms.isEmpty(pathEffect)) {
        p.setPathEffect(getDashEffect(pathEffect));
      } else {
        p.setPathEffect(null);
      }
    }
    p.setColor(req.getIntPropertyValue(rColor));
    if (ind == 0) {
      String resId = req.getStringPropertyValue(req.ALL.R_SHADER);
      if (resId != null) {
        p.setShader(getShader(resId));
      }
      // do not check shadow color here
      if (rc.shadowRenderingMode == 1) {
        int shadowColor = req.getIntPropertyValue(req.ALL.R_SHADOW_COLOR);
        if (shadowColor == 0) {
          shadowColor = rc.shadowRenderingColor;
        }
        int shadowLayer = req.getIntPropertyValue(req.ALL.R_SHADOW_RADIUS);
        if (shadowColor == 0) {
          shadowLayer = 0;
        }
        p.setShadowLayer(shadowLayer, 0, 0, shadowColor);
      }
    }

    return true;
  }