对于我们的应用程序,我目前正在将地图框与自定义地图图块集成(如
here所述).使用OfflineManager和OfflineTilePyramidRegionDefinition,一切都运行正常,我可以下载磁贴并在mbgl-offline.db中找到它们,但它们似乎没有在应用中使用.据报道,离线区域已完成,但只是没有显示.据我了解
offline documentation,在下载瓷砖后,其他一切都是“放手”.
我已经尝试了几种不同的来源(例如,OpenMapTiles.org),因为我们仍然在设置我们自己的地图图块服务器.
我在这里错过了什么吗?我非常感谢任何线索.
最好,
菲尔
更新:
以下是一些更多信息:
XML布局
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"/>
下载地图数据的代码:
// 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,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);
}
});
在下载地图数据时,日志基本上只是垃圾邮件大量的HTTP 200s,所以一切看起来都很好.此外,脱机包报告完成,sqlite-db似乎也很好.
在离线模式下启动应用程序时,这基本上就是日志:
D/mbgl: [JNI]: nativeCreate
/com.mapbox.mapboxsdk.maps.MapView: MapView start Telemetry…
/MapboxEventManager: Telemetry initialize() called…
/MapboxEventManager: Mapbox Telemetry has already been initialized.
D/mbgl: [JNI]: nativeInitializeDisplay
D/mbgl: [JNI]: nativeInitializeContext
I/MapboxEventManager: flushEventsQueueImmediately() called…
D/MapboxEventManager: turnstile event pushed.
W/MapboxEventManager: Not connected to network,so empty events cache
and return without attempting to send events
I/com.mapbox.mapboxsdk.http.HTTPRequest: Request failed due to a
connection error: No Internet connection available.
D/mbgl: [JNI]: nativeViewResize
D/mbgl: [JNI]: nativeCreateSurface
D/mbgl: [JNI]: nativeFramebufferResize
I/TelemetryService: onStartCommand() called
D/mbgl: [JNI]: nativeViewResize
D/mbgl: [JNI]: nativeFramebufferResize
I/Timeline: Timeline: Activity_idle id:
android.os.BinderProxy@41bd28b8 time:609768
W/MapboxEventManager: Not connected to network,so empty events cache
and return without attempting to send events