MapBox SDK - [ParseStyle]: Failed to parse style: 0 - Invalid value.

I have implemented a owned map server from OpenMapTiles Map Server

My intention is to use the MapBox SDK with the maps of my server.

Open Map Tile Server

Apply the "Dark Matter" style using the following TileJSON 2.0 specification:

enter image description here

By using the setStyleJson method of MapBox I set this origin:

setContentView(R.layout.activity_main);
        Mapbox.getInstance(this, "access_token");
        setContentView(R.layout.activity_main);
        mapView = (MapView) findViewById(R.id.mapView);
        mapView.onCreate(savedInstanceState);

        mapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(MapboxMap mapboxMap) {
                mapboxMap.setStyleJson("http://192.168.1.65:8080/styles/dark-matter.json");
                mapboxMap.setCameraPosition(new CameraPosition.Builder()
                        .target(new LatLng(47.3769, 8.5417))
                        .zoom(25)
                        .build());
            }
        });

The map remains blank, and through the logcat I can see the following error message:

05-17 12:38:18.489 19008-19008/sergio.sanchez.sanchez.demomapbox E/mbgl: {chez.demomapbox}[ParseStyle]: Failed to parse style: 0 - Invalid value.

Can someone tell me what I'm doing wrong?

Thank you.

Upvotes: 1

Views: 1708

Answers (1)

Mohammad Banisaeid
Mohammad Banisaeid

Reputation: 2626

mapboxMap.setStyleJson method expects the actual JSON string, not a URL. In order to pass a URL, use mapbox map's setStyleUrl method or map view's setStyleUrl method:

mapView.setStyleUrl("http://192.168.1.65:8080/styles/dark-matter.json");
mapView.onCreate(savedInstanceState);

Upvotes: 1

Related Questions