java mapbox。更改映射类型时,getStyle()返回null
从样式更改mapStyle时,我对mapbox有问题。MAPBOX_街道的风格。卫星街(反之亦然)迅速排成一行。(其他样式也会出现这种情况,这些只是示例)
我的代码:
public void btnChangeMapType(View view) {
this.mapboxMap.getStyle(style -> {
String styleUri = this.mapboxMap.getStyle().getUri();
if (this.animator != null)
this.animator.cancel();
if (styleUri.equalsIgnoreCase(SATELLITE_STREETS)) {
changeMapType(Style.MAPBOX_STREETS, this.mapboxMap.getStyle());
} else {
changeMapType(Style.SATELLITE_STREETS, this.mapboxMap.getStyle());
}
});
}
private void changeMapType(String mapboxMapType, Style mapboxStyle) {
this.mapboxMap.setStyle(mapboxMapType, style -> {
if (this.previousLocation != null) {
this.positionGeoJson = new GeoJsonSource(MAP_LAYER_SOURCE_ID, Feature.fromGeometry(Point.fromLngLat(this.previousLocation.getLongitude(), this.previousLocation.getLatitude())));
} else {
this.positionGeoJson = getNewGeoJsonPosition();
}
if (this.hasFocus && this.animator != null) {
drawDrivenLine();
this.animator.start();
}
});
}
如果我点击一个按钮,多次快速调用btnChangeMapType,我会在字符串styleUri=this行上看到一个错误。mapboxMap。getStyle()。getUri()在btnChangeMapType()中
错误日志:
2020-02-20 11:31:50.828 14916-14916/at.myprojects.project E/Mbgl-MapChangeReceiver: Exception in onDidFinishLoadingStyle
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.mapbox.mapboxsdk.maps.Style.getUri()' on a null object reference
有没有办法防止我的应用程序崩溃/出现此错误
共 (0) 个答案