use of org.osmdroid.bonuspack.kml.KmlFeature in project osmbonuspack by MKergall.
the class MapActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch(requestCode) {
case FriendsManager.START_SHARING_REQUEST:
case FriendsManager.FRIENDS_REQUEST:
mFriendsManager.onActivityResult(requestCode, resultCode, intent);
break;
case ROUTE_REQUEST:
if (resultCode == RESULT_OK) {
int nodeId = intent.getIntExtra("NODE_ID", 0);
map.getController().setCenter(mRoads[mSelectedRoad].mNodes.get(nodeId).mLocation);
Marker roadMarker = (Marker) mRoadNodeMarkers.getItems().get(nodeId);
roadMarker.showInfoWindow();
}
break;
case POIS_REQUEST:
if (resultCode == RESULT_OK) {
int id = intent.getIntExtra("ID", 0);
map.getController().setCenter(mPOIs.get(id).mLocation);
Marker poiMarker = mPoiMarkers.getItem(id);
poiMarker.showInfoWindow();
}
break;
case KmlTreeActivity.KML_TREE_REQUEST:
mKmlStack.pop();
updateUIWithKml();
if (intent == null)
break;
KmlFeature selectedFeature = intent.getParcelableExtra("KML_FEATURE");
if (selectedFeature == null)
break;
BoundingBox bb = selectedFeature.getBoundingBox();
setViewOn(bb);
break;
case KmlStylesActivity.KML_STYLES_REQUEST:
updateUIWithKml();
break;
case PICK_KML_FILE:
if (intent != null) {
Uri uri = intent.getData();
openFile(uri.toString(), false, false);
}
break;
case SAVE_KML_FILE:
if (intent != null) {
Uri uri = intent.getData();
saveFile(uri);
}
break;
default:
break;
}
}
use of org.osmdroid.bonuspack.kml.KmlFeature in project osmbonuspack by MKergall.
the class MapActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this));
MapsForgeTileSource.createInstance(getApplication());
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.main, null);
setContentView(v);
SharedPreferences prefs = getSharedPreferences("OSMNAVIGATOR", MODE_PRIVATE);
MAPBOXSATELLITELABELLED = new MapBoxTileSource("MapBoxSatelliteLabelled", 1, 19, 256, ".png");
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveAccessToken(this);
((MapBoxTileSource) MAPBOXSATELLITELABELLED).retrieveMapBoxMapId(this);
TileSourceFactory.addTileSource(MAPBOXSATELLITELABELLED);
graphHopperApiKey = ManifestUtil.retrieveKey(this, "GRAPHHOPPER_API_KEY");
flickrApiKey = ManifestUtil.retrieveKey(this, "FLICKR_API_KEY");
geonamesAccount = ManifestUtil.retrieveKey(this, "GEONAMES_ACCOUNT");
mapzenApiKey = ManifestUtil.retrieveKey(this, "MAPZEN_APIKEY");
map = (MapView) v.findViewById(R.id.map);
String tileProviderName = prefs.getString("TILE_PROVIDER", "Mapnik");
mNightMode = prefs.getBoolean("NIGHT_MODE", false);
if ("rendertheme-v4".equals(tileProviderName)) {
setMapsForgeTileProvider();
} else {
try {
ITileSource tileSource = TileSourceFactory.getTileSource(tileProviderName);
map.setTileSource(tileSource);
} catch (IllegalArgumentException e) {
map.setTileSource(TileSourceFactory.MAPNIK);
}
}
if (mNightMode)
map.getOverlayManager().getTilesOverlay().setColorFilter(TilesOverlay.INVERT_COLORS);
map.setTilesScaledToDpi(true);
map.setMultiTouchControls(true);
map.setMinZoomLevel(1.0);
map.setMaxZoomLevel(21.0);
map.setVerticalMapRepetitionEnabled(false);
map.setScrollableAreaLimitLatitude(TileSystem.MaxLatitude, -TileSystem.MaxLatitude, 0);
// Toast.makeText(this, "H="+map.getHeight(), Toast.LENGTH_LONG).show();
IMapController mapController = map.getController();
// To use MapEventsReceiver methods, we add a MapEventsOverlay:
MapEventsOverlay overlay = new MapEventsOverlay(this);
map.getOverlays().add(overlay);
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
// mOrientation = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
// map prefs:
mapController.setZoom((double) prefs.getFloat("MAP_ZOOM_LEVEL_F", 5));
mapController.setCenter(new GeoPoint((double) prefs.getFloat("MAP_CENTER_LAT", 48.5f), (double) prefs.getFloat("MAP_CENTER_LON", 2.5f)));
myLocationOverlay = new DirectedLocationOverlay(this);
map.getOverlays().add(myLocationOverlay);
if (savedInstanceState == null) {
Location location = null;
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location == null)
location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
if (location != null) {
// location known:
onLocationChanged(location);
} else {
// no location known: hide myLocationOverlay
myLocationOverlay.setEnabled(false);
}
startPoint = null;
destinationPoint = null;
viaPoints = new ArrayList<GeoPoint>();
} else {
myLocationOverlay.setLocation((GeoPoint) savedInstanceState.getParcelable("location"));
// TODO: restore other aspects of myLocationOverlay...
startPoint = savedInstanceState.getParcelable("start");
destinationPoint = savedInstanceState.getParcelable("destination");
viaPoints = savedInstanceState.getParcelableArrayList("viapoints");
}
ScaleBarOverlay scaleBarOverlay = new ScaleBarOverlay(map);
map.getOverlays().add(scaleBarOverlay);
// Itinerary markers:
mItineraryMarkers = new FolderOverlay();
mItineraryMarkers.setName(getString(R.string.itinerary_markers_title));
map.getOverlays().add(mItineraryMarkers);
mViaPointInfoWindow = new ViaPointInfoWindow(R.layout.itinerary_bubble, map);
updateUIWithItineraryMarkers();
// Tracking system:
mTrackingModeButton = (Button) findViewById(R.id.buttonTrackingMode);
mTrackingModeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mTrackingMode = !mTrackingMode;
updateUIWithTrackingMode();
}
});
if (savedInstanceState != null) {
mTrackingMode = savedInstanceState.getBoolean("tracking_mode");
updateUIWithTrackingMode();
} else
mTrackingMode = false;
// TODO restore state
mIsRecordingTrack = false;
AutoCompleteOnPreferences departureText = (AutoCompleteOnPreferences) findViewById(R.id.editDeparture);
departureText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
Button searchDepButton = (Button) findViewById(R.id.buttonSearchDep);
searchDepButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
handleSearchButton(START_INDEX, R.id.editDeparture);
}
});
AutoCompleteOnPreferences destinationText = (AutoCompleteOnPreferences) findViewById(R.id.editDestination);
destinationText.setPrefKeys(SHARED_PREFS_APPKEY, PREF_LOCATIONS_KEY);
Button searchDestButton = (Button) findViewById(R.id.buttonSearchDest);
searchDestButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
handleSearchButton(DEST_INDEX, R.id.editDestination);
}
});
View expander = findViewById(R.id.expander);
expander.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
View searchPanel = findViewById(R.id.search_panel);
if (searchPanel.getVisibility() == View.VISIBLE) {
searchPanel.setVisibility(View.GONE);
} else {
searchPanel.setVisibility(View.VISIBLE);
}
}
});
View searchPanel = findViewById(R.id.search_panel);
searchPanel.setVisibility(prefs.getInt("PANEL_VISIBILITY", View.VISIBLE));
registerForContextMenu(searchDestButton);
// context menu for clicking on the map is registered on this button.
// (a little bit strange, but if we register it on mapView, it will catch map drag events)
// Route and Directions
mWhichRouteProvider = prefs.getInt("ROUTE_PROVIDER", OSRM);
mRoadNodeMarkers = new FolderOverlay();
mRoadNodeMarkers.setName("Route Steps");
map.getOverlays().add(mRoadNodeMarkers);
if (savedInstanceState != null) {
// STATIC mRoad = savedInstanceState.getParcelable("road");
updateUIWithRoads(mRoads);
}
// POIs:
// POI search interface:
String[] poiTags = getResources().getStringArray(R.array.poi_tags);
poiTagText = (AutoCompleteTextView) findViewById(R.id.poiTag);
ArrayAdapter<String> poiAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, poiTags);
poiTagText.setAdapter(poiAdapter);
Button setPOITagButton = (Button) findViewById(R.id.buttonSetPOITag);
setPOITagButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Hide the soft keyboard:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0);
// Start search:
String feature = poiTagText.getText().toString();
if (!feature.equals(""))
Toast.makeText(v.getContext(), "Searching:\n" + feature, Toast.LENGTH_LONG).show();
getPOIAsync(feature);
}
});
// POI markers:
mPoiMarkers = new RadiusMarkerClusterer(this);
Bitmap clusterIcon = BonusPackHelper.getBitmapFromVectorDrawable(this, R.drawable.marker_poi_cluster);
mPoiMarkers.setIcon(clusterIcon);
mPoiMarkers.mAnchorV = Marker.ANCHOR_BOTTOM;
mPoiMarkers.mTextAnchorU = 0.70f;
mPoiMarkers.mTextAnchorV = 0.27f;
mPoiMarkers.getTextPaint().setTextSize(12 * getResources().getDisplayMetrics().density);
map.getOverlays().add(mPoiMarkers);
if (savedInstanceState != null) {
// STATIC - mPOIs = savedInstanceState.getParcelableArrayList("poi");
updateUIWithPOI(mPOIs, "");
}
// KML handling:
mKmlOverlay = null;
if (savedInstanceState != null) {
// STATIC - mKmlDocument = savedInstanceState.getParcelable("kml");
updateUIWithKml();
} else {
// first launch:
mKmlDocument = new KmlDocument();
mKmlStack = new Stack<KmlFeature>();
mKmlClipboard = new KmlFolder();
// check if intent has been passed with a kml URI to load (url or file)
Intent onCreateIntent = getIntent();
if (onCreateIntent.getAction().equals(Intent.ACTION_VIEW)) {
String uri = onCreateIntent.getDataString();
openFile(uri, true, false);
}
}
// Sharing
mFriendsManager = new FriendsManager(this, map);
mFriendsManager.onCreate(savedInstanceState);
checkPermissions();
Button menuButton = (Button) findViewById(R.id.buttonMenu);
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openOptionsMenu();
}
});
}
use of org.osmdroid.bonuspack.kml.KmlFeature in project osmbonuspack by MKergall.
the class MapActivity method recordCurrentLocationInTrack.
void recordCurrentLocationInTrack(String trackId, String trackName, GeoPoint currentLocation) {
// Find the KML track in the current KML structure - and create it if necessary:
KmlTrack t;
KmlFeature f = mKmlDocument.mKmlRoot.findFeatureId(trackId, false);
if (f == null)
t = createTrack(trackId, trackName);
else if (!(f instanceof KmlPlacemark))
// id already defined but is not a PlaceMark
return;
else {
KmlPlacemark p = (KmlPlacemark) f;
if (!(p.mGeometry instanceof KmlTrack))
// id already defined but is not a Track
return;
else
t = (KmlTrack) p.mGeometry;
}
// TODO check if current location is really different from last point of the track
// record in the track the current location at current time:
t.add(currentLocation, new Date());
// refresh KML:
updateUIWithKml();
}
use of org.osmdroid.bonuspack.kml.KmlFeature in project osmbonuspack by MKergall.
the class KmlTreeActivity method onContextItemSelected.
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
KmlFolder currentKmlFolder = (KmlFolder) mCurrentKmlFeature;
switch(item.getItemId()) {
case // =move to the emptied clipboard
R.id.kml_item_menu_cut:
mKmlClipboard.mItems.clear();
mKmlClipboard.add(currentKmlFolder.mItems.get(info.position));
currentKmlFolder.removeItem(info.position);
mListAdapter.notifyDataSetChanged();
return true;
case R.id.kml_item_menu_copy:
KmlFeature copy = currentKmlFolder.mItems.get(info.position).clone();
mKmlClipboard.mItems.clear();
mKmlClipboard.mItems.add(copy);
return true;
case R.id.kml_item_menu_behind:
if (info.position > 0) {
KmlFeature kmlItem = currentKmlFolder.removeItem(info.position);
currentKmlFolder.mItems.add(info.position - 1, kmlItem);
mListAdapter.notifyDataSetChanged();
}
return true;
case R.id.kml_item_menu_front:
if (info.position < currentKmlFolder.mItems.size() - 1) {
KmlFeature kmlItem = currentKmlFolder.removeItem(info.position);
currentKmlFolder.mItems.add(info.position + 1, kmlItem);
mListAdapter.notifyDataSetChanged();
}
return true;
case R.id.kml_item_menu_show_on_map:
Intent intent = new Intent();
// TODO: is it the right way to pass a handle to an object?
intent.putExtra("KML_FEATURE", currentKmlFolder.mItems.get(info.position));
saveCurrentFeature();
setResult(RESULT_OK, intent);
finish();
return true;
default:
return super.onContextItemSelected(item);
}
}
use of org.osmdroid.bonuspack.kml.KmlFeature in project osmbonuspack by MKergall.
the class KmlListAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
KmlFeature item = (KmlFeature) getItem(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.kml_list_item, null);
}
TextView itemText = (TextView) convertView.findViewById(R.id.listItemTxt);
itemText.setText(item.mName);
// Handle checkbox:
/*
CheckBox checkBoxIsVisible = (CheckBox)convertView.findViewById(R.id.listItemCheckbox);
checkBoxIsVisible.setChecked(mRoot.mItems.get(position).mVisibility);
if (checkBoxIsVisible != null) {
checkBoxIsVisible.setOnClickListener(new OnClickListener(){
@Override public void onClick(View view) {
int position = (Integer)view.getTag();
KmlFeature item = mRoot.mItems.get(position);
item.mVisibility = ((CheckBox)view).isChecked();
}
});
checkBoxIsVisible.setTag(position);
}
*/
ImageView img = (ImageView) convertView.findViewById(R.id.listItemImg);
if (item instanceof KmlFolder) {
img.setImageResource(R.drawable.moreinfo_arrow);
} else if (item instanceof KmlPlacemark) {
KmlGeometry geometry = ((KmlPlacemark) item).mGeometry;
if (geometry instanceof KmlPoint)
img.setImageResource(R.drawable.marker_kml_point);
else if (geometry instanceof KmlLineString)
img.setImageResource(R.drawable.kml_icon_linestring);
else if (geometry instanceof KmlPolygon)
img.setImageResource(R.drawable.kml_icon_polygon);
else if (geometry instanceof KmlMultiGeometry)
img.setImageResource(R.drawable.kml_icon_multigeometry);
else if (geometry instanceof KmlTrack)
img.setImageResource(R.drawable.kml_icon_gxtrack);
else
img.setImageDrawable(null);
} else if (item instanceof KmlGroundOverlay) {
img.setImageResource(R.drawable.kml_icon_groundoverlay);
} else
img.setImageDrawable(null);
return convertView;
}
Aggregations