Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions src/utils/rtlText.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading