visgl / react-map-gl

React friendly API wrapper around MapboxGL JS
http://visgl.github.io/react-map-gl/
Other
7.83k stars 1.35k forks source link

https://github.com/mapbox/mapbox-gl-language Control is not working with Map #1436

Closed hardik-satasiya closed 3 years ago

hardik-satasiya commented 3 years ago

I used ReactMapGL and I want to show map label's in user's browser language

import ReactMapGL from 'react-map-gl';

So I used this control https://github.com/mapbox/mapbox-gl-language

import ReactMapGL from 'react-map-gl';

const Map: React.FC<MapProps> = (props) => {
  const mapRef = useRef<any>();

  useEffect(() => {
      if(mapRef && mapRef.current) {
        const map = mapRef.current.getMap();
        map.addControl(new MapboxLanguage());  // just browser lang
        //  map.addControl(new MapboxLanguage({defaultLanguage: 'de'})); // or specific lang
      }
    },[mapRef]);

    return <ReactMapGL
            ref={mapRef}

But seems it's not working

I am using chrome.

Many thanks in advance please, can anyone show me the right direction or another way to do it? or am I doing it wrong?

there are multiple styles of the map as well so I need to change lang on style change as well if it's relevant to this.

Pessimistress commented 3 years ago

Please use the bug template and create a CodeSandbox that reproduces your issue if you think there is a bug with this library. Go to Discussions for generic Q&A.

xwg2015 commented 1 year ago

map.setStyle(mapboxLanguage.setLanguage(map.getStyle(), language));

you can try this.

xwg2015 commented 1 year ago

@hardik-satasiya