是否有一种方法可以加载文件夹中的多个矢量PBF文件,其方式与现在可以从在线源进行加载的方式类似?
我的应用程序处理几个MBTiles文件,但我更喜欢读取其中包含PBF的文件夹。因此,我可以仅使用一层加载所有地图,而不必删除前一层(绑定到一个MBTiles)并添加新的一层。
我可以通过添加绑定到HTTPTileDataSource
的层来从在线源加载PBF:
HTTPTileDataSource(
0,
14,
"https://www.my-server.com/tiles/v3/{z}/{x}/{y}.pbf?key=MY_API_KEY)
我想这样做,但要使用Android设备中的PBF。因此,有离线支持。显然,如上所述,我可以加载MBTiles文件,但是我的用例有几个文件,我想在地图之间进行透明,平滑和简单的转换。
我可以用某种方式写上面的URL来从设备中加载PBF吗?
谢谢!
更新
我忘了提一下,到目前为止,我一直没有尝试过。基本上,我使用约定来访问Android设备上的文件:
HTTPTileDataSource(
0,
14,
Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "/my-app/mbtiles/{z}/{x}/{y}.pbf")
这会引发如下错误:
2019-09-13 13:36:37.096 4432-4554/com.myapp.com.debug I/carto-mobile-sdk: HTTPTileDataSource::loadTile: Loading /storage/emulated/0/myapp/mbtiles/10/504/399.pbf
2019-09-13 13:36:37.096 4432-4554/com.myapp.com.debug E/carto-mobile-sdk: HTTPTileDataSource::loadTile: Exception while loading tile 10/504/399: Invalid URL: /storage/emulated/0/myapp/mbtiles/10/504/399.pbf
2019-09-13 13:36:37.096 4432-4554/com.myapp.com.debug I/carto-mobile-sdk: HTTPTileDataSource::loadTile: Loading /storage/emulated/0/myapp/mbtiles/10/503/399.pbf
2019-09-13 13:36:37.097 4432-4554/com.myapp.com.debug E/carto-mobile-sdk: HTTPTileDataSource::loadTile: Exception while loading tile 10/503/399: Invalid URL: /storage/emulated/0/myapp/mbtiles/10/503/399.pbf
但是,如果我尝试通过使用File
类并检查canRead()
方法来读取这些文件,则它们是可读的。所以他们在那里。
也许问题出在用于建立HTTP连接的库中,该库不接受内部文件吗?
使用类似的方法(使用“ file://”协议为URL加上前缀)会引发不同的错误。代码是:
return new HTTPTileDataSource(
0,
14,
"file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "myapp/mbtiles/{z}/{x}/{y}.pbf");
错误是:
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] JNI DETECTED ERROR IN APPLICATION: can't call void java.net.HttpURLConnection.setRequestMethod(java.lang.String) on instance of sun.net.www.protocol.file.FileURLConnection
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] in call to CallVoidMethodV
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] "Thread-51" prio=1 tid=37 Runnable
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] | group="main" sCount=0 dsCount=0 flags=0 obj=0x14500000 self=0x8a8ac800
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] | sysTid=5073 nice=19 cgrp=default sched=0/0 handle=0x8a782970
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] | state=R schedstat=( 61800737 288938844 285 ) utm=6 stm=0 core=2 HZ=100
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] | stack=0x8a688000-0x8a68a000 stackSize=1006KB
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] | held mutexes= "mutator lock"(shared held)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #00 pc 0047eae1 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, int, BacktraceMap*, char const*, art::ArtMethod*, void*)+209)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #01 pc 0057c193 /system/lib/libart.so (art::Thread::DumpStack(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+355)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #02 pc 00577693 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char>>&, bool, BacktraceMap*, bool) const+83)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #03 pc 00395256 /system/lib/libart.so (art::JavaVMExt::JniAbort(char const*, char const*)+1254)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #04 pc 003956c1 /system/lib/libart.so (art::JavaVMExt::JniAbortV(char const*, char const*, char*)+113)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #05 pc 0014f207 /system/lib/libart.so (art::ScopedCheck::AbortF(char const*, ...)+71)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #06 pc 00152ff5 /system/lib/libart.so (art::ScopedCheck::CheckMethodAndSig(art::ScopedObjectAccess&, _jobject*, _jclass*, _jmethodID*, art::Primitive::Type, art::InvokeType)+1941)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #07 pc 00151a3d /system/lib/libart.so (art::CheckJNI::CallMethodV(char const*, _JNIEnv*, _jobject*, _jclass*, _jmethodID*, char*, art::Primitive::Type, art::InvokeType)+973)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #08 pc 0013df2b /system/lib/libart.so (art::CheckJNI::CallVoidMethodV(_JNIEnv*, _jobject*, _jmethodID*, char*)+75)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #09 pc 00222680 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #10 pc 002e4b7a /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #11 pc 00123455 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #12 pc 00122bfa /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #13 pc 00076084 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #14 pc 0025d7fc /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #15 pc 001206e1 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #16 pc 00110bb3 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #17 pc 000412c7 /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #18 pc 00040e5f /data/app/com.myapp.debug-bfKnles_CQatK-qZx2DX7A==/lib/x86/libcarto_mobile_sdk.so (???)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #19 pc 00071445 /system/lib/libc.so (__pthread_start(void*)+53)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #20 pc 000205db /system/lib/libc.so (__start_thread+75)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] native: #21 pc 0001ec16 /system/lib/libc.so (__bionic_clone+70)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534] (no managed stack frames)
2019-09-13 13:41:33.782 4965-5073/com.myapp.debug A/zygote: java_vm_ext.cc:534]
答案 0 :(得分:0)
顾名思义,HTTPTileDataSource仅用于HTTP。 file://不是http,即使它是URL。您可能需要编写自定义数据源。我建议将票证发布到https://github.com/CartoDB/mobile-sdk/issues