Mapbox-gl-js: RTL text plugin is not applied to styles initialized after the plugin is loaded

Created on 21 Jun 2017  ·  9Comments  ·  Source: mapbox/mapbox-gl-js

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... ?

bug

Most helpful comment

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

All 9 comments

cc @ChrisLoer

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.

Oh, I see. Thanks for the workaround.

Err, my race condition explanation was totally bogus. 😅 Turns out to be a simple regression I introduced in https://github.com/mapbox/mapbox-gl-js/commit/171db6177a6a5e7246fcef4d74ed297ee5a196d8 by passing the wrong arguments to the plugin registration callback in the case the plugin was already available.

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

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

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`

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

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');
}
Was this page helpful?
0 / 5 - 0 ratings