gpt4 book ai didi

java - 显示 3D 地形 Mapbox v10 Android

转载 作者:行者123 更新时间:2023-12-04 23:42:08 41 4
gpt4 key购买 nike

我正在尝试将新的 map 框用于 android v10,特别是新的 3d 地形功能。所有示例都在 Kotlin 中,我遵循了下面的在线指南,但我一直遇到相同的错误消息。
在线示例:

mapboxMap.loadStyle(
styleExtension = style(Style.SATELLITE_STREETS) {
+rasterDemSource("TERRAIN_SOURCE") {
url("mapbox://mapbox.mapbox-terrain-dem-v1")
}
+terrain("TERRAIN_SOURCE") {
exaggeration(1.1)
}
)
以下是我正在使用的代码:
public class MainActivity extends AppCompatActivity {    
private MapView mapView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mapView = findViewById(R.id.mapView);
//mapView.getMapboxMap().loadStyleUri(Style.OUTDOORS);

MapboxMap mapboxMap = mapView.getMapboxMap();


StyleContract.StyleExtension styleExtension = new StyleContract.StyleExtension() {
@NonNull
@Override
public String getStyleUri() {
return Style.SATELLITE;
}

@NonNull
@Override
public List<StyleContract.StyleSourceExtension> getSources() {
RasterDemSource rasterDemSource = new RasterDemSource(new RasterDemSource.Builder("TERRAIN_SOURCE"));
rasterDemSource.url("mapbox://mapbox.mapbox-terrain-v2");

List<StyleContract.StyleSourceExtension> ex = new ArrayList<StyleContract.StyleSourceExtension>();
ex.add(rasterDemSource);

return ex;
}

@NonNull
@Override
public List<StyleContract.StyleImageExtension> getImages() {

return null;
}

@NonNull
@Override
public List<Pair<StyleContract.StyleLayerExtension, LayerPosition>> getLayers() {
return null;
}

@Nullable
@Override
public StyleContract.StyleLightExtension getLight() {
return null;
}

@Nullable
@Override
public StyleContract.StyleTerrainExtension getTerrain() {
Terrain terrain = new Terrain("TERRAIN_SOURCE");
terrain.exaggeration(1.1);

return null;
}
};

mapboxMap.loadStyle(styleExtension);
}
}
我不断收到以下错误代码:

2021-11-02 17:21:39.439 23646-23646/com.example.myapplicationW/System.err: java.lang.NullPointerException: Attempt to invokeinterface method 'java.util.Iterator java.lang.Iterable.iterator()' ona null object reference 2021-11-02 17:21:39.43923646-23646/com.example.myapplication W/System.err: atcom.mapbox.maps.MapboxMap.onFinishLoadingStyleExtension$sdk_release(MapboxMap.kt:1349)2021-11-02 17:21:39.439 23646-23646/com.example.myapplicationW/System.err: atcom.mapbox.maps.MapboxMap$loadStyle$1.onStyleLoaded(MapboxMap.kt:163)2021-11-02 17:21:39.439 23646-23646/com.example.myapplicationW/System.err: atcom.mapbox.maps.MapboxMap$initializeStyleLoad$1.onStyleLoaded(MapboxMap.kt:214)2021-11-02 17:21:39.439 23646-23646/com.example.myapplicationW/System.err: atcom.mapbox.maps.StyleObserver.onStyleLoaded(StyleObserver.kt:58)2021-11-02 17:21:39.439 23646-23646/com.example.myapplicationW/System.err: atcom.mapbox.maps.NativeObserver.notify(NativeObserver.kt:61) 2021-11-0217:21:39.439 23646-23646/com.example.myapplication W/System.err:
at android.os.MessageQueue.nativePollOnce(Native Method) 2021-11-0217:21:39.439 23646-23646/com.example.myapplication W/System.err:
at android.os.MessageQueue.next(MessageQueue.java:335) 2021-11-0217:21:39.440 23646-23646/com.example.myapplication W/System.err:
at android.os.Looper.loop(Looper.java:206) 2021-11-02 17:21:39.44023646-23646/com.example.myapplication W/System.err: atandroid.app.ActivityThread.main(ActivityThread.java:8633) 2021-11-0217:21:39.440 23646-23646/com.example.myapplication W/System.err:
at java.lang.reflect.Method.invoke(Native Method) 2021-11-0217:21:39.440 23646-23646/com.example.myapplication W/System.err:
atcom.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)2021-11-02 17:21:39.440 23646-23646/com.example.myapplicationW/System.err: atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)2021-11-02 17:21:39.446 23646-23646/com.example.myapplicationE/libc++abi: terminating with uncaught exception of typejni::PendingJavaException 2021-11-02 17:21:39.44723646-23646/com.example.myapplication A/libc: Fatal signal 6(SIGABRT), code -1 (SI_QUEUE) in tid 23646 (e.myapplication), pid23646 (e.myapplication)

最佳答案

原来我错误地使用了样式扩展,以下现在有效:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mapView = findViewById(R.id.mapView);
MapboxMap mapboxMap = mapView.getMapboxMap();

mapboxMap.loadStyle(createStyle());
}

private StyleContract.StyleExtension createStyle() {
StyleExtensionImpl.Builder builder = new StyleExtensionImpl.Builder(Style.SATELLITE);

RasterDemSource rasterDemSource = new RasterDemSource(new RasterDemSource.Builder("TERRAIN_SOURCE").tileSize(514));
rasterDemSource.url("mapbox://mapbox.mapbox-terrain-dem-v1");
builder.addSource(rasterDemSource);

Terrain terrain = new Terrain("TERRAIN_SOURCE");
terrain.exaggeration(1.1);
builder.setTerrain(terrain);

return builder.build();
}

关于java - 显示 3D 地形 Mapbox v10 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69805425/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com