/** * Create the markers and add them to the MarkerOverlay Gets it from the Intent or from the * savedInstanceState Assign them the proper <GeoPoint> if missing * * @param savedInstanceState */ private void createMarkers(Bundle savedInstanceState) { List<MarkerDTO> markerDTOs; // add the OverlayItem to the ArrayItemizedOverlay ArrayList<DescribedMarker> markers; if (savedInstanceState != null) { markerDTOs = savedInstanceState.getParcelableArrayList(PARAMETERS.MARKERS); markers = MarkerUtils.markerDTO2DescribedMarkers(this, markerDTOs); } else { markerDTOs = getIntent().getParcelableArrayListExtra(PARAMETERS.MARKERS); markers = MarkerUtils.markerDTO2DescribedMarkers(this, markerDTOs); // retrieve geopoint if missing if (getIntent().getExtras() == null) { return; } featureIdField = getIntent().getExtras().getString(PARAMETERS.FEATURE_ID_FIELD); if (featureIdField == null) { featureIdField = FEATURE_DEFAULT_ID; } if (!MarkerUtils.assignFeaturesFromDb(markers, featureIdField)) { Toast.makeText(this, R.string.error_unable_getfeature_db, Toast.LENGTH_LONG).show(); canConfirm = false; // TODO dialog : download features for this area? } } // create an ItemizedOverlay with the default marker overlayManager.getMarkerOverlay().getOverlayItems().addAll(markers); }
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); savedInstanceState.putBoolean(DB_LOADED_FLAG, dbLoaded); savedInstanceState.putString(FEATUREIDFIELD_FLAG, featureIdField); savedInstanceState.putBoolean(CANCONFRIM_FLAG, canConfirm); // MARKERS // get current markers overlayManager.saveInstanceState(savedInstanceState); for (MapControl mc : mapView.getControls()) { mc.saveState(savedInstanceState); } }
/** * get a marker from markerOverlay. The one highlighted or the first one * * @return */ private DescribedMarker getDefaultMarker() { MarkerOverlay m = mapView.getMarkerOverlay(); // add the marker overlay if not present if (m == null) { overlayManager.toggleOverlayVisibility(R.id.markers, true); m = mapView.getMarkerOverlay(); } DescribedMarker marker = m.getHighlighted(); if (marker == null) { List<DescribedMarker> markers = m.getMarkers(); if (markers.size() > 0) { marker = markers.get(0); } else { // TODO add a new marker } } return marker; }
/* (non-Javadoc) * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d(MapsActivity.class.getSimpleName(), "MapsActivity onActivityResult"); if (requestCode == LayerSwitcherFragment.OPACITY_SETTIN_REQUEST_ID) { final int newValue = PreferenceManager.getDefaultSharedPreferences(getBaseContext()) .getInt(MBTilesLayerOpacitySettingActivity.MBTILES_OPACITY_ID, 192); ArrayList<Layer> layers = layerManager.getLayers(); for (Layer l : layers) { if (l instanceof MbTilesLayer) { l.setOpacity(newValue); layerManager.redrawLayer(l); } } // its not necessary to handle the other stuff return; } if (requestCode == GetFeatureInfoLayerListActivity.BBOX_REQUEST && resultCode == RESULT_OK) { // the response can contain a feature to use to replace the current marker // on the map manageMarkerSubstitutionAction(data); } // controls can be refreshed getting the result of an intent, in this case // each control knows which intent he sent with their requestCode/resultCode for (MapControl control : mapView.getControls()) { control.refreshControl(requestCode, resultCode, data); } // reload stores in the panel (we do it everyTime, maybe there is a better way SourcesFragment sf = (SourcesFragment) getSupportFragmentManager().findFragmentById(R.id.right_drawer); if (sf != null) { sf.reloadStores(); } // manager mapstore configuration load // TODO: with the new interface this will load a map instead of the mapstoreconfig if (data == null) return; Bundle b = data.getExtras(); if (requestCode == DATAPROPERTIES_REQUEST_CODE) { mapView.getOverlayController().redrawOverlays(); // close right drawer if (mLayerMenu != null) { if (mDrawerLayout.isDrawerOpen(mLayerMenu)) { mDrawerLayout.closeDrawer(mLayerMenu); } } } Resource resource = (Resource) data.getSerializableExtra(GeoStoreResourceDetailActivity.PARAMS.RESOURCE); if (resource != null) { String geoStoreUrl = data.getStringExtra(GeoStoreResourcesActivity.PARAMS.GEOSTORE_URL); loadGeoStoreResource(resource, geoStoreUrl); } if (b.containsKey(MAPSTORE_CONFIG)) { overlayManager.loadMapStoreConfig((MapStoreConfiguration) b.getSerializable(MAPSTORE_CONFIG)); } if (b.containsKey(MSM_MAP)) { layerManager.loadMap((MSMMap) b.getSerializable(MSM_MAP)); } ArrayList<Layer> layersToAdd = (ArrayList<Layer>) b.getSerializable(LAYERS_TO_ADD); if (layersToAdd != null) { addLayers(layersToAdd); } }
/** Initialize Application and restores state */ @Override protected void onCreate(Bundle savedInstanceState) { // setup loading requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // getSupportActionBar(); // setSupportProgressBarIndeterminateVisibility(false); super.onCreate(savedInstanceState); if (getIntent() != null && getIntent().hasExtra(PARAMETERS.DRAWER_MODE)) { mDrawerMode = DrawerMode.values()[getIntent().getIntExtra(PARAMETERS.DRAWER_MODE, 0)]; switch (mDrawerMode) { case BOTH: setContentView(R.layout.main); break; case ONLY_LEFT: setContentView(R.layout.main_only_left_drawer); break; case NONE: setContentView(R.layout.main_no_drawers); break; } } else { mDrawerMode = DrawerMode.BOTH; // // LAYOUT INITIALIZATION // setContentView(R.layout.main); // Setup the left menu (Drawer) } // // MAP INITIALIZATION // // create overlay manager boolean mapLoaded = initMap(savedInstanceState); layerManager = new MultiSourceOverlayManager(mapView); overlayManager = layerManager; // setup slide menu(es) setupDrawerLayout(); dbLoaded = initDb(); // if something went wrong durind db and map initialization, // we should stop if (!mapLoaded && !dbLoaded) { // TODO: notify the user the problem Toast.makeText(this, "DB not loaded", Toast.LENGTH_LONG).show(); // TODO i18n } // // LEFT MENU INITIALIZATION // setupLeftMenu(savedInstanceState, layerManager); // CONTEXT MENU this.registerForContextMenu(mapView); mapView.getMapScaleBar().setShowMapScaleBar(true); // TODO preferences; overlayManager.setMarkerOverlay(new MarkerOverlay()); createMarkers(savedInstanceState); String action = getIntent().getAction(); if (Intent.ACTION_VIEW.equals(action)) { // prevent editing canConfirm = false; } else { // Default edit canConfirm = true; this.addConfirmButton(); } addControls(savedInstanceState); centerMapFile(); loadFromBundle(); }