map appears blank if layers and sources are passed
Versions I am using react-map-gl version 3.3.4 with mapbox-gl: 0.47.0 and react 16.0.0
The expected behaviour The map will appears with correct layers and sources
The problem A blank screen appears without a map.
Tested browers chrome 69.0.3497.100 (Official Build) (64-bit) (for imac) firefox 62.0.2 (64-bit) (for imac)
Observations
- there is no relevant information in console
- if mapStyle='mapbox://styles/infoamazonia/cjmh38rfkgtzc2rp0tir972ag' is used directly instead Immutable.fromJS, the map appears but we have to pass through raster-tiles as layer because of this other issue, in which we need to change the way we retrieve the raster layer to PNG instead of JPG. Otherwise, Firefox and other browsers that don't support WebP will show a black background instead of the transparency of that raster.
the script is
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactMapGL from 'react-map-gl';
import Dimensions from 'react-dimensions';
import Immutable from 'immutable'
const MAPBOX_TOKEN = '[MAPBOX_TOKEN]';
class MapBox extends Component {
state = {
stateViewport: {
width:0,
height:0,
latitude:0,
longitude:0,
zoom: 8
},
updated:true
}
static propTypes = {
containerWidth: PropTypes.number.isRequired,
containerHeight: PropTypes.number.isRequired
}
componentDidMount() {
this.setState({stateViewport:{
width: this.props.containerWidth,
height: this.props.containerHeight,
latitude: this.props.coordinates[1],
longitude: this.props.coordinates[0],
zoom: 7
}});
}
componentWillReceiveProps(nextProps) {
this.setState({stateViewport:{
width: this.props.containerWidth,
height: this.props.containerHeight,
latitude: this.props.coordinates[1],
longitude: this.props.coordinates[0],
zoom: 8
}})
}
render() {
const mapStyle = Immutable.fromJS({
"version": 8,
"sources": {
"raster-tiles": {
"type": "raster",
"url": "mapbox://styles/infoamazonia/cjmh38rfkgtzc2rp0tir972ag",
"tileSize": 256
}
},
"layers": [{
"id": "Assentamentos_incra-2wyd2b2",
"type": "raster",
"source": "raster-tiles",
"minzoom": 0,
"maxzoom": 22
},
{
"id": "raster-layer",
"type": "raster",
"source": {
"type": "raster",
"tiles": ["https://api.mapbox.com/v4/cjmgv2m1s2q942spqd4naf2ke/{z}/{x}/{y}.png?access_token=MAPBOX_TOKEN"]
},
"minzoom": 0,
"maxzoom": 22
}
]
});
return (
<ReactMapGL
{...this.state.stateViewport}
//mapStyle='mapbox://styles/infoamazonia/cjmh38rfkgtzc2rp0tir972ag'
mapStyle={mapStyle}
mapboxApiAccessToken={MAPBOX_TOKEN}
onViewportChange={this.viewportChange()}
>
{console.log("MAP STYLE")}
{console.log(mapStyle)}
</ReactMapGL>
)
}
}
export default Dimensions({elementResize: true})(MapBox)
The mapStyle you pass only contain the raster layers. Is that intended?
The mapStyle you pass only contain the raster layers. Is that intended?
@Pessimistress For testing purposes, yes, we just want to have raster layers in this map to see it working with different browsers without the black background issue that we are facing. If we manage to have this fixed, then we can go adding new different layers to the mapStyle.
I don't know if you solved this or not, but in your sources.raster-tiles the url needs to be a valid raster source instead of a style.