コード例 #1
0
  /** Wrapper for the OpenStreetMap view. */
  public OpenStreetMapWrapper(final Context context) {
    this.context = context;
    this.markerManager = new OpenStreetMapMarkerManager(this);
    this.overlayItemToMarker = Maps.newHashMap();

    // Create a custom tile source
    final ITileSource seamarks =
        new XYTileSource(
            "seamarks",
            null,
            0,
            19,
            256,
            ".png",
            new String[] {"http://tiles.openseamap.org/seamark/"});
    final MapTileProviderBasic tileProvider = new MapTileProviderBasic(context, seamarks);
    final TilesOverlay seamarksOverlay = new TilesOverlay(tileProvider, context);
    seamarksOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
    seamarksOverlay.setUseSafeCanvas(true);

    // Create the mapview with the custom tile provider array
    this.mapView = new MapView(context, 256);
    this.mapView.setMultiTouchControls(true);
    this.mapView.setUseSafeCanvas(false);
    this.mapView.getOverlays().add(seamarksOverlay);

    CloudmadeUtil.retrieveCloudmadeKey(context);
  }
コード例 #2
0
  public boolean onPrepareOptionsMenu(
      final Menu pMenu, final int menuIdOffset, final MapView mapView) {
    for (final Overlay overlay : this.overlaysReversed()) {
      if (overlay instanceof IOverlayMenuProvider) {
        final IOverlayMenuProvider overlayMenuProvider = (IOverlayMenuProvider) overlay;
        if (overlayMenuProvider.isOptionsMenuEnabled()) {
          overlayMenuProvider.onPrepareOptionsMenu(pMenu, menuIdOffset, mapView);
        }
      }
    }

    if (mTilesOverlay != null && mTilesOverlay.isOptionsMenuEnabled()) {
      mTilesOverlay.onPrepareOptionsMenu(pMenu, menuIdOffset, mapView);
    }

    return true;
  }
コード例 #3
0
 public void setUseSafeCanvas(boolean useSafeCanvas) {
   mUseSafeCanvas = useSafeCanvas;
   for (Overlay overlay : mOverlayList)
     if (overlay instanceof SafeDrawOverlay)
       ((SafeDrawOverlay) overlay).setUseSafeCanvas(this.isUsingSafeCanvas());
   if (mTilesOverlay != null) {
     mTilesOverlay.setUseSafeCanvas(this.isUsingSafeCanvas());
   }
 }
コード例 #4
0
  public void onDetach(final MapView pMapView) {
    if (mTilesOverlay != null) {
      mTilesOverlay.onDetach(pMapView);
    }

    for (final Overlay overlay : this.overlaysReversed()) {
      overlay.onDetach(pMapView);
    }
  }
コード例 #5
0
  public boolean onOptionsItemSelected(
      final MenuItem item, final int menuIdOffset, final MapView mapView) {
    for (final Overlay overlay : this.overlaysReversed()) {
      if (overlay instanceof IOverlayMenuProvider) {
        final IOverlayMenuProvider overlayMenuProvider = (IOverlayMenuProvider) overlay;
        if (overlayMenuProvider.isOptionsMenuEnabled()
            && overlayMenuProvider.onOptionsItemSelected(item, menuIdOffset, mapView)) {
          return true;
        }
      }
    }

    if (mTilesOverlay != null
        && mTilesOverlay.isOptionsMenuEnabled()
        && mTilesOverlay.onOptionsItemSelected(item, menuIdOffset, mapView)) {
      return true;
    }

    return false;
  }
コード例 #6
0
  public void onDraw(final Canvas c, final MapView pMapView) {
    if (mTilesOverlay != null
        && mTilesOverlay.isEnabled()
        && mTilesOverlay.isDrawingShadowLayer()) {
      mTilesOverlay.onDraw(c, pMapView, true);
    }

    if (mTilesOverlay != null && mTilesOverlay.isEnabled()) {
      mTilesOverlay.onDraw(c, pMapView, false);
    }

    for (final Overlay overlay : mOverlayList) {
      if (overlay.isEnabled() && overlay.isDrawingShadowLayer()) {
        overlay.onDraw(c, pMapView, true);
      }
    }

    for (final Overlay overlay : mOverlayList) {
      if (overlay.isEnabled()) {
        overlay.onDraw(c, pMapView, false);
      }
    }
  }
コード例 #7
0
  public void setOfflineMap(String mapname) throws FileNotFoundException {
    mFile = new File(Environment.getExternalStorageDirectory(), "/" + mapname);

    if (!mFile.exists()) {
      throw new FileNotFoundException();
    }

    MapTileModuleProviderBase treasureMapModuleProvider =
        new MapTileFileArchiveProvider(
            new SimpleRegisterReceiver(mContext),
            mTreasureMapTileSource,
            new IArchiveFile[] {MBTilesFileArchive.getDatabaseFileArchive(mFile)});

    MapTileProviderBase treasureMapProvider =
        new MapTileProviderArray(
            mTreasureMapTileSource,
            null,
            new MapTileModuleProviderBase[] {treasureMapModuleProvider});

    TilesOverlay treasureMapTilesOverlay = new TilesOverlay(treasureMapProvider, mContext);
    treasureMapTilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

    mMap.getOverlays().add(treasureMapTilesOverlay);
  }
コード例 #8
0
 /**
  * Sets the optional TilesOverlay class. If set, this overlay will be drawn before all other
  * overlays and will not be included in the editable list of overlays and can't be cleared except
  * by a subsequent call to setTilesOverlay().
  *
  * @param tilesOverlay the tilesOverlay to set
  */
 public void setTilesOverlay(final TilesOverlay tilesOverlay) {
   mTilesOverlay = tilesOverlay;
   if (mTilesOverlay != null) {
     mTilesOverlay.setUseSafeCanvas(this.isUsingSafeCanvas());
   }
 }
コード例 #9
0
  @Override
  protected void draw(final Canvas pC, final MapView pOsmv, final boolean shadow) {

    if (shadow) {
      return;
    }

    // Don't draw if we are animating
    if (pOsmv.isAnimating()) {
      return;
    }

    // Calculate the half-world size
    final Projection projection = pOsmv.getProjection();
    final int zoomLevel = projection.getZoomLevel();
    mWorldSize_2 = TileSystem.MapSize(zoomLevel) / 2;

    // Save the Mercator coordinates of what is on the screen
    mViewportRect.set(projection.getScreenRect());
    mViewportRect.offset(mWorldSize_2, mWorldSize_2);

    // Start calculating the tile area with the current viewport
    mTileArea.set(mViewportRect);

    // Get the target zoom level difference.
    int miniMapZoomLevelDifference = getZoomDifference();

    // Make sure the zoom level difference isn't below the minimum zoom level
    if (zoomLevel - getZoomDifference() < mTileProvider.getMinimumZoomLevel()) {
      miniMapZoomLevelDifference +=
          zoomLevel - getZoomDifference() - mTileProvider.getMinimumZoomLevel();
    }

    // Shift the screen coordinates into the target zoom level
    mTileArea.set(
        mTileArea.left >> miniMapZoomLevelDifference,
        mTileArea.top >> miniMapZoomLevelDifference,
        mTileArea.right >> miniMapZoomLevelDifference,
        mTileArea.bottom >> miniMapZoomLevelDifference);

    // Limit the area we are interested in for tiles to be the MAP_WIDTH by MAP_HEIGHT and
    // centered on the center of the screen
    mTileArea.set(
        mTileArea.centerX() - (getWidth() / 2),
        mTileArea.centerY() - (getHeight() / 2),
        mTileArea.centerX() + (getWidth() / 2),
        mTileArea.centerY() + (getHeight() / 2));

    // Get the area where we will draw the minimap in screen coordinates
    mMiniMapCanvasRect.set(
        mViewportRect.right - getPadding() - getWidth(),
        mViewportRect.bottom - getPadding() - getHeight(),
        mViewportRect.right - getPadding(),
        mViewportRect.bottom - getPadding());
    mMiniMapCanvasRect.offset(-mWorldSize_2, -mWorldSize_2);

    // Draw a solid background where the minimap will be drawn with a 2 pixel inset
    pC.drawRect(
        mMiniMapCanvasRect.left - 2,
        mMiniMapCanvasRect.top - 2,
        mMiniMapCanvasRect.right + 2,
        mMiniMapCanvasRect.bottom + 2,
        mPaint);

    super.drawTiles(
        pC,
        projection.getZoomLevel() - miniMapZoomLevelDifference,
        TileSystem.getTileSize(),
        mTileArea);
  }
コード例 #10
0
  private MapView setupMapView() {
    final MapView mapView;

    if (mLayersSettings == null) {
      mapView = setupDefaultMapView();

      Toast.makeText(
              getContext(), getString(R.string.toast_no_layers_settings_found), Toast.LENGTH_LONG)
          .show();
    } else {
      final MapTileModuleProviderBase baseModuleProvider =
          getMBTilesProvider(mLayersSettings.layersSource.base);

      if (baseModuleProvider == null) {
        // failed to load the MBTiles as file, use the default configuration
        mapView = setupDefaultMapView();

        Toast.makeText(
                getContext(), getString(R.string.toast_mbtiles_load_failed), Toast.LENGTH_LONG)
            .show();
      } else {
        updateTitle(mLayersSettings.name);

        final MBTilesProvider baseProviders =
            MBTilesProvider.createFromProviders(getTileSize(), baseModuleProvider);

        mapView =
            new MapView(
                getContext(),
                getTileSize(),
                new DefaultResourceProxyImpl(getContext().getApplicationContext()),
                baseProviders);

        mapView.setScrollableAreaLimit(mLayersSettings.boundingBoxE6);
        mapView.setMaxZoomLevel(
            baseProviders.getMaximumZoomLevel()
                - getResources().getInteger(R.integer.last_zoom_offset));

        final List<MapTileModuleProviderBase> levelModuleProviders =
            loadLevelModuleProviders(mLayersSettings.layersSource);

        if (!levelModuleProviders.isEmpty()) {
          final MBTilesProvider levelProviders =
              MBTilesProvider.createFromProviders(
                  getTileSize(),
                  levelModuleProviders.toArray(
                      new MapTileModuleProviderBase[levelModuleProviders.size()]));
          levelProviders.setSelectedIndoorLevel(mIndoorLevel);

          final TilesOverlay tilesOverlay = new TilesOverlay(levelProviders, getContext());
          tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
          mapView.getOverlays().add(tilesOverlay);

          final LevelsFilterNavigationListView levelsFilterNavigationListView =
              new LevelsFilterNavigationListView(
                  ((AppCompatActivity) getActivity()).getSupportActionBar());
          levelsFilterNavigationListView.setDefaultLevel(mIndoorLevel);

          final List<Double> levels = new ArrayList<>();

          for (MapTileModuleProviderBase levelModuleProvider : levelModuleProviders) {
            if (levelModuleProvider instanceof MBTilesModuleProvider) {
              levels.add(((MBTilesModuleProvider) levelModuleProvider).getIndoorLevel());
            }
          }

          levelsFilterNavigationListView.setLevels(levels);
          levelsFilterNavigationListView.setLevelsFilterViewCallback(
              new LevelsFilterNavigationListView.LevelsFilterViewCallback() {
                @Override
                public void onLevelSelected(double level) {
                  mIndoorLevel = level;

                  levelProviders.setSelectedIndoorLevel(level);
                  mapView.invalidate();
                  mapView.getController().animateTo(mMapView.getMapCenter());
                }
              });
        }
      }
    }

    configureMapView(mapView);

    return mapView;
  }