Created
January 29, 2019 05:06
-
-
Save hijiangtao/a53a5922428331b63c44f6d2d7cb07d3 to your computer and use it in GitHub Desktop.
mapbox-gl-language not work well inside react-map-gl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solve my problem.
Thank you.