4

对于我们的应用程序,我目前正在将地图框与自定义地图瓦片源集成(如此处所述。一切运行良好,使用有效的互联网连接,OfflineManagerOfflineTilePyramidRegionDefinition可以下载磁贴并在 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"/>

下载地图数据的代码:

// 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);
            }
        });

在下载地图数据时,日志基本上只是发送了很多 HTTP 200 的垃圾邮件,所以在这方面一切似乎都很好。此外,离线包报告完整,sqlite-db 似乎也很好。

在离线模式下启动应用程序时,这基本上是日志:

D/mbgl: [JNI]: nativeCreate

/com.mapbox.mapboxsdk.maps.MapView: MapView 开始遥测...

/MapboxEventManager:遥测初始化()调用...

/MapboxEventManager: Mapbox Telemetry 已经被初始化。

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/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@41bd28b8 time:609768

W/MapboxEventManager:未连接到网络,因此空事件缓存并返回而不尝试发送事件

4

1 回答 1

0

您能否提供有关该问题的更多信息,例如任何日志输出以及正在发生的行为与您的预期之间的关系?确保您对离线下载和您的 mapviews 样式使用相同的 mapbox 样式 URL。

于 2017-03-10T22:30:09.610 回答