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

Absolute file URL is treated as mapbox: style URL #3505

Closed
ManuelRiegler opened this issue Jan 11, 2016 · 6 comments
Closed

Absolute file URL is treated as mapbox: style URL #3505

ManuelRiegler opened this issue Jan 11, 2016 · 6 comments
Assignees
Labels
bug iOS Mapbox Maps SDK for iOS

Comments

@ManuelRiegler
Copy link

Hi guys,
I try to use custom raster tiles in my project but I always get the following error:
"loading style failed: HTTP status code 401"

My MGLMapView is embed in an .xib file with just the default settings and I set the styleURL within the code (using local styles):

NSString *path = [[NSBundle mainBundle] pathForResource:@"alpstein_raster" ofType:@"json"]; styleURL = [NSURL URLWithString:path]; self.mapView.styleURL = styleURL;

My alpstein_raster json looks like:


{
  "version": 8,
  "name": "Alpstein",
  "sources": {
    "Alpstein-Summer": {
      "type": "raster",
      "tiles": [
        "http://xxx/AlpsteinSummer/{z}/{x}/{y}.png",
        "http://xxx/AlpsteinSummer/{z}/{x}/{y}.png",
        "http://xxx/AlpsteinSummer/{z}/{x}/{y}.png",
        "http://xxx/AlpsteinSummer/{z}/{x}/{y}.png"
      ],
      "tileSize": 256
      "maxzoom": 17
    }
  },

  "layers": [{
    "id": "Alpstein",
    "type": "raster",
    "source": "Alpstein-Summer",
    "paint": {
      "raster-fade-duration": 100
    }
  }]
}

I don´t set an AccessTokes since I don´t use MapBox Tilessources.
Any idea what I am doing wrong?
Tx for help,
Askin

@ManuelRiegler ManuelRiegler changed the title Custom raster tiles Custom raster tiles don`t work with local styles Jan 11, 2016
@ManuelRiegler
Copy link
Author

When I upload my JSON file to a webserver it works:
NSString *urlstr = @"http://www.someurl.com/alpstein_raster.json";
styleURL = [NSURL URLWithString:urlstr];

@1ec5
Copy link
Contributor

1ec5 commented Jan 11, 2016

MGLMapView is seeing an absolute file URL and treating it as a mapbox: URL. The workaround is to use a relative URL. Relative URLs are calculated relative to the main bundle:

[NSURL URLWithString:@"alpstein_raster"]

@RomainQuidet
Copy link
Contributor

confirmed, it's working on local file with [NSURL URLWithString:@"asset://myfilename.json"]

@RomainQuidet
Copy link
Contributor

@1ec5 Don't you think it would be useful to also expose the setStyleJSON api ? Users could need to load dynamically constructed json strings (versus files).

@ManuelRiegler
Copy link
Author

tx guys -> [NSURL URLWithString:@"asset://alpstein_raster.json"]; works

@1ec5
Copy link
Contributor

1ec5 commented Jan 11, 2016

Hm, it shouldn’t be necessary to use the asset: protocol – that’s an implementation detail. A relative URL like myfilename.json is expected to work. Reopening because we should get absolute file URLs to work too. It’s just a matter of calculating the common base between an absolute file path and the path to the main bundle.

Don't you think it would be useful to also expose the setStyleJSON api ?

This API was exposed way back when, until we removed it in #1184 to reduce MGLMapView’s complexity. Moreover, passing a JSON file as a string was unwieldy for manipulating more than the most simple of styles, since you had to serialize back and forth (see cutting-room-floor/mapbox-gl-cocoa#31). There are plans to introduce a proper, object-oriented style API (#837), which would address this and other use cases.

@1ec5 1ec5 reopened this Jan 11, 2016
@1ec5 1ec5 added bug iOS Mapbox Maps SDK for iOS labels Jan 11, 2016
@1ec5 1ec5 changed the title Custom raster tiles don`t work with local styles Absolute file URL is treated as mapbox: style URL Jan 11, 2016
@1ec5 1ec5 self-assigned this Aug 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

No branches or pull requests

3 participants