[android] - load style without url or json

This commit is contained in:
tobrun
2019-05-23 18:52:33 +02:00
committed by Tobrun
parent 04309e01ce
commit 9cf1746e35
9 changed files with 103 additions and 7 deletions

View File

@@ -11,9 +11,6 @@ build/
*.so
*.apk
# Lib assets
MapboxGLAndroidSDK/src/main/assets/
# Local settings
local.properties
gradle/configuration.gradle

View File

@@ -5,8 +5,8 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
## master
### Bug fixes
- Fixed an issue where it was possible to set the map’s content insets then tilt the map enough to see the horizon, causing performance issues [#15195](https://github.com/mapbox/mapbox-gl-native/pull/15195)
- Fixed an issue where it was possible to set the map’s content insets then tilt the map enough to see the horizon, causing performance issues [#15195](https://github.com/mapbox/mapbox-gl-native/pull/15195)
- Allow loading of a map without a Style URI or Style JSON [#15293](https://github.com/mapbox/mapbox-gl-native/pull/15293)
## 8.0.2 - July 31, 2019
[Changes](https://github.com/mapbox/mapbox-gl-native/compare/android-v8.0.1...android-v8.0.2) since [Mapbox Maps SDK for Android v8.0.1](https://github.com/mapbox/mapbox-gl-native/releases/tag/android-v8.0.1):

View File

@@ -837,7 +837,7 @@ public final class MapboxMap {
nativeMapView.setStyleJson(builder.getJson());
} else {
// user didn't provide a `from` component, load a blank style instead
nativeMapView.setStyleJson("{}");
nativeMapView.setStyleJson(Style.EMPTY_JSON);
}
}

View File

@@ -37,6 +37,8 @@ import java.util.Map;
@SuppressWarnings("unchecked")
public class Style {
static final String EMPTY_JSON = "{\"version\": 8,\"sources\": {},\"layers\": []}";
private final NativeMap nativeMap;
private final HashMap<String, Source> sources = new HashMap<>();
private final HashMap<String, Layer> layers = new HashMap<>();

View File

@@ -48,7 +48,7 @@ class StyleTest {
fun testEmptyBuilder() {
val builder = Style.Builder()
mapboxMap.setStyle(builder)
verify(exactly = 1) { nativeMapView.styleJson = "{}" }
verify(exactly = 1) { nativeMapView.styleJson = Style.EMPTY_JSON }
}
@Test

View File

@@ -594,6 +594,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<activity
android:name=".activity.style.NoStyleActivity"
android:description="@string/description_no_style"
android:label="@string/activity_no_style">
<meta-data
android:name="@string/category"
android:value="@string/category_style" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activity.FeatureOverviewActivity" />
</activity>
<!-- Features -->
<activity
android:name=".activity.feature.QueryRenderedFeaturesPropertiesActivity"

View File

@@ -0,0 +1,84 @@
package com.mapbox.mapboxsdk.testapp.activity.style
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.support.v4.content.res.ResourcesCompat
import android.support.v7.app.AppCompatActivity
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.*
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
import com.mapbox.mapboxsdk.testapp.R
import java.net.URI
import kotlinx.android.synthetic.main.activity_map_simple.*
/**
* Activity showcasing how to load symbols on a map without a Style URI or Style JSON.
*/
class NoStyleActivity : AppCompatActivity() {
private val imageIcon: Drawable by lazy {
ResourcesCompat.getDrawable(resources, R.drawable.ic_add_white, theme)!!
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_map_simple)
mapView.getMapAsync { map ->
map.moveCamera(CameraUpdateFactory.newLatLngZoom(cameraTarget, cameraZoom))
map.setStyle(
Style.Builder()
.withImage(imageId, imageIcon)
.withSource(GeoJsonSource(sourceId, URI("asset://points-sf.geojson")))
.withLayer(SymbolLayer(layerId, sourceId).withProperties(iconImage(imageId)))
)
}
}
override fun onStart() {
super.onStart()
mapView.onStart()
}
override fun onResume() {
super.onResume()
mapView.onResume()
}
override fun onPause() {
super.onPause()
mapView.onPause()
}
override fun onStop() {
super.onStop()
mapView.onStop()
}
override fun onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}
override fun onDestroy() {
super.onDestroy()
mapView.onDestroy()
}
override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
outState?.let {
mapView.onSaveInstanceState(it)
}
}
companion object {
const val layerId = "custom-layer-id"
const val sourceId = "custom-source-id"
const val imageId = "image-id"
const val cameraZoom = 10.0
val cameraTarget = LatLng(37.758912, -122.442578)
}
}

View File

@@ -69,6 +69,7 @@
<string name="description_textureview_transparent">Enable a transparent surface on TextureView</string>
<string name="description_overlay">Blend an overlay on a map</string>
<string name="description_grid_source">Example Custom Geometry Source</string>
<string name="description_no_style">Load a map without providing a style URI or JSON</string>
<string name="description_local_glyph">Suzhou using Droid Sans for Chinese glyphs</string>
<string name="description_hillshade">Example raster-dem source and hillshade layer</string>
<string name="description_heatmaplayer">Use HeatmapLayer to visualise earthquakes</string>

View File

@@ -68,6 +68,7 @@
<string name="activity_textureview_transparent">TextureView transparent background</string>
<string name="activity_overlay">Map overlay</string>
<string name="activity_grid_source">Grid Source</string>
<string name="activity_no_style">No Style URI/JSON</string>
<string name="activity_local_glyph">Local CJK glyph generation</string>
<string name="activity_hillshade">Hillshade</string>
<string name="activity_heatmaplayer">Heatmap layer</string>