@react-native-mapbox-gl/maps语言插件汉化不完善问题

mapbox react native 直接使用会出现部分地图语言翻译不全,有大量拼音label,本文讲解如何解决这个问题:
首先地图使用URL使用以下版本:

mapbox://styles/mapbox/streets-v10
mapbox://styles/mapbox/outdoors-v10
mapbox://styles/mapbox/dark-v9
mapbox://styles/mapbox/light-v9
mapbox://styles/mapbox/satellite-streets-v9
mapbox://styles/mapbox/traffic-day-v2
mapbox://styles/mapbox/traffic-night-v2  

然后修改源码,路径 node_modules\@react-native-mapbox-gl\maps\android\rctmgl\src\main\java\com\mapbox\rctmgl\components\mapview\RCTMGLMapView.java

 private void setupLocalization(Style style) {
   mLocalizationPlugin = new LocalizationPlugin(RCTMGLMapView.this, mMap, style);
  if (mLocalizeLabels) {
       try {
           mLocalizationPlugin.matchMapLanguageWithDeviceDefault();
           localizationPlugin.setMapLanguage(MapLocale.CHINA);//可以根据需要修改,或者动态的设置语言
       } catch (Exception e) { 
           final String localeString = Locale.getDefault().toString();
           Logger.w(LOG_TAG, String.format("Could not find matching locale for %s", localeString));
       }
   }
 }

网页版本的语言插件 https://github.com/mapbox/mapbox-gl-language

posted @ 2020-12-15 10:59  木子归零  阅读(376)  评论(0编辑  收藏  举报