Skip to content

Commit

Permalink
feat: remove RTLTextPlugin default for MapLibre (#2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
KiwiKilian authored Jan 31, 2025
1 parent 74a652e commit fbf2791
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
10 changes: 4 additions & 6 deletions docs/api-reference/maplibre/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,12 @@ If `reuseMaps` is set to `true`, when a map component is unmounted, the underlyi

Note that since some map options cannot be modified after initialization, when reusing maps, only the reactive props and `initialViewState` of the new component are respected.

#### `RTLTextPlugin`: string | false {#rtltextplugin}
#### `RTLTextPlugin`: string | object {#rtltextplugin}

Default: `'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'`

Sets the map's [RTL text plugin](https://www.mapbox.com/mapbox-gl-js/plugins/#mapbox-gl-rtl-text). Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left.

Setting this prop is the equivalent of calling [setRTLTextPlugin](https://maplibre.org/maplibre-gl-js/docs/API/functions/setRTLTextPlugin/) with `lazy: true`. Set to `false` to disable loading the RTL text plugin.
- `pluginUrl`: `string` URL to the plugin JS file.
- `lazy`: `boolean` When true, the plugin is only loaded when the map first encounters Hebrew or Arabic text. Default `true`.

Sets the map's RTL text plugin via [setRTLTextPlugin](https://maplibre.org/maplibre-gl-js/docs/API/functions/setRTLTextPlugin/). Can be used with [mapbox-gl-rtl-text](https://github.com/mapbox/mapbox-gl-rtl-text). Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left.

#### `workerCount`: number {#workercount}

Expand Down
11 changes: 11 additions & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
| `*Layer` | `*LayerSpecification` |
| `*SourceRaw` | `*SourceSpecification` |

### MapLibre

#### Removed default for `RTLTextPlugin`

The default `RTLTextPlugin` loaded from mapbox.com has been removed to align with the default behavior of MapLibre.
To keep the previous behavior, specify the `pluginUrl` which was previously used or supply the plugin from any other source:

```tsx
<Map RTLTextPlugin="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js" />
```


## Upgrading to v7.1

Expand Down
16 changes: 7 additions & 9 deletions modules/react-maplibre/src/utils/set-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type GlobalSettings = {
*/
maxParallelImageRequests?: number;
/** The map's RTL text plugin. Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left. */
RTLTextPlugin?: string | false;
RTLTextPlugin?: string | {pluginUrl: string; lazy?: boolean};
/** The number of web workers instantiated on a page with maplibre-gl maps.
* @default 2
*/
Expand All @@ -16,26 +16,24 @@ export type GlobalSettings = {
};

export default function setGlobals(mapLib: any, props: GlobalSettings) {
const {
RTLTextPlugin = 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js',
maxParallelImageRequests,
workerCount,
workerUrl
} = props;
const {RTLTextPlugin, maxParallelImageRequests, workerCount, workerUrl} = props;
if (
RTLTextPlugin &&
mapLib.getRTLTextPluginStatus &&
mapLib.getRTLTextPluginStatus() === 'unavailable'
) {
const {pluginUrl, lazy = true} =
typeof RTLTextPlugin === 'string' ? {pluginUrl: RTLTextPlugin} : RTLTextPlugin;

mapLib.setRTLTextPlugin(
RTLTextPlugin,
pluginUrl,
(error?: Error) => {
if (error) {
// eslint-disable-next-line
console.error(error);
}
},
true
lazy
);
}
if (maxParallelImageRequests !== undefined) {
Expand Down

0 comments on commit fbf2791

Please sign in to comment.