javascript - React map gl(空白有图层或没有图层的地图)
问题描述
我使用https://www.npmjs.com/package/react-map-gl包并从那里尝试实现这个自定义数据示例,但它似乎只在空白页面或地图上显示一个圆圈但没有圆圈。C
import ReactMapboxGl, { Layer, Feature } from 'react-mapbox-gl';
import ReactMapGL from 'react-map-gl';
import React from 'react';
import { connect } from 'react-redux';
import { extraLayer } from 'Components/dataViewElements/Map/test.js';
import { fromJS } from 'immutable';
const MAPBOX_TOKEN =
'pk.TOKEN_HERE';
const mapStyle = fromJS({
version: 8,
sources: {
'mapbox-streets': {
type: 'vector',
url: 'mapbox://mapbox.mapbox-streets-v6',
},
points: {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: { type: 'Point', coordinates: [-122.45, 37.78] },
},
],
},
},
},
layers: [
{
id: 'my-layer',
type: 'circle',
source: 'points',
paint: {
'circle-color': '#f00',
'circle-radius': 4,
},
},
],
});
class MapElement extends React.Component {
state = {
viewport: {
width: '70vw',
height: '70vh',
latitude: -24.4698,
longitude: 135.0251,
zoom: 4,
},
};
_onViewportChange = viewport => this.setState({ viewport });
render() {
const { viewport } = this.state;
console.log(mapStyle);
return (
<ReactMapGL
{...viewport}
mapStyle={mapStyle}
// mapStyle={mapStyle}
mapboxApiAccessToken={MAPBOX_TOKEN}
onViewportChange={this._onViewportChange}
/>
);
}
}
const mapStateToProps = (state, props) => ({});
const mapDispatchToProps = dispatch => ({});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(MapElement);
非常感谢任何帮助,尝试解决这个问题几个小时,所以认为应该在这里发布。
解决方案
推荐阅读
- vhdl - 无法使用 uvm_hdl_force 强制使用经过验证的路径的信号?
- html - 背景图像和空白区域的问题
- javascript - 如何强制输入集合在输入时始终具有相同的值?
- python - 满足条件后进入下一次迭代
- python - 如何使用 selenium Python 单击框架和 iFrame 中的项目
- r - 在 Shiny 中与 tmap 并排地图
- python - 尝试合并用户的用户名时,序列化程序无法正常工作
- winforms - Winforms 构建日期未显示在已安装的应用程序中
- c++ - 按主题备用名称获取 x509 证书 - c++
- python - 有没有办法可以将熊猫库恢复为更简单的python代码