From 92ce7220f83882ba0309dc7f3820a478cf78b3db Mon Sep 17 00:00:00 2001 From: Bruno Raimbault Date: Thu, 10 Sep 2026 10:37:07 +0200 Subject: [PATCH] fix: set the RTL text plugin --- src/Map.js | 5 ++++- src/utils/rtlText.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/utils/rtlText.js diff --git a/src/Map.js b/src/Map.js index 3000d741..ffd31762 100644 --- a/src/Map.js +++ b/src/Map.js @@ -15,6 +15,7 @@ import { composeTransformRequest, } from './utils/images.js' import { OVERLAY_START_POSITION, MAP_MAX_ZOOM } from './utils/layers.js' +import { loadRTLTextPlugin } from './utils/rtlText.js' import { mapStyle } from './utils/style.js' import syncMaps from './utils/sync.js' import './Map.css' @@ -37,7 +38,9 @@ export class MapGL extends Evented { constructor(el, options = {}) { super() - const { locale, glyphs, scrollZoom } = options + const { locale, glyphs, scrollZoom, rtlTextPluginUrl } = options + + loadRTLTextPlugin(rtlTextPluginUrl) const mapgl = new Map({ container: el, diff --git a/src/utils/rtlText.js b/src/utils/rtlText.js new file mode 100644 index 00000000..59c88827 --- /dev/null +++ b/src/utils/rtlText.js @@ -0,0 +1,21 @@ +import { setRTLTextPlugin } from 'maplibre-gl' + +// Official Mapbox/MapLibre plugin for Arabic shaping and right-to-left reordering. +const DEFAULT_RTL_TEXT_PLUGIN_URL = + 'https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.3.0/dist/mapbox-gl-rtl-text.js' + +let requested = false + +export const loadRTLTextPlugin = (url = DEFAULT_RTL_TEXT_PLUGIN_URL) => { + if (requested) { + return + } + + requested = true + + try { + setRTLTextPlugin(url, true) + } catch (error) { + console.error('Failed to set RTL text plugin', error) + } +}