mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Prove that our mapbox sdk let us implement the map directly inside the activity
This commit is contained in:
parent
6d18ca0748
commit
7356044ad9
2 changed files with 114 additions and 2 deletions
|
|
@ -1,6 +1,96 @@
|
||||||
package fr.free.nrw.commons.nearby;
|
package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import fr.free.nrw.commons.theme.NavigationBaseActivity;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class NearbyTestActivity extends NavigationBaseActivity {
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||||
|
import com.mapbox.mapboxsdk.maps.Style;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The most basic example of adding a map to an activity.
|
||||||
|
*/
|
||||||
|
public class NearbyTestActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private MapView mapView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Mapbox access token is configured here. This needs to be called either in your application
|
||||||
|
// object or in the same activity which contains the mapview.
|
||||||
|
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));
|
||||||
|
|
||||||
|
|
||||||
|
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||||
|
setContentView(R.layout.activity_nearby_test);
|
||||||
|
|
||||||
|
mapView = findViewById(R.id.mapView);
|
||||||
|
mapView.onCreate(savedInstanceState);
|
||||||
|
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||||
|
@Override
|
||||||
|
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||||
|
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||||
|
@Override
|
||||||
|
public void onStyleLoaded(@NonNull Style style) {
|
||||||
|
Log.d("NearbyTestActivity","onStyleLoaded");
|
||||||
|
// Map is set up and the style has loaded. Now you can add data or make other map adjustments.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the mapView lifecycle to the activity's lifecycle methods
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
mapView.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
mapView.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
mapView.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
mapView.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLowMemory() {
|
||||||
|
super.onLowMemory();
|
||||||
|
mapView.onLowMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
mapView.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
mapView.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
app/src/main/res/layout/activity_nearby_test.xml
Normal file
22
app/src/main/res/layout/activity_nearby_test.xml
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.mapbox.mapboxsdk.maps.MapView
|
||||||
|
android:id="@+id/mapView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
mapbox:mapbox_cameraTargetLat="-36.84"
|
||||||
|
mapbox:mapbox_cameraTargetLng="174.76"
|
||||||
|
mapbox:mapbox_cameraZoom="10"
|
||||||
|
mapbox:mapbox_cameraBearing="34.33"
|
||||||
|
mapbox:mapbox_cameraTilt="50.25"
|
||||||
|
mapbox:mapbox_cameraZoomMax="12.41"
|
||||||
|
mapbox:mapbox_cameraZoomMin="6"
|
||||||
|
mapbox:mapbox_uiRotateGestures="false"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue