Beispiel #1
0
  /**
   * Creates/Restore the layer switcher or restore the old one and add all other menu
   *
   * @param savedInstanceState
   * @param layerManager
   */
  private void setupLeftMenu(Bundle savedInstanceState, MultiSourceOverlayManager layerManager) {
    // work on fragment management
    FragmentManager fManager = getSupportFragmentManager();
    LayerSwitcherFragment osf;
    if (savedInstanceState != null) {
      osf = (LayerSwitcherFragment) fManager.findFragmentById(R.id.left_drawer_container);
      if (osf == null) {
        Log.e("MAPSACTIVITY", "unable to restore layer switcher");
      }
      layerManager.setLayerChangeListener(osf);
      layerManager.restoreInstanceState(savedInstanceState);

    } else {
      layerManager.defaultInit();
      //			@SuppressWarnings("unchecked")
      //			ArrayList<Layer> layers =  (ArrayList<Layer>) LocalPersistence.readObjectFromFile(this,
      // LocalPersistence.CURRENT_MAP);
      //			if(layers != null){
      //				layerManager.setLayers(layers);
      //			}else{

      if (getIntent() != null
          && getIntent().getExtras() != null
          && getIntent().getExtras().containsKey(MSM_MAP)) {

        layerManager.loadMap((MSMMap) getIntent().getExtras().getSerializable(MSM_MAP));

      } else {
        boolean dontLoadMBTileLayer =
            MapFilesProvider.getBackgroundSourceType() == BackgroundSourceType.MBTILES;
        MSMMap map = SpatialDbUtils.mapFromDb(dontLoadMBTileLayer);
        StorageUtils.setupSources(this);
        // This adds layers also if its called loadMap but it will not order layers
        // layerManager.loadMap(map);
        // so use this instead
        addLayersOrdered(map.layers);
      }

      //			}
      // setup left drawer fragments
      if (mDrawerMode != DrawerMode.NONE) {

        osf = new LayerSwitcherFragment();
        layerManager.setLayerChangeListener(osf);
        FragmentTransaction fragmentTransaction = fManager.beginTransaction();
        fragmentTransaction.add(R.id.left_drawer_container, osf);
        GenericMenuFragment other = new GenericMenuFragment();
        // fragmentTransaction.add(R.id.right_drawer, other);
        if (mDrawerMode == DrawerMode.BOTH) {

          SourcesFragment sf = new SourcesFragment();
          fragmentTransaction.add(R.id.right_drawer, sf);
        }
        fragmentTransaction.commit();
      }
    }
  }
Beispiel #2
0
 /**
  * @param layer
  * @param attributeName
  * @param id
  * @param attributeValue
  * @param marker
  * @param f
  */
 private void setMarkerProperties(
     String layer,
     String attributeName,
     String id,
     String attributeValue,
     DescribedMarker marker,
     Feature f) {
   GeoPoint p = SpatialDbUtils.getGeopointFromLayer(layer, attributeName, attributeValue);
   // get Only the first
   if (p != null) {
     // TODO ask if you want to change
     // if yes move and center map
     marker.setGeoPoint(p);
     marker.setFeatureId(id);
     marker.setFeature(f);
     mapView.redraw();
     canConfirm = true;
   } else {
     Toast.makeText(this, R.string.error_getting_data_from_database, Toast.LENGTH_LONG).show();
   }
 }
Beispiel #3
0
  /**
   * checks if the preferences of the background renderer changed if so, the mapview is informed and
   * is cleared and redrawed
   */
  public void checkIfMapViewNeedsBackgroundUpdate() {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean thingsChanged =
        prefs.getBoolean(MapView.MAPSFORGE_BACKGROUND_FILEPATH_CHANGED, false);
    if (!thingsChanged) return;

    final BackgroundSourceType currentMapRendererType = this.mapView.getMapRendererType();

    String filePath = prefs.getString(MapView.MAPSFORGE_BACKGROUND_FILEPATH, null);
    final String defaultType =
        getApplicationContext().getPackageName().equals("it.geosolutions.geocollect.android.app")
            ? "1"
            : "0";
    BackgroundSourceType type =
        BackgroundSourceType.values()[
            Integer.parseInt(
                prefs.getString(MapView.MAPSFORGE_BACKGROUND_RENDERER_TYPE, defaultType))];

    final Editor ed = prefs.edit();
    ed.putBoolean(MapView.MAPSFORGE_BACKGROUND_FILEPATH_CHANGED, false);
    ed.commit();

    File mapFile = new File(filePath);
    if (mapFile == null || !mapFile.exists()) {
      mapFile = MapFilesProvider.getBackgroundMapFile();
      filePath = mapFile.getPath();
      type = BackgroundSourceType.MAPSFORGE;
    }

    // 1. renderer changed
    if (type != currentMapRendererType) {

      MapRenderer mapRenderer = null;
      switch (type) {
        case MAPSFORGE:
          if (filePath == null) {
            throw new IllegalArgumentException(
                "no filepath selected to change to mapsforge renderer");
          }
          mapView.setMapFile(new File(filePath));
          mapRenderer = new DatabaseRenderer(mapView.getMapDatabase());
          // TODO it was MBTILES with no or dimmed mbtiles layer, add MBTiles layer ?

          MSMMap map = SpatialDbUtils.mapFromDb(false);
          Log.d(
              MapsActivity.class.getSimpleName(),
              "to mapsforge maps includes " + map.layers.size() + " layers");

          addLayersOrdered(map.layers);

          break;
        case MBTILES:
          mapRenderer = new MbTilesDatabaseRenderer(getBaseContext(), filePath);

          MSMMap map2 = SpatialDbUtils.mapFromDb(true);

          layerManager.setLayers(map2.layers);

          break;
        case GEOCOLLECT:
          // TODO
          break;
        default:
          break;
      }
      if (mDrawerToggle != null) {
        mDrawerToggle.syncState();
      }
      mapView.setRenderer(mapRenderer, true);
      mapView.clearAndRedrawMapView();
      MapFilesProvider.setBackgroundSourceType(type);

    } else if (filePath != null && !filePath.equals(mapView.getMapRenderer().getFileName())) {

      // 2.renderer is the same but file changed
      switch (type) {
        case MAPSFORGE:
          mapView.setMapFile(new File(filePath));
          break;
        case MBTILES:
          mapView.setRenderer(new MbTilesDatabaseRenderer(getBaseContext(), filePath), true);
          break;
        case GEOCOLLECT:
          // TODO
          break;
        default:
          break;
      }
      mapView.clearAndRedrawMapView();
    }
  }