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

More friendly URL structures and style formatting assumptions #96

Closed
2 tasks done
jwasilgeo opened this issue Jul 23, 2021 · 0 comments · Fixed by #100
Closed
2 tasks done

More friendly URL structures and style formatting assumptions #96

jwasilgeo opened this issue Jul 23, 2021 · 0 comments · Fixed by #100

Comments

@jwasilgeo
Copy link
Contributor

jwasilgeo commented Jul 23, 2021

Recently when testing the L.esri.Vector.vectorTileLayer with a custom Koop VectorTileServer, I noticed the following errors coming from the Util.js helper functions, which made it impossible to successfully communicate with and render a layer:

  • 1. Sometimes VectorTileServer properties about related URLs include "/" at the beginning, for example:
    defaultStyles: "/resources/styles"

    The beginning forward slash results in a defaultStylesUrl with too many forward slashes and some servers treat this as an invalid path. See Util.js's loadStyleFromService function.

    A similar issue exists when formatting the style object to meet the Mapbox spec, specifically for the source.tiles property. See Util.js's formatStyle function and focus on this line:
    source.tiles = [source.url + metadata.tiles[0]]

    Proposed changes:

    • Let's add more conditional checks and deal with extra slashes ourselves.

    • OR: Remove duplicate forward slashes from any URLs that are manually constructed or modified by Util.js. For example perhaps this string replacement that doesn't affect the valid double slashes at the https:// position:
      urlThatNeedsCleaning = urlThatNeedsCleaning.replace(/([^:]\/)\/+/g, "$1");

  • 2. Some styles do not have sprite or glyphs properties. These are listed as optional in the Mapbox style spec. This block makes perhaps too many assumptions:

    // resolve absolute URLs for style.sprite and style.glyphs
    if (style.sprite.indexOf('http') === -1) {
    style.sprite = styleUrl.replace(
    'styles/root.json',
    style.sprite.replace('../', '')
    );
    }
    if (style.glyphs.indexOf('http') === -1) {
    style.glyphs = styleUrl.replace(
    'styles/root.json',
    style.glyphs.replace('../', '')
    );
    }
    // add the token to the style.sprite and style.glyphs properties as a query param
    style.sprite += token ? '?token=' + token : '';
    style.glyphs += token ? '?token=' + token : '';

    Proposed changes:

    • Be more careful with assuming sprite or glyphs exist and do something like this for both:
      if (style.sprite && style.sprite.indexOf('http') === -1) { ...

    • And move these lines into their related if statements:

      // add the token to the style.sprite and style.glyphs properties as a query param
      style.sprite += token ? '?token=' + token : '';
      style.glyphs += token ? '?token=' + token : '';

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

Successfully merging a pull request may close this issue.

1 participant