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

RTL text plugin is not applied to styles initialized after the plugin is loaded #4859

Closed
petrsloup opened this issue Jun 21, 2017 · 9 comments
Assignees
Labels

Comments

@petrsloup
Copy link

mapbox-gl-js version: 0.38.0

Steps to Trigger Behavior

  1. mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.1.1/mapbox-gl-rtl-text.js');
  2. Initialize the map (or even setStyle is enough) after the plugin is loaded

Compare:
https://jsbin.com/kepafevoho/edit?html,output (style passed via constructor)
https://jsbin.com/lixutelitu/edit?html,output (style set via setStyle after 1 s timeout)

Expected Behavior

The RTL texts should be displayed correctly even when using setStyle.
The two demos above should produce visually equal results.

Actual Behavior

The RTL does not work (the map does not seem to know about the plugin, but calling setRTLTextPlugin throws setRTLTextPlugin cannot be called multiple times..

Looks like the plugin is only "applied" on the existing map and style once after it is loaded... ?

@jfirebaugh
Copy link
Contributor

cc @ChrisLoer

@ChrisLoer ChrisLoer self-assigned this Jun 21, 2017
@ChrisLoer
Copy link
Contributor

Thanks for the super-clear report, @petrsloup.

There's a race condition here. The first time you create a style, we start running background web workers. When you register the RTL text plugin, we send a notification to the web workers to load the code. The code assumes the workers will be running before the plugin becomes available, but in your example that's not the case, because the plugin has a chance to fully load before your initial call to setStyle. In that case, the "load plugin" notification we sent to the workers gets ignored.

We'll fix the bug, but until then note that the bug only applies to the ordering of the initial setStyle vs. setRTLTextPlugin. After the background workers are running, changing styles should work just fine.

@petrsloup
Copy link
Author

Oh, I see. Thanks for the workaround.

@ChrisLoer
Copy link
Contributor

Err, my race condition explanation was totally bogus. 😅 Turns out to be a simple regression I introduced in 171db61 by passing the wrong arguments to the plugin registration callback in the case the plugin was already available.

@hakimelek
Copy link

Hello, I am still experiencing the same issue on rerenders. Is there a way to detect that setRTLTextPlugin was already being called?

@arindam1993
Copy link
Contributor

Reopening this since it seems to have regressed as per report in #9087

@arindam1993
Copy link
Contributor

This seems to we working for me with gl-js 1.6.0 and rtl-text-plugin 0.2.1.

https://jsbin.com/digepuxaze/edit?html,output
( with the map being initialized 5s after downloading the rtl text plugin`

@soufian044
Copy link

if anyone still looking i found this solution :
if (mapboxgl.getRTLTextPluginStatus() !== 'loaded') {mapboxgl.setRTLTextPlugin('...') }

@masoudhaghi
Copy link

masoudhaghi commented Mar 10, 2021

When you use this code snippet after the map initialization, you get the the following error.

Uncaught TypeError: mapboxgl.getRTLTextPluginStatus is not a function

As you can guess, the getRTLTextPluginStatus is not a function and should be used without the () in the end. The following code is the correct method to load the RTL Text Plugin without loading the plugin more than once.

if (mapboxgl.getRTLTextPluginStatus !== 'loaded') {
	mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.0/mapbox-gl-rtl-text.js');
}

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

7 participants