示例#1
0
  /** @return if map could be replaced */
  public void generateNewBitmapNative(
      RenderingContext rc,
      NativeOsmandLibrary library,
      NativeSearchResult searchResultHandler,
      Bitmap bmp,
      RenderingRuleSearchRequest render,
      final List<IMapDownloaderCallback> notifyList) {
    long now = System.currentTimeMillis();
    if (rc.width > 0 && rc.height > 0 && searchResultHandler != null) {
      // init rendering context
      rc.tileDivisor = (int) (1 << (31 - rc.zoom));
      rc.cosRotateTileSize = FloatMath.cos((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
      rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
      try {
        if (Looper.getMainLooper() != null && library.useDirectRendering()) {
          final Handler h = new Handler(Looper.getMainLooper());
          notifyListenersWithDelay(rc, notifyList, h);
        }

        // Native library will decide on it's own best way of rendering
        // If res.bitmapBuffer is null, it indicates that rendering was done directly to
        // memory of passed bitmap, but this is supported only on Android >= 2.2
        final NativeLibrary.RenderingGenerationResult res =
            library.generateRendering(rc, searchResultHandler, bmp, bmp.hasAlpha(), render);
        rc.ended = true;
        notifyListeners(notifyList);
        long time = System.currentTimeMillis() - now;
        rc.renderingDebugInfo =
            String.format(
                "Rendering: %s ms  (%s text)\n"
                    + "(%s points, %s points inside, %s of %s objects visible)\n", //$NON-NLS-1$
                time,
                rc.textRenderingTime,
                rc.pointCount,
                rc.pointInsideCount,
                rc.visible,
                rc.allObjects);

        // See upper note
        if (res.bitmapBuffer != null) {
          bmp.copyPixelsFromBuffer(res.bitmapBuffer);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
示例#2
0
  public void generateNewBitmap(
      RenderingContext rc,
      List<BinaryMapDataObject> objects,
      Bitmap bmp,
      RenderingRuleSearchRequest render,
      final List<IMapDownloaderCallback> notifyList) {
    long now = System.currentTimeMillis();
    // fill area
    Canvas cv = new Canvas(bmp);
    if (rc.defaultColor != 0) {
      cv.drawColor(rc.defaultColor);
    }
    if (objects != null && !objects.isEmpty() && rc.width > 0 && rc.height > 0) {
      // init rendering context
      rc.tileDivisor = (int) (1 << (31 - rc.zoom));
      rc.cosRotateTileSize = FloatMath.cos((float) Math.toRadians(rc.rotate)) * TILE_SIZE;
      rc.sinRotateTileSize = FloatMath.sin((float) Math.toRadians(rc.rotate)) * TILE_SIZE;

      // put in order map
      TIntObjectHashMap<TIntArrayList> orderMap = sortObjectsByProperOrder(rc, objects, render);

      int objCount = 0;

      int[] keys = orderMap.keys();
      Arrays.sort(keys);

      boolean shadowDrawn = false;

      for (int k = 0; k < keys.length; k++) {
        if (!shadowDrawn
            && (keys[k] >> 2) >= rc.shadowLevelMin
            && (keys[k] >> 2) <= rc.shadowLevelMax
            && rc.shadowRenderingMode > 1) {
          for (int ki = k; ki < keys.length; ki++) {
            if ((keys[ki] >> 2) > rc.shadowLevelMax || rc.interrupted) {
              break;
            }
            TIntArrayList list = orderMap.get(keys[ki]);
            for (int j = 0; j < list.size(); j++) {
              int i = list.get(j);
              int ind = i >> 8;
              int l = i & 0xff;
              BinaryMapDataObject obj = objects.get(ind);

              // show text only for main type
              drawObj(obj, render, cv, rc, l, l == 0, true, (keys[ki] & 3));
              objCount++;
            }
          }
          shadowDrawn = true;
        }
        if (rc.interrupted) {
          return;
        }

        TIntArrayList list = orderMap.get(keys[k]);
        for (int j = 0; j < list.size(); j++) {
          int i = list.get(j);
          int ind = i >> 8;
          int l = i & 0xff;
          BinaryMapDataObject obj = objects.get(ind);

          // show text only for main type
          drawObj(obj, render, cv, rc, l, l == 0, false, (keys[k] & 3));
          objCount++;
        }
        rc.lastRenderedKey = (keys[k] >> 2);
        if (objCount > 25) {
          notifyListeners(notifyList);
          objCount = 0;
        }
      }

      long beforeIconTextTime = System.currentTimeMillis() - now;
      notifyListeners(notifyList);
      drawIconsOverCanvas(rc, cv);

      notifyListeners(notifyList);
      textRenderer.drawTextOverCanvas(rc, cv, rc.useEnglishNames);

      long time = System.currentTimeMillis() - now;
      rc.renderingDebugInfo =
          String.format(
              "Rendering: %s ms  (%s text)\n"
                  + "(%s points, %s points inside, %s of %s objects visible)", //$NON-NLS-1$
              time,
              time - beforeIconTextTime,
              rc.pointCount,
              rc.pointInsideCount,
              rc.visible,
              rc.allObjects);
      log.info(rc.renderingDebugInfo);
    }
  }