This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - add binding integration for RasterDEMSource, add example
- Loading branch information
Showing
11 changed files
with
312 additions
and
3 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
.../MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java
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.mapboxsdk.style.sources; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.support.annotation.UiThread; | ||
|
||
import java.net.URL; | ||
|
||
/** | ||
* A raster DEM source. Currently only supports Mapbox Terrain RGB (mapbox://mapbox.terrain-rgb) | ||
* | ||
* @see <a href="https://www.mapbox.com/mapbox-gl-js/style-spec/#sources-raster-dem">The style specification</a> | ||
*/ | ||
@UiThread | ||
public class RasterDemSource extends Source { | ||
public static final int DEFAULT_TILE_SIZE = 512; | ||
|
||
/** | ||
* Internal use | ||
* | ||
* @param nativePtr - pointer to native peer | ||
*/ | ||
private RasterDemSource(long nativePtr) { | ||
super(nativePtr); | ||
} | ||
|
||
/** | ||
* Create the raster dem source from an URL | ||
* | ||
* @param id the source id | ||
* @param url the source url | ||
*/ | ||
public RasterDemSource(String id, URL url) { | ||
this(id, url.toExternalForm()); | ||
} | ||
|
||
/** | ||
* Create the raster dem source from an URL | ||
* | ||
* @param id the source id | ||
* @param url the source url | ||
*/ | ||
public RasterDemSource(String id, String url) { | ||
initialize(id, url, DEFAULT_TILE_SIZE); | ||
} | ||
|
||
/** | ||
* Create the raster source from an URL with a specific tile size | ||
* | ||
* @param id the source id | ||
* @param url the source url | ||
* @param tileSize the tile size | ||
*/ | ||
public RasterDemSource(String id, String url, int tileSize) { | ||
initialize(id, url, tileSize); | ||
} | ||
|
||
/** | ||
* Create the raster dem source from a {@link TileSet} | ||
* | ||
* @param id the source id | ||
* @param tileSet the {@link TileSet} | ||
*/ | ||
public RasterDemSource(String id, TileSet tileSet) { | ||
initialize(id, tileSet.toValueObject(), DEFAULT_TILE_SIZE); | ||
} | ||
|
||
/** | ||
* Create the raster source from a {@link TileSet} with a specific tile size | ||
* | ||
* @param id the source id | ||
* @param tileSet the {@link TileSet} | ||
* @param tileSize tje tile size | ||
*/ | ||
public RasterDemSource(String id, TileSet tileSet, int tileSize) { | ||
initialize(id, tileSet.toValueObject(), tileSize); | ||
} | ||
|
||
/** | ||
* @return The url or null | ||
*/ | ||
@Nullable | ||
public String getUrl() { | ||
return nativeGetUrl(); | ||
} | ||
|
||
protected native void initialize(String layerId, Object payload, int tileSize); | ||
|
||
@Override | ||
protected native void finalize() throws Throwable; | ||
|
||
protected native String nativeGetUrl(); | ||
|
||
} |
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
84 changes: 84 additions & 0 deletions
84
...App/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HillshadeLayerActivity.java
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,84 @@ | ||
package com.mapbox.mapboxsdk.testapp.activity.style; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.style.layers.HillshadeLayer; | ||
import com.mapbox.mapboxsdk.style.sources.RasterDemSource; | ||
import com.mapbox.mapboxsdk.testapp.R; | ||
|
||
/** | ||
* Test activity showcasing using HillshadeLayer. | ||
*/ | ||
public class HillshadeLayerActivity extends AppCompatActivity { | ||
|
||
private static final String LAYER_ID = "hillshade-layer"; | ||
private static final String LAYER_BELOW_ID = "waterway-river-canal"; | ||
private static final String SOURCE_ID = "hillshade-source"; | ||
private static final String SOURCE_URL = "mapbox://mapbox.terrain-rgb"; | ||
|
||
private MapView mapView; | ||
private MapboxMap mapboxMap; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_fill_extrusion_layer); | ||
|
||
mapView = (MapView) findViewById(R.id.mapView); | ||
mapView.onCreate(savedInstanceState); | ||
mapView.getMapAsync(map -> { | ||
mapboxMap = map; | ||
|
||
RasterDemSource rasterDemSource = new RasterDemSource(SOURCE_ID, SOURCE_URL); | ||
mapboxMap.addSource(rasterDemSource); | ||
|
||
HillshadeLayer hillshadeLayer = new HillshadeLayer(LAYER_ID, SOURCE_ID); | ||
mapboxMap.addLayerBelow(hillshadeLayer, LAYER_BELOW_ID); | ||
}); | ||
} | ||
|
||
@Override | ||
protected void onStart() { | ||
super.onStart(); | ||
mapView.onStart(); | ||
} | ||
|
||
@Override | ||
protected void onResume() { | ||
super.onResume(); | ||
mapView.onResume(); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
mapView.onPause(); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
mapView.onStop(); | ||
} | ||
|
||
@Override | ||
public void onSaveInstanceState(Bundle outState) { | ||
super.onSaveInstanceState(outState); | ||
mapView.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
mapView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
mapView.onDestroy(); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_hillshade_layer.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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<com.mapbox.mapboxsdk.maps.MapView | ||
android:id="@id/mapView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:mapbox_cameraTargetLat="52.090710" | ||
app:mapbox_cameraTargetLng="5.121125" | ||
app:mapbox_cameraZoom="10" | ||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/> | ||
|
||
</RelativeLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "raster_dem_source.hpp" | ||
|
||
#include "../android_conversion.hpp" | ||
#include "../value.hpp" | ||
#include "../conversion/url_or_tileset.hpp" | ||
#include "source.hpp" | ||
|
||
#include <mbgl/util/variant.hpp> | ||
|
||
#include <string> | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
RasterDEMSource::RasterDEMSource(jni::JNIEnv& env, jni::String sourceId, jni::Object<> urlOrTileSet, jni::jint tileSize) | ||
: Source( | ||
env, | ||
std::make_unique<mbgl::style::RasterDEMSource>( | ||
jni::Make<std::string>(env, sourceId), | ||
convertURLOrTileset(Value(env, urlOrTileSet)), | ||
tileSize | ||
) | ||
) { | ||
} | ||
|
||
RasterDEMSource::RasterDEMSource(jni::JNIEnv& env, | ||
mbgl::style::Source& coreSource, | ||
AndroidRendererFrontend& frontend) | ||
: Source(env, coreSource, createJavaPeer(env), frontend) { | ||
} | ||
|
||
RasterDEMSource::~RasterDEMSource() = default; | ||
|
||
jni::String RasterDEMSource::getURL(jni::JNIEnv& env) { | ||
optional<std::string> url = source.as<mbgl::style::RasterDEMSource>()->RasterDEMSource::getURL(); | ||
return url ? jni::Make<jni::String>(env, *url) : jni::String(); | ||
} | ||
|
||
jni::Class<RasterDEMSource> RasterDEMSource::javaClass; | ||
|
||
jni::Object<Source> RasterDEMSource::createJavaPeer(jni::JNIEnv& env) { | ||
static auto constructor = RasterDEMSource::javaClass.template GetConstructor<jni::jlong>(env); | ||
return jni::Object<Source>(RasterDEMSource::javaClass.New(env, constructor, reinterpret_cast<jni::jlong>(this)).Get()); | ||
} | ||
|
||
void RasterDEMSource::registerNative(jni::JNIEnv& env) { | ||
// Lookup the class | ||
RasterDEMSource::javaClass = *jni::Class<RasterDEMSource>::Find(env).NewGlobalRef(env).release(); | ||
|
||
#define METHOD(MethodPtr, name) jni::MakeNativePeerMethod<decltype(MethodPtr), (MethodPtr)>(name) | ||
|
||
// Register the peer | ||
jni::RegisterNativePeer<RasterDEMSource>( | ||
env, RasterDEMSource::javaClass, "nativePtr", | ||
std::make_unique<RasterDEMSource, JNIEnv&, jni::String, jni::Object<>, jni::jint>, | ||
"initialize", | ||
"finalize", | ||
METHOD(&RasterDEMSource::getURL, "nativeGetUrl") | ||
); | ||
} | ||
|
||
} // namespace android | ||
} // namespace mbgl |
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,33 @@ | ||
#pragma once | ||
|
||
#include "source.hpp" | ||
#include <mbgl/style/sources/raster_dem_source.hpp> | ||
#include <jni/jni.hpp> | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
class RasterDEMSource : public Source { | ||
public: | ||
|
||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/style/sources/RasterDemSource"; }; | ||
|
||
static jni::Class<RasterDEMSource> javaClass; | ||
|
||
static void registerNative(jni::JNIEnv&); | ||
|
||
RasterDEMSource(jni::JNIEnv&, jni::String, jni::Object<>, jni::jint); | ||
|
||
RasterDEMSource(jni::JNIEnv&, mbgl::style::Source&, AndroidRendererFrontend&); | ||
|
||
~RasterDEMSource(); | ||
|
||
jni::String getURL(jni::JNIEnv&); | ||
|
||
private: | ||
jni::Object<Source> createJavaPeer(jni::JNIEnv&); | ||
|
||
}; // class RasterDEMSource | ||
|
||
} // namespace android | ||
} // namespace mbgl |
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