Skip to content

Instantly share code, notes, and snippets.

@hijiangtao
Created January 29, 2019 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hijiangtao/a53a5922428331b63c44f6d2d7cb07d3 to your computer and use it in GitHub Desktop.
Save hijiangtao/a53a5922428331b63c44f6d2d7cb07d3 to your computer and use it in GitHub Desktop.
mapbox-gl-language not work well inside react-map-gl
import React, {Component} from 'react';
import {render} from 'react-dom';
import {StaticMap} from 'react-map-gl';
import MapboxLanguage from 'mapbox-gl-language';
export default class App extends Component {
state = {
viewport: {
longitude: -100,
latitude: 40,
zoom: 3.5
}
};
_onLoad = (event) => {
const map = event.target;
map.addControl(new MapboxLanguage({
defaultLanguage: 'zh',
}));
// Set following line to run will fix the chinese label display problem
// map.setLayoutProperty('country-label-lg', 'text-field', ['get', 'name_zh']);
}
render() {
return (
<StaticMap
{...this.state.viewport}
width="100%"
height="100%"
mapStyle="mapbox://styles/mapbox/light-v9"
onLoad={this._onLoad} />
);
}
}
render(<App/>, document.getElementById('map'));
@yihong0618
Copy link

Solve my problem.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment