Exemple #1
0
  @Override
  public void draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, Point topLeftPoint) {
    long tileLeft = MercatorProjection.longitudeToTileX(boundingBox.minLongitude, zoomLevel);
    long tileTop = MercatorProjection.latitudeToTileY(boundingBox.maxLatitude, zoomLevel);
    long tileRight = MercatorProjection.longitudeToTileX(boundingBox.maxLongitude, zoomLevel);
    long tileBottom = MercatorProjection.latitudeToTileY(boundingBox.minLatitude, zoomLevel);

    int tileSize = this.displayModel.getTileSize();
    int pixelX1 = (int) (MercatorProjection.tileToPixel(tileLeft, tileSize) - topLeftPoint.x);
    int pixelY1 = (int) (MercatorProjection.tileToPixel(tileTop, tileSize) - topLeftPoint.y);
    int pixelX2 =
        (int) (MercatorProjection.tileToPixel(tileRight, tileSize) - topLeftPoint.x + tileSize);
    int pixelY2 =
        (int) (MercatorProjection.tileToPixel(tileBottom, tileSize) - topLeftPoint.y + tileSize);

    for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize) {
      canvas.drawLine(lineX, pixelY1, lineX, pixelY2, this.paintBack);
    }

    for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize) {
      canvas.drawLine(pixelX1, lineY, pixelX2, lineY, this.paintBack);
    }

    for (int lineX = pixelX1; lineX <= pixelX2 + 1; lineX += tileSize) {
      canvas.drawLine(lineX, pixelY1, lineX, pixelY2, this.paintFront);
    }

    for (int lineY = pixelY1; lineY <= pixelY2 + 1; lineY += tileSize) {
      canvas.drawLine(pixelX1, lineY, pixelX2, lineY, this.paintFront);
    }
  }
  @Test
  public void executeQueryTest() {
    MapFile mapFile = new MapFile(MAP_FILE);

    MapFileInfo mapFileInfo = mapFile.getMapFileInfo();
    Assert.assertTrue(mapFileInfo.debugFile);

    for (byte zoomLevel = ZOOM_LEVEL_MIN; zoomLevel <= ZOOM_LEVEL_MAX; ++zoomLevel) {
      int tileX = MercatorProjection.longitudeToTileX(0.04, zoomLevel);
      int tileY = MercatorProjection.latitudeToTileY(0.04, zoomLevel);
      Tile tile = new Tile(tileX, tileY, zoomLevel, 256);

      MapReadResult mapReadResult = mapFile.readMapData(tile);

      Assert.assertEquals(1, mapReadResult.pointOfInterests.size());
      Assert.assertEquals(1, mapReadResult.ways.size());

      checkPointOfInterest(mapReadResult.pointOfInterests.get(0));
      checkWay(mapReadResult.ways.get(0));
    }

    mapFile.close();
  }
  /** Triggers a redraw process of the map. */
  public void redraw() {
    if (this.getWidth() <= 0 || this.getHeight() <= 0 || isZoomAnimatorRunning()) {
      return;
    }

    MapPosition mapPosition = this.mapViewPosition.getMapPosition();

    if (this.mapFile != null) {
      GeoPoint geoPoint = mapPosition.geoPoint;
      double pixelLeft =
          MercatorProjection.longitudeToPixelX(geoPoint.longitude, mapPosition.zoomLevel);
      double pixelTop =
          MercatorProjection.latitudeToPixelY(geoPoint.latitude, mapPosition.zoomLevel);
      pixelLeft -= getWidth() >> 1;
      pixelTop -= getHeight() >> 1;

      long tileLeft = MercatorProjection.pixelXToTileX(pixelLeft, mapPosition.zoomLevel);
      long tileTop = MercatorProjection.pixelYToTileY(pixelTop, mapPosition.zoomLevel);
      long tileRight =
          MercatorProjection.pixelXToTileX(pixelLeft + getWidth(), mapPosition.zoomLevel);
      long tileBottom =
          MercatorProjection.pixelYToTileY(pixelTop + getHeight(), mapPosition.zoomLevel);

      for (long tileY = tileTop; tileY <= tileBottom; ++tileY) {
        for (long tileX = tileLeft; tileX <= tileRight; ++tileX) {
          Tile tile = new Tile(tileX, tileY, mapPosition.zoomLevel);
          MapGeneratorJob mapGeneratorJob =
              new MapGeneratorJob(tile, this.mapFile, this.jobParameters, this.debugSettings);

          if (this.inMemoryTileCache.containsKey(mapGeneratorJob)) {
            Bitmap bitmap = this.inMemoryTileCache.get(mapGeneratorJob);
            this.frameBuffer.drawBitmap(mapGeneratorJob.tile, bitmap);
          } else if (this.fileSystemTileCache.containsKey(mapGeneratorJob)) {
            Bitmap bitmap = this.fileSystemTileCache.get(mapGeneratorJob);

            if (bitmap != null) {
              this.frameBuffer.drawBitmap(mapGeneratorJob.tile, bitmap);
              this.inMemoryTileCache.put(mapGeneratorJob, bitmap);
            } else {
              // the image data could not be read from the cache
              this.jobQueue.addJob(mapGeneratorJob);
            }
          } else {
            // cache miss
            this.jobQueue.addJob(mapGeneratorJob);
          }
        }
      }

      this.jobQueue.requestSchedule();
      synchronized (this.mapWorker) {
        this.mapWorker.notify();
      }
    }

    this.overlayController.redrawOverlays();

    if (this.mapScaleBar.isShowMapScaleBar()) {
      this.mapScaleBar.redrawScaleBar();
    }

    invalidateOnUiThread();
  }