alx
alx

Reputation: 352

Android: How to update Skobbler map style

I am working with Skobbler SDK 2.3 and I am wondering how to update the map styles in SKMaps.zip.

The problem:

I modified the contained "daystyle", but I noticed that this only takes effect after deleting the app data. This is really not what I want. It looks like SKPrepareMapTextureThread(android.content.Context context, java.lang.String mapTexturesPath,java.lang.String zipName, SKPrepareMapTextureListener listener).start()
only copies the files if SKMaps folder doesn't exists. Does anybody know if there is such a check inside the start() method, or (better) how to deliver modified SKMap styles to the users?

Upvotes: 1

Views: 398

Answers (1)

Ando
Ando

Reputation: 11429

SKPrepareMapTextureThread only copies the files if SKMaps folder doesn't exists and this is how it is intended to be, as the unziping of the map resources takes a rather long time and is intended to be executed only once. To update a style a workaround will be required:

1) delete the file .installed.txt from map resources path and call SKPrepareMapTextureThread so that the resources will be restored from assets. Although this is the easiest way, it is also the most time consuming:

final File txtPreparedFile = new File(mapResourcesDirPath + "/.installed.txt"); 
        if (!txtPreparedFile.exists()) { 
            txtPreparedFile.delete(); 
        } 
new SKPrepareMapTextureThread(context, mapResourcesDirPath, "SKMaps.zip", skPrepareMapTextureListener).start(); 

2) a more optimal approach would be to write a routine that replace the old style with the new one

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

Upvotes: 1

Related Questions