2017-03-10 48 views
3

为我们的应用程序,我目前正在整合地图框自定义地图瓦片surce(如描述here)。一切运行良好与工作互联网连接,使用OfflineManagerOfflineTilePyramidRegionDefinition我可以下载瓷砖,并在mbgl-offline.db中找到它们,但它们似乎不在应用程序中使用。据报道,离线地区是完整的,但只是不显示。据我了解offline documentation,下载瓷砖后,其他一切都“手”。MapBox GL安卓:离线下载自定义图块源地图,但无法使用

我试过几个不同的来源(例如,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 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: [email protected] time:609768

W/MapboxEventManager: Not connected to network, so empty events cache and return without attempting to send events

+0

我觉得我有这个问题太,并会回头通过该项目,但我认为你需要确保你下载的是相同的风格在离线区域。 – dazza5000

+0

感谢您的检查!不应该'mapView.getStyleUrl()'已经确定,相同的样式已经下载了,因为它已经被使用了?在布局XML中设置它之后,我不更改地图样式。 –

回答

0

你能提供有关问题的详细信息,如任何日志输出,这是发生VS你所期望的行为?确保您使用的离线下载和mapviews风格都使用相同的地图箱样式的网址。

+0

感谢您的评论 - 我用更多的信息更新了答案。这些附加信息有帮助吗? –

+0

只需再次与您联系:我用更多信息更新了答案。这些附加信息有帮助吗? –

相关问题