Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - load style without url or json
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Aug 1, 2019
1 parent 04309e0 commit 9cf1746
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 7 deletions.
3 changes: 0 additions & 3 deletions platform/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ build/
*.so
*.apk

# Lib assets
MapboxGLAndroidSDK/src/main/assets/

# Local settings
local.properties
gradle/configuration.gradle
Expand Down
4 changes: 2 additions & 2 deletions platform/android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ public void setStyle(Style.Builder builder, final Style.OnStyleLoaded callback)
nativeMapView.setStyleJson(builder.getJson());
} else {
// user didn't provide a `from` component, load a blank style instead
nativeMapView.setStyleJson("{}");
nativeMapView.setStyleJson(Style.EMPTY_JSON);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
@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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 9cf1746

Please sign in to comment.