Phi*_*ann 5 android offline mapbox mbtiles mapbox-gl
对于我们的应用程序,我目前正在将地图框与自定义地图图块表面集成(如此处所述)。使用有效的互联网连接,一切都运行良好,OfflineManager我OfflineTilePyramidRegionDefinition可以下载图块并在 mbgl-offline.db 中找到它们,但它们似乎未在应用程序中使用。据报告,离线区域已完成,但只是不显示。据我了解离线文档,下载图块后,其他一切都是“放手”。
我尝试了几个不同的来源(例如,OpenMapTiles.org),因为我们仍在建立自己的地图切片服务器的过程中。
我在这里错过了什么吗?我真的很感谢任何线索。
最好的,菲尔
更新: 这里有更多信息:
XML 布局
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:center_latitude="51"
mapbox:center_longitude="7"
mapbox:style_url="http://demo.tileserver.org/styles/klokantech-basic.json"
mapbox:zoom="1"/>
Run Code Online (Sandbox Code Playgroud)
下载地图数据的代码:
// Set up the OfflineManager
OfflineManager offlineManager = OfflineManager.getInstance(context);
// Create a bounding box for the offline region
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(6, 50))
.include(new LatLng(8, 52))
.build();
// Define the offline region
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
mapView.getStyleUrl(),
latLngBounds,
0,
9, // also tried other zoom levels
context.getResources().getDisplayMetrics().density);
// Set the metadata
byte[] metadata;
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put(JSON_FIELD_REGION_NAME, "Cologne");
String json = jsonObject.toString();
metadata = json.getBytes(JSON_CHARSET);
} catch (Exception exception) {
Log.e("Failed to encode metadata: " + exception.getMessage());
metadata = null;
}
// Create the region asynchronously
offlineManager.createOfflineRegion(
definition,
metadata,
new OfflineManager.CreateOfflineRegionCallback() {
@Override
public void onCreate(OfflineRegion offlineRegion) {
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
// Monitor the download progress using setObserver
offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() {
@Override
public void onStatusChanged(OfflineRegionStatus status) {
// Calculate the download percentage and update the progress bar
double percentage = status.getRequiredResourceCount() >= 0
? (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) :
0.0;
if (status.isComplete()) {
// Download complete
Log.d("Region downloaded successfully.");
ReadOSRMRouteTask readOSRMRouteTask = new ReadOSRMRouteTask();
readOSRMRouteTask.execute();
} else if (status.isRequiredResourceCountPrecise()) {
// Switch to determinate state
Log.d((int) Math.round(percentage) + "% downloaded");
}
}
@Override
public void onError(OfflineRegionError error) {
// If an error occurs, print to logcat
Log.e("onError reason: " + error.getReason());
Log.e("onError message: " + error.getMessage());
}
@Override
public void mapboxTileCountLimitExceeded(long limit) {
// Notify if offline region exceeds maximum tile count
Log.e("Mapbox tile count limit exceeded: " + limit);
}
});
}
@Override
public void onError(String error) {
Log.e("Error: " + error);
}
});
Run Code Online (Sandbox Code Playgroud)
下载地图数据时,日志基本上只是发送大量 HTTP 200,因此这方面一切看起来都很好。此外,离线包报告完整,sqlite-db 看起来也很好。
以离线模式启动应用程序时,日志基本上如下:
D/mbgl: [JNI]: nativeCreate
/com.mapbox.mapboxsdk.maps.MapView:MapView 启动遥测...
/MapboxEventManager:遥测初始化()调用...
/MapboxEventManager:Mapbox 遥测已初始化。
D/mbgl: [JNI]: nativeInitializeDisplay
D/mbgl: [JNI]: nativeInitializeContext
I/MapboxEventManager:flushEventsQueueImmediately() 调用...
D/MapboxEventManager:推送旋转栅门事件。
W/MapboxEventManager:未连接到网络,因此清空事件缓存并返回而不尝试发送事件
I/com.mapbox.mapboxsdk.http.HTTPRequest:由于连接错误,请求失败:没有可用的 Internet 连接。
D/mbgl: [JNI]: nativeViewResize
D/mbgl: [JNI]: nativeCreateSurface
D/mbgl: [JNI]: nativeFramebufferResize
I/TelemetryService:调用了 onStartCommand()
D/mbgl: [JNI]: nativeViewResize
D/mbgl: [JNI]: nativeFramebufferResize
I/时间线:时间线:Activity_idle id:android.os.BinderProxy@41bd28b8 时间:609768
W/MapboxEventManager:未连接到网络,因此清空事件缓存并返回而不尝试发送事件
| 归档时间: |
|
| 查看次数: |
1905 次 |
| 最近记录: |