-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
Proposal: Support custom text transformation plugins #3920
Comments
We have recently made a huge refactoring to the rtl text plugin to split worker code and main thread code. |
Interesting idea @ibesora. I would leave the RTL plugin interface in place and add a second interface for generic text transformation plugins. Both can use the same functionality internally. |
Motivation
Allowing people to format labels as they want without having to transform their data in external software is quite limited using Maplibre style expressions. Things like having a number like
0.66
in the underlying data and wanting it to show as66%
are not supported right now. This proposal aims to fix that gap.While style spec could be extended to support more text transformations, it's arguably impossible to support everything a developer might need and adding support for new transformations would require a new style spec version.
Proposed change
Add a new API to Maplibre that replaces the current RTLTextPlugin one for a more generic one to support arbitrary text transformation plugins. RTLTextPlugin must still be supported as it is by this new API.
API Modifications
TextPlugin
interface that follows theplugin
structure defined inrtl_text_plugin
. One annoying caveat here is that the current implementation executes a function calledapplyArabicShaping
which is quite centered around RTL text. My proposal here would be to support using eitherapplyArabicShaping
, to keep backward compatibility with current plugins, or a more genericapplyTransformation
for newly developed ones.getRTLTextPluginStatus
,clearRTLTextPlugin
,setRTLTextPlugin
,downloadRTLTextPlugin
, andlazyLoadRTLTextPlugin
to remove traces ofRTL
and allow using multiple plugins instead of a single one.SymbolBucket::populate
to support checking the status of multiple pluginstransformTextInternal
intransform_text.ts
to runapplyTransformation
orapplyArabicShaping
on each plugin, one at a time, following the definition orderCompatibility
Supporting
applyArabicShaping
in plugins would allow this proposal to keep compatibility with existing plugins. No migration is needed.There might be concerns about people writing arbitrary javascript code that can tank the performance but this can also be an issue currently.
Rejected Alternatives
There's a similar proposal to handle this in maplibre/maplibre-style-spec#516 by defining external functions in Maplibre's style spec. Doing that would couple the style definition with the website's code which this proposal avoids.
cc @ChrisLoer
The text was updated successfully, but these errors were encountered: