use of org.osmdroid.tileprovider.tilesource.MapBoxTileSource 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();
}
});
}
Aggregations