Android:如何更新Skobbler地图样式
Android: How to update Skobbler map style
我正在使用 Skobbler SDK 2.3,我想知道如何更新 SKMaps.zip 中的地图样式。
问题:
我修改了包含的"daystyle",但我注意到这只有在删除应用程序数据后才会生效。这真的不是我想要的。看起来像 SKPrepareMapTextureThread(android.content.Context context, java.lang.String mapTexturesPath,java.lang.String zipName, SKPrepareMapTextureListener listener).start()
仅当 SKMaps 文件夹不存在时才复制文件。有人知道 start() 方法中是否有这样的检查,或者(更好)如何向用户提供修改后的 SKMap 样式吗?
SKPrepareMapTextureThread 仅在 SKMaps 文件夹不存在时复制文件,这就是它的预期方式,因为地图资源的解压缩需要相当长的时间并且只执行一次。
要更新样式,需要解决方法:
1) 从地图资源路径中删除文件 .installed.txt 并调用 SKPrepareMapTextureThread 以便从资产中恢复资源。虽然这是最简单的方法,但也是最耗时的:
final File txtPreparedFile = new File(mapResourcesDirPath + "/.installed.txt");
if (!txtPreparedFile.exists()) {
txtPreparedFile.delete();
}
new SKPrepareMapTextureThread(context, mapResourcesDirPath, "SKMaps.zip", skPrepareMapTextureListener).start();
2) 更优化的方法是编写一个用新样式替换旧样式的例程
copyFile(new File("path/daystyle.json"), new File("mapResourcesDirPath/SKMaps/daystyle/daystyle.json"));
...
public static void copyFile(File sourceFile, File destFile) throws IOException {
if(!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
// previous code: destination.transferFrom(source, 0, source.size());
// to avoid infinite loops, should be:
long count = 0;
long size = source.size();
while((count += destination.transferFrom(source, count, size-count))<size);
}
finally {
if(source != null) {
source.close();
}
if(destination != null) {
destination.close();
}
}
}
我正在使用 Skobbler SDK 2.3,我想知道如何更新 SKMaps.zip 中的地图样式。
问题:
我修改了包含的"daystyle",但我注意到这只有在删除应用程序数据后才会生效。这真的不是我想要的。看起来像 SKPrepareMapTextureThread(android.content.Context context, java.lang.String mapTexturesPath,java.lang.String zipName, SKPrepareMapTextureListener listener).start()
仅当 SKMaps 文件夹不存在时才复制文件。有人知道 start() 方法中是否有这样的检查,或者(更好)如何向用户提供修改后的 SKMap 样式吗?
SKPrepareMapTextureThread 仅在 SKMaps 文件夹不存在时复制文件,这就是它的预期方式,因为地图资源的解压缩需要相当长的时间并且只执行一次。 要更新样式,需要解决方法:
1) 从地图资源路径中删除文件 .installed.txt 并调用 SKPrepareMapTextureThread 以便从资产中恢复资源。虽然这是最简单的方法,但也是最耗时的:
final File txtPreparedFile = new File(mapResourcesDirPath + "/.installed.txt");
if (!txtPreparedFile.exists()) {
txtPreparedFile.delete();
}
new SKPrepareMapTextureThread(context, mapResourcesDirPath, "SKMaps.zip", skPrepareMapTextureListener).start();
2) 更优化的方法是编写一个用新样式替换旧样式的例程
copyFile(new File("path/daystyle.json"), new File("mapResourcesDirPath/SKMaps/daystyle/daystyle.json"));
...
public static void copyFile(File sourceFile, File destFile) throws IOException {
if(!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
// previous code: destination.transferFrom(source, 0, source.size());
// to avoid infinite loops, should be:
long count = 0;
long size = source.size();
while((count += destination.transferFrom(source, count, size-count))<size);
}
finally {
if(source != null) {
source.close();
}
if(destination != null) {
destination.close();
}
}
}