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

V8 style support #39

Merged
merged 12 commits into from
Feb 17, 2021
Merged

V8 style support #39

merged 12 commits into from
Feb 17, 2021

Conversation

ryanhamley
Copy link
Contributor

@ryanhamley ryanhamley commented Oct 24, 2020

This PR fixes #31 but in doing so, it drops support for all Mapbox styles based on vector tile source v7 as these styles are deprecated and Mapbox is encouraging all users to migrate to v8 styles. This change will require a major version release of this plugin.

Additionally, this PR drops support for IE11 since Mapbox GL JS is also deprecating support for the browser.

This PR also updates the example pages to use the newest styles and current versions of Mapbox GL JS and the RTL plugin while adding new example pages for Italian, Simplified Chinese and Traditional Chinese.

The code now assumes that your text-field will include an expression of the form ['get', 'name_xx']. This can be a top-level expression, in a coalesce expression or nested deeper in an expression. The plugin will also now support Italian (it), Simplified Chinese (zh-Hans) and Traditional Chinese (zh-Hant) by default. v7 style Chinese zh is no longer supported.

@mapbox/gl-js

Copy link

@samanpwbb samanpwbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanhamley this looks solid! I think we should get the docs updated to clarify requirements for using this library:

  • Streets v8
  • Expression text values (no support for curly backets)
  • Expects translated languages with coalesce expressions that fall back to non-null name field.

I see a few opportunities for improvement but I don't think these are necessary for merge:

  1. There is a somewhat common edge case where user will have a text field that isn't already wrapped in a coalesce (for example, if the style uses ["get", "name"] alone). Based on the logic implemented now, this could result in a lot of empty labels. To cover these cases, it'd be great if the plugin checked if field values are wrapped in coalesce, and if not, add the coalesce.
  2. To improve developer UX, add some validation to warn on curly bracket tokens, or warn on non-coalesce wrapped get expressions.
  3. There are rare edge cases where language get expressions are used in inputs to other expressions rather than outputs. Since the current implementation doesn't know about context when it applies transforms, there's no way to handle these cases. I would at least add a note about this in the readme. Take for example:
["match", 
  ["get", "name"], 
  "Canada", 
  "America's Hat", 
  ["coalesce", 
    ["get", "name_en"], 
    ["get", "name"]
  ]
]

@@ -5,7 +5,7 @@
* @param {object} options - Options to configure the plugin.
* @param {string[]} [options.supportedLanguages] - List of supported languages
* @param {Function} [options.languageTransform] - Custom style transformation to apply
* @param {RegExp} [options.languageField=/^\{name/] - RegExp to match if a text-field is a language field
* @param {RegExp} [options.languageField=/^name_/] - RegExp to match if a text-field is a language field
Copy link

@samanpwbb samanpwbb Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this PR drops support for translating non-expression (token) text field values. This is a good idea to keep the library small and future-thinking, but I think we should make that change really clear in the docs. Tokens are technically still supported in GL stylesheets.

t.end();
});

t.end();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a test case with a more complex expression (multiple get expressions, more depth).

index.js Outdated
var url = style.sources[sourceName].url;
// the source URL can reference the source version or the style version
// this check and the error forces users to migrate to styles using source version 8
return url.indexOf('mapbox.mapbox-streets-v8') > -1 || /mapbox-streets-v[1-9][1-9]/.test(url);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geojson sources don't have a url, so should we skip sources here without a url?

index.js Outdated
var url = style.sources[sourceName].url;
// the source URL can reference the source version or the style version
// this check and the error forces users to migrate to styles using source version 8
return url.indexOf('mapbox.mapbox-streets-v8') > -1 || /mapbox-streets-v[1-9][1-9]/.test(url);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return url.indexOf('mapbox.mapbox-streets-v8') > -1 || /mapbox-streets-v[1-9][1-9]/.test(url);
return url && url.indexOf('mapbox.mapbox-streets-v8') > -1 || /mapbox-streets-v[1-9][1-9]/.test(url);

Copy link

@andrewharvey andrewharvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I've been running this in production with no issues noticed so far.

@ryanhamley
Copy link
Contributor Author

@samanpwbb I think I addressed all your concerns. This now handles the unwrapped case text-field: ['get', 'name'] and provides a warning when token syntax is encountered and the documentation has been updated.

@andrewharvey That's great to hear that this is already working well! Once this is merged, I'm going to make a few updates and make a new release.

Copy link

@samanpwbb samanpwbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

README.md Outdated
["match",
["get", "name"],
"Canada",
"America's Hat",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hehe maybe we should use an example that is less offensive to canadians. @tristen do you have suggestions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I likey. @willymaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

["match", 
  ["get", "name"], 
  "California", 
  "Golden State", 
  ["coalesce", 
    ["get", "name_en"], 
    ["get", "name"]
  ]
]

@ryanhamley ryanhamley merged commit d7b2a1a into master Feb 17, 2021
@ryanhamley ryanhamley deleted the v8-style-support branch February 17, 2021 01:18
@ryanhamley ryanhamley restored the v8-style-support branch February 17, 2021 01:18
@ryanhamley ryanhamley mentioned this pull request Feb 17, 2021
This was referenced Mar 4, 2021
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support of streets-v11 (and other styles based on Streets v8 vector tile source)
4 participants