MapBox GL Android:已下载但未使用自定义磁贴源的脱机地图
对于我们的应用程序,我目前正在将地图盒与自定义地图平铺表面集成(如上所述)。使用MapBox GL Android:已下载但未使用自定义磁贴源的脱机地图,android,mapbox,offline,mapbox-gl,mbtiles,Android,Mapbox,Offline,Mapbox Gl,Mbtiles,对于我们的应用程序,我目前正在将地图盒与自定义地图平铺表面集成(如上所述)。使用OfflineManager和OfflineTilePyramidRegionDefinition我可以下载互动程序并在mbgl-offline.db中找到它们,但它们似乎没有在应用程序中使用。离线区域报告已完成,但没有显示。据我所知,在下载tiles之后,其他一切都是“放手”的 我尝试了几种不同的来源(例如),因为我们仍在建立自己的地图平铺服务器 我是不是遗漏了什么?我真的很感激任何线索 最好的, 菲尔 更新: 以
OfflineManager
和OfflineTilePyramidRegionDefinition
我可以下载互动程序并在mbgl-offline.db中找到它们,但它们似乎没有在应用程序中使用。离线区域报告已完成,但没有显示。据我所知,在下载tiles之后,其他一切都是“放手”的
我尝试了几种不同的来源(例如),因为我们仍在建立自己的地图平铺服务器
我是不是遗漏了什么?我真的很感激任何线索
最好的,
菲尔
更新:
以下是更多信息:
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"/>
在下载地图数据时,日志基本上只是垃圾发送了大量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:FlusheventSqueueInstallent()已调用
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/时间线:时间线:活动\空闲id:
android.os。BinderProxy@41bd28b8时间:609768
W/MapboxEventManager:未连接到网络,因此空事件缓存
返回而不尝试发送事件
您能否提供有关该问题的更多信息,例如任何日志输出以及发生的行为与您预期的情况?请确保脱机下载和mapviews样式都使用相同的mapbox样式URL。谢谢您的评论-我用一些详细信息更新了答案。这些额外的信息有用吗?只是想再次与您联系:我用更多的信息更新了答案。这些附加信息有用吗?我想我也遇到了这个问题,将回顾整个项目,但我认为您需要确保在脱机区域下载相同的样式。谢谢检查!“mapView.getStyleUrl()”不应该确保下载了相同的样式,因为它已经被使用了吗?在布局XML中设置后,我不会更改地图样式。
// 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);
}
});