Пример #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 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);
  }
Пример #3
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;
  }