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

Improve tile URL normalization for better support for custom vector source support #7037

Closed
Danielku15 opened this issue Jul 27, 2018 · 1 comment
Labels

Comments

@Danielku15
Copy link

mapbox-gl-js version: 0.47.0 and master branch

browser: Any

Steps to Trigger Behavior

  1. Try to use a non mapbox URL as style source (e.g. ESRI or an own OpenMapTiles server )

Link to Demonstration

https://jsfiddle.net/ef7qwb1c/

Expected Behavior

MapBox should load the tiles form the given URL and display them.

Actual Behavior

MapBox constructs an invalid TileURL resulting in a failed XMLHttpRequest to load the data resulting in a an empty map and a lot of JS errors.

How to fix

Issue is the normalizeTileURL function which does not consider the sourceURL in this scenario:

if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;

In the provided fiddle the tileURL is set to /tile/6/26/15.pbf and sourceURL is https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer. Together they form a correct URL but mapbox only returns the tileURL.

I made a simple change to the function and the 3rd party source is working as expected.

export const normalizeTileURL = function(tileURL: string, sourceURL?: ?string, tileSize?: ?number): string {
    if (!sourceURL) return tileURL;
    if (!isMapboxURL(sourceURL)) {
        const sourceUrlObject = parseURL(sourceURL);
        sourceUrlObject.path += tileURL;
        return formatUrl(sourceUrlObject);
    }
    ...

An actual fix might need to consider certain formats (trailing&leading slashes, placeholders etc.) but considering a compatible format mapbox properly loads and displays the tiles with this change.

@jfirebaugh
Copy link
Contributor

The TileJSON at https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer isn't valid. Entires in the tiles property array must be complete URLs, not relative paths. This will need to be corrected on the server side.

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

No branches or pull requests

3 participants