Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to have mbtiles outside of bundle dir #10

Open
firefountain opened this issue Sep 8, 2014 · 17 comments
Open

Ability to have mbtiles outside of bundle dir #10

firefountain opened this issue Sep 8, 2014 · 17 comments

Comments

@firefountain
Copy link

Right now.. I can't for the life of me figure out a way to get the sdk to read mbtiles that are not bundled with the app.

If we want to download a map after the app is compiled, its impossible to load it up..Everything get's downloaded to the Documents dir, outside the bundle.

Anyway to quickly change it?

@psyzz
Copy link

psyzz commented Oct 15, 2014

@firefountain did you find a way to achieve this ?

@firefountain
Copy link
Author

My priorities shifted to another issue. But a little bit of research showed that you can changed it on the source code in iOS.

Dig a bit. You need to chance a few things when you load the map. RMMBTilesSource

@adampax
Copy link
Owner

adampax commented Oct 15, 2014

Sorry haven't had any free time to spend on this due to work and personal obligations -- yes this should be possible with some changes with referencing the path in RMMBTilesSource. When I get a chance I will take a look.

@psyzz
Copy link

psyzz commented Nov 4, 2014

Ok, thanks guys i make some changes in RMMBTilesSource and ComPolancomediaMapboxView.m to do the thing. Now i'll try to add eventlistener 'click' on annotation popup

@firefountain
Copy link
Author

@arshavinho Care to share the code?

I can give you the event listener for the "click" on annotation. Already have that made!

@psyzz
Copy link

psyzz commented Nov 5, 2014

@firefountain yes, did you have make anothers features ?
I need to set image for annotations, i know @adampax already try this.
I also need eventlistener click on polygon.

I'm really not comfortable with objC so to have mbtiles outside of bundle dir, i don't produce an optimized code. I will post my code tomorow but the trick is to use - (id)initWithTileSetURL:(NSURL *)tileSetURL and set "map" with Ti.Filesystem.getFile(path_to_mbtiles).resolve()

var mapView = mapbox.createView({
        // map: '/maps/road-trip',
                map: Ti.Filesystem.getFile(path_to_mbtiles).resolve(),
                minZoom: 7,
        maxZoom: 12,
        zoom: 9,
        centerLatLng: [18.467354,-91.903534],
        width: Ti.UI.FILL,
        height: Ti.UI.FILL,
        debugTiles:true
    });

@maikkley
Copy link

@arshavinho Could you share your code? Thanks!

fyi:
I'll implement the ability to import a geoJSON Layer soon.

@adampax
Copy link
Owner

adampax commented Nov 10, 2014

All, sorry for being offline for a while, been busy moving to another country. I will hopefully have some more availability in the coming weeks to help with some of the new stuff people want implemented.

@psyzz
Copy link

psyzz commented Nov 10, 2014

Yes, i comment line 62 - 77 in ComPolancomediaMapboxView.m and add:

mapSource = [[RMMBTilesSource alloc] initWithTileSetURL:[NSURL fileURLWithPath:mapPath]];

You need to send the mbtiles file path with .resolve() :

var mapView = mapbox.createView({
        // map: '/maps/road-trip',
        map: Ti.Filesystem.getFile(path_to_mbtiles).resolve(),
        minZoom: 7,
        maxZoom: 12,
        zoom: 9,
        centerLatLng: [18.467354,-91.903534],
        width: Ti.UI.FILL,
        height: Ti.UI.FILL,
        debugTiles:true
    });

@psyzz
Copy link

psyzz commented Nov 10, 2014

@adampax i noticed that the memory used isn't release when we close the window, did you notice ?
I moved to Ti.Map and add MKTileOverlay for that

@firefountain
Copy link
Author

@arshavinho I'm going to open a new issue and drop my code there. Easier to control

#12

There you go!

@nitrag
Copy link

nitrag commented Mar 10, 2015

@adampax

You think you could proof and incorporate my code...I think I'm on the right track. I can't test as I can't figure out how to compile!

I want to still be able to use the resources directory (default) for testing but also need the ability to download maps OTA or via iTunes and use them.

Thanks!

line59:
        NSLog(@"[VIEW LIFECYCLE EVENT] addMap");

        NSString *mapPath = [TiUtils stringValue:[self.proxy valueForKey:@"map"]];
        id mapSource;

        //check absolute path
        NSString *mapInApplicationDataFolder = [[NSBundle mainBundle] pathForResource:
                          mapPath ofType:@".mbtiles" inDirectory:@"applicationDataDirectory"]; //is this right? or somehow use the fullly resolved path instead

        //check if file exists, otherwise try to add remote map
        NSString *mapInResourcesFolder = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[mapPath stringByAppendingString:@".mbtiles"]];

        BOOL fileExistsAppData = [[NSFileManager defaultManager] fileExistsAtPath:mapInApplicationDataFolder];
        NSLog(@"mapFile exists in AppData: %i", fileExistsAppData);

        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:mapInResourcesFolder];
        NSLog(@"mapFile exists in Resources (default): %i", fileExists);

        if( fileExistsAppData)
        {
            mapSource = [[RMMBTilesSource alloc] initWithTileSetURL:[NSURL fileURLWithPath:mapInApplicationDataFolder]];  //arshavinho credit  //mapInApplicationDataFolder generate proper URL?? or do we want to somehow use Ti.Filesystem.getFile(path_to_mbtiles).resolve()
        }
        else if(fileExists)
        {
            mapSource = [[RMMBTilesSource alloc] initWithTileSetResource:mapPath ofType:@"mbtiles"];

        } else
        {
            mapSource = [[RMMapBoxSource alloc] initWithMapID:mapPath];

        }

@maikkley
Copy link

@nitrag
Why you dont use Titanium Code for loading the mbtiles and use it with the mapbox module?

@nitrag
Copy link

nitrag commented Mar 10, 2015

I thought the resources directory was read-only? So a download would land
in ApplicationData which I could not get mapbox to see. Unless I'm missing
something?

Download mbtiles from internet to save for offline use. <--trying to
accomplish
On Mar 10, 2015 5:40 PM, "maikkley" [email protected] wrote:

@nitrag https://github.com/nitrag
Why you dont use Titanium Code for loading the mbtiles and use it with the
mapbox module?


Reply to this email directly or view it on GitHub
#10 (comment)
.

@maikkley
Copy link

Yes you are right, the resource dir is read only. But you can access application dir with the module.
Try so get file and the resolve method. This works for me :-)

@nitrag
Copy link

nitrag commented Mar 11, 2015

This still required the modification to ComPolancomediaMapboxView.m thought right?

I can't get the module to build for the life of me. Can anyone provide exact steps from cloning the git to building app? I'm probably missing some small detail. I would really like to contribute to this repo.

@nitrag
Copy link

nitrag commented Mar 11, 2015

OK I figured it out. Had to build with 3.4.1. Will attempt with 3.5.0 tomorrow and post my working code for both the AppData or Resources data file locations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants