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

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

Closed

Description

@ManuelRiegler

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

Activity

  1. changed the title [-]Custom raster tiles[/-] [+]Custom raster tiles don`t work with local styles[/+] on Jan 11, 2016
  2. ManuelRiegler commented on Jan 11, 2016

    @ManuelRiegler
    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];

  3. 1ec5 commented on Jan 11, 2016

    @1ec5
    Contributor

    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"]
  4. RomainQuidet commented on Jan 11, 2016

    @RomainQuidet
    Contributor

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

  5. RomainQuidet commented on Jan 11, 2016

    @RomainQuidet
    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).

  6. ManuelRiegler commented on Jan 11, 2016

    @ManuelRiegler
    Author

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

  7. 1ec5 commented on Jan 11, 2016

    @1ec5
    Contributor

    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.

  8. reopened this on Jan 11, 2016
  9. added
    iOS
    on Jan 11, 2016
  10. changed the title [-]Custom raster tiles don`t work with local styles[/-] [+]Absolute file URL is treated as mapbox: style URL[/+] on Jan 11, 2016
  11. self-assigned this
    on Aug 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugiOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions