支持从右到左文本
使用 mapbox-gl-rtl-text 插件支持阿拉伯语和希伯来语等从右到左的语言;
<!DOCTYPE html>
<html lang="en">
<head>
<title>支持从右到左文本</title>
<meta property="og:description" content="使用 mapbox-gl-rtl-text 插件支持阿拉伯语和希伯来语等从右到左的语言" />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='stylesheet' href='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.css' />
<script src='https://unpkg.com/maplibre-gl@5.5.0/dist/maplibre-gl.js'></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
maplibregl.setRTLTextPlugin(
'https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.3.0/dist/mapbox-gl-rtl-text.js',
true // 延迟加载插件
);
const map = new maplibregl.Map({
container: 'map',
style:
'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL',
center: [44.3763, 33.2788], // 巴格达(伊拉克首都)
zoom: 11
});
</script>
</body>
</html>