Added no WebGL error message to MapboxGL map component

This commit is contained in:
orangemug 2018-08-22 22:05:46 +01:00
parent 98c235bc21
commit 6207416b32
2 changed files with 35 additions and 4 deletions

View file

@ -15,6 +15,9 @@ import 'mapbox-gl/dist/mapbox-gl.css'
import '../../mapboxgl.css'
import '../../libs/mapbox-rtl'
const IS_SUPPORTED = MapboxGl.supported();
function renderPropertyPopup(features) {
var mountNode = document.createElement('div');
ReactDOM.render(<FeaturePropertyPopup features={features} />, mountNode)
@ -82,6 +85,8 @@ export default class MapboxGlMap extends React.Component {
}
UNSAFE_componentWillReceiveProps(nextProps) {
if(!IS_SUPPORTED) return;
if(!this.state.map) return
const metadata = nextProps.mapStyle.metadata || {}
MapboxGl.accessToken = metadata['maputnik:mapbox_access_token'] || tokens.mapbox
@ -94,6 +99,8 @@ export default class MapboxGlMap extends React.Component {
}
componentDidUpdate(prevProps) {
if(!IS_SUPPORTED) return;
const map = this.state.map;
if(this.props.inspectModeEnabled !== prevProps.inspectModeEnabled) {
@ -108,6 +115,8 @@ export default class MapboxGlMap extends React.Component {
}
componentDidMount() {
if(!IS_SUPPORTED) return;
const mapOpts = {
...this.props.options,
container: this.container,
@ -164,9 +173,20 @@ export default class MapboxGlMap extends React.Component {
}
render() {
return <div
className="maputnik-map"
ref={x => this.container = x}
></div>
if(IS_SUPPORTED) {
return <div
className="maputnik-map"
ref={x => this.container = x}
></div>
}
else {
return <div
className="maputnik-map maputnik-map--error"
>
<div className="maputnik-map__error-message">
Error: Cannot load MapboxGL, WebGL is either unsupported or disabled
</div>
</div>
}
}
}

View file

@ -1,5 +1,6 @@
// MAP
.maputnik-map {
display: flex;
position: fixed !important;
top: $toolbar-height + $toolbar-offset;
right: 0;
@ -10,6 +11,16 @@
- 200px /* layer list */
- 350px /* layer editor */
);
&--error {
align-items: center;
justify-content: center;
}
&__error-message {
margin: 16px;
text-align: center;
}
}
// DOC LABEL