Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Expose setStyleJson from native class to MapboxMap and MapboxView - #4769

Closed
smartkiwi wants to merge 2 commits into
mapbox:masterfrom
smartkiwi:master
Closed

smartkiwi wants to merge 2 commits into
mapbox:masterfrom
smartkiwi:master

Conversation

@smartkiwi

Copy link
Copy Markdown

Here is the use case:
I need app the be able load style json from internal storage. So it could be updated periodically without publishing new version of functionality or publishing new style to mapbox studio (the phone might not have wireless connection during the day).
I've tried setStyleUrl - but it supports only http://. mapbox:// or assists//, but reject to load information from file://

E/mbgl: {Map}[Setup]: loading style failed: unexpected url: file:/storage/emulated/0/Download/test_aoi_style.json

@bleege

bleege commented Apr 20, 2016

Copy link
Copy Markdown
Contributor

@smartkiwi Thanks for the PR and the insight into what technically you're trying to accomplish. In this case we're reluctant to merge this into the project as we're currently working on a Runtime Styling API that would likely (as best we can tell) accomplish the same thing technically and don't want to introduce an additional API with a short self life. Can you tell us more about what the feature you're trying to build so that we can make sure that the Runtime Styling API will be able to meet those needs? Thanks!

@jfirebaugh

Copy link
Copy Markdown
Contributor

Refs #900, #1299, #1367, #1997 for previous discussions about setStyleJSON.

@smartkiwi

Copy link
Copy Markdown
Author

Thank you for reviewing and providing context.
Sounds like Runtime Styling API would help with my use case, any idea when will it be ready?
The end goal is to highlight some area on a map and update that area every day.
We've tried to use polygon loaded from geojson but we couldn't make it transparent and still visible.
We were able to accomplish need visual result by creating layer in style and setting transparency for it.
The application would run on a phones without permanent wireless connection - so we would want to be able load updated style from local storage.

Actually we don't need whole style to be updated - just polygon for one of the layers.

I was hoping that loading style from Json would solve the task at hand - build proof of content app to be used internally.

But unfortunately I have problem building and/or importing of my fork of the Mapbox SDK.

@vicapow

vicapow commented Apr 20, 2016

Copy link
Copy Markdown

Any guesses why the filesystem path to the style wouldn't work?

@smartkiwi

Copy link
Copy Markdown
Author

Here is the code I use to load style from URL on a local filesystem which produces the exception I've posted before

E/mbgl: {Map}[Setup]: loading style failed: unexpected url: file:/storage/emulated/0/Download/test_aoi_style.json

public void showAoiGeoJsonLayers() {
    if (mMap == null) {
        return;
    }
    File internalFile = new File(
            Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS
            ), "test_aoi_style.json"
    );
    Log.i(TAG, internalFile.toString());
    Log.i(TAG, "file exists: " + internalFile.exists());
    try {
        String internalFileUrl = internalFile.toURI().toURL().toString();
        Log.i(TAG, "URL: " + internalFileUrl);
        mMap.setStyleUrl(internalFileUrl);
    } catch (MalformedURLException e) {
        Log.e(TAG, e.getStackTrace().toString());
    }

}

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Apr 21, 2016
@bleege

bleege commented Apr 27, 2016

Copy link
Copy Markdown
Contributor

The forthcoming Style API is going to be the preferred solution for the SDK. Thank you though for the PR @smartkiwi.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants