-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example activity of creating MapView
- Loading branch information
Showing
7 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/mapbox/maps/testapp/examples/MapViewCustomizationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.mapbox.maps.testapp.examples | ||
|
||
import android.os.Bundle | ||
import android.widget.LinearLayout | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.mapbox.geojson.Point | ||
import com.mapbox.maps.* | ||
import com.mapbox.maps.testapp.R | ||
import kotlinx.android.synthetic.main.activity_map_view_customization.* | ||
|
||
/** | ||
* Example of customizing your [MapView]. | ||
* This example will show how to create [MapView] both programmatically and from xml | ||
* and apply various options. | ||
*/ | ||
class MapViewCustomizationActivity : AppCompatActivity() { | ||
|
||
private lateinit var customMapView: MapView | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_map_view_customization) | ||
configureMapViewFromXml() | ||
configureMapViewFromCode() | ||
} | ||
|
||
private fun configureMapViewFromCode() { | ||
val mapboxMapOptions = MapboxMapOptions(this).apply { | ||
// set initial camera position | ||
cameraOptions = CameraOptions.Builder() | ||
.center(Point.fromLngLat(-122.4194, 37.7749)) | ||
.zoom(9.0) | ||
.build() | ||
// use texture view renderer | ||
textureView = true | ||
// set other map options | ||
mapOptions = MapOptions.Builder() | ||
.constrainMode(ConstrainMode.HEIGHT_ONLY) | ||
.glyphsRasterizationOptions( | ||
GlyphsRasterizationOptions.Builder() | ||
.rasterizationMode(GlyphsRasterizationMode.IDEOGRAPHS_RASTERIZED_LOCALLY) | ||
.build() | ||
) | ||
.build() | ||
// set token and cache size for this particular map view | ||
resourceOptions = ResourceOptions.Builder() | ||
.accessToken(getString(R.string.mapbox_access_token)) | ||
.cacheSize(75_000L) | ||
.build() | ||
} | ||
// create view programmatically and add to root layout | ||
customMapView = MapView(this, mapboxMapOptions) | ||
val params = LinearLayout.LayoutParams( | ||
LinearLayout.LayoutParams.MATCH_PARENT, | ||
0, | ||
1.0f | ||
) | ||
root.addView(customMapView, params) | ||
// load style to map view | ||
customMapView.getMapboxMap().loadStyleUri(Style.SATELLITE) | ||
} | ||
|
||
private fun configureMapViewFromXml() { | ||
// let's set `custom` token to MapView from code (however it will be same token from resources so that map will work) | ||
MapboxOptions.setDefaultResourceOptions(this, getString(R.string.mapbox_access_token)) | ||
// all options provided in xml file - so we just load style | ||
mapView.getMapboxMap().loadStyleUri(Style.DARK) | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
mapView.onStart() | ||
customMapView.onStart() | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
mapView.onStop() | ||
customMapView.onStop() | ||
} | ||
|
||
override fun onLowMemory() { | ||
super.onLowMemory() | ||
mapView.onLowMemory() | ||
customMapView.onLowMemory() | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
mapView.onDestroy() | ||
customMapView.onDestroy() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/res/layout/activity_map_view_customization.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/root" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<com.mapbox.maps.MapView | ||
android:id="@+id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
app:mapbox_cameraTargetLat="52.52" | ||
app:mapbox_cameraTargetLng="13.4050" | ||
app:mapbox_cameraPitch="65" | ||
app:mapbox_cameraZoom="15" | ||
app:mapbox_mapOrientation="downwards" | ||
app:mapbox_mapSurface="surface_view" | ||
tools:context=".examples.SimpleMapActivity" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters