- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经为这个问题摸不着头脑太久了。我有最简单的 React 应用程序,它将一些数据作为 props 传递给 WhateverMap(之所以这么说是因为我一直在尝试许多不同的 Map 库)。
但是,当我尝试使用 ScatterplotLayer 在 Deck.GL 上绘制数据点时,我在渲染的 map 上根本看不到它们。
根据 React Developer Tools,ScatterplotLayer 组件确实收到了我的数据点。
我希望在柏林火车轨道的特定部分看到一些标记。
import React, { Component } from 'react';
import Header from './Header';
import WhateverMap from './Map';
import Table from './Table';
class App extends Component {
state = {
// Trip along the Ringbahn
data: [
{'timestamp': Date.now()-10000, 'coordinates': [52.536131,13.447444], 'temperature': 19},
{'timestamp': Date.now()-9000, 'coordinates': [52.538221,13.44376], 'temperature': 20},
{'timestamp': Date.now()-8000, 'coordinates': [52.540247,13.43899], 'temperature': 21},
{'timestamp': Date.now()-7000, 'coordinates': [52.541751,13.43513], 'temperature': 22},
{'timestamp': Date.now()-6000, 'coordinates': [52.54264,13.433692], 'temperature': 23},
{'timestamp': Date.now()-5000, 'coordinates': [52.543007,13.431339], 'temperature': 24},
{'timestamp': Date.now()-4000, 'coordinates': [52.543755,13.428731], 'temperature': 25},
{'timestamp': Date.now()-3000, 'coordinates': [52.544295,13.427207], 'temperature': 27}
]
};
render() {
return (
<div className="container">
<Header />
<WhateverMap data={this.state.data} />
<Table data={this.state.data} />
</div>
);
}
}
export default App;
无论 map :
import React, { PureComponent } from 'react';
import MapGL from 'react-map-gl';
import DeckGL, { ScatterplotLayer } from 'deck.gl';
const mapbox_token = ''
const mapConfig = {
center: [52.540875, 13.438545],
zoom: 13
};
class WhateverMap extends PureComponent {
constructor(props) {
super(props);
this.state = {
viewport: {
width: 960,
height: 600,
latitude: mapConfig.center[0],
longitude: mapConfig.center[1],
zoom: mapConfig.zoom,
startDragLngLat: mapConfig.center,
},
};
this.onChangeViewport = this.onChangeViewport.bind(this);
}
onChangeViewport(viewport) {
this.setState({
viewport: { ...this.state.viewport, ...viewport }
});
}
initialize(gl) {
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE, gl.ONE_MINUS_DST_ALPHA, gl.ONE);
gl.blendEquation(gl.FUNC_ADD);
}
render() {
const { viewport } = this.state;
const { data } = this.props;
const plot_position_layer = new ScatterplotLayer({
id: 'scatterplot-layer',
data,
pickable: true,
opacity: 0.8,
radiusScale: 6,
radiusMinPixels: 1,
radiusMaxPixels: 100,
getPosition: d => d.coordinates,
})
return (
<div className="reactmapgldeckgl">
<MapGL
{...viewport}
mapboxApiAccessToken={mapbox_token}
mapStyle="mapbox://styles/mapbox/dark-v9"
onChangeViewport={this.onChangeViewport}
>
<DeckGL
{...viewport}
onWebGLInitialized={this.initialize}
layers={[plot_position_layer]}
/>
</MapGL>
</div>
);
}
}
export default WhateverMap;
最佳答案
首先是答案。您的代码似乎是正确的,但是,一些调整似乎可以解决该错误。
const plot_position_layer = new ScatterplotLayer({
id: 'scatterplot-layer',
data,
pickable: true,
opacity: 0.8,
radiusScale: 30, // make the dots visible or darker background
radiusMinPixels: 15, // make the dots visible or darker background
radiusMaxPixels: 100,
getPosition: d => [d.coordinates[1], d.coordinates[0]], // -> Essential Change here
getColor: d => [255, 255, 255], // make the dots visible or darker background
})
Now, what has changed essentially is
getPosition: d => [d.coordinates[1], d.coordinates[0]]
奇怪的是,getPosition 函数应该返回一个数组,其中第一个元素是经度而不是纬度,这就是点超出范围的原因。
看看他们的例子 here在第 11 行。
// Source data CSV
const DATA_URL =
'https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/scatterplot/manhattan.json'; // eslint-disable-line
export const INITIAL_VIEW_STATE = {
longitude: -74, //remember, longitude starts with 74
latitude: 40.7,
zoom: 11,
maxZoom: 16,
pitch: 0,
bearing: 0
};
DATA_URL
读取为
[
[-73.986022,40.730743,2], // the first element is longitude
[-73.984293,40.729468,1],
[-73.987752,40.732017,1],
[-73.986887,40.730105,2],
...
]
希望这有帮助
关于reactjs - Deck.GL ScatterplotLayer 不渲染点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52559897/
我一直在使用行程图层可视化行程数据,并且尝试在每条行程线的开头放置一个图标。是否可以让多个图标随时间改变位置、出现和消失? Example of what I'm trying to do (red
这可能非常简单,但我找不到如何在 deck.gl 的标签下方添加新层。它在底层使用 Mapbox GL JS。对于 mapbox gl,解释为 here . 我还在他们的文档中搜索了 z-index
谁能告诉我运行像 Uno 或 Hearts (Deck Game) 这样的游戏循环的最佳方法 [CPU2 turn]; [CPU3 turn]; [User turn]; // Wait to get
我编写了纸牌游戏的代码..但现在是时候制作图形和界面了 代表卡片的最佳方法是什么?? a) CALayerb) 用户界面 View c) UIButton 哪一个最适合动画和接收用户触摸???你有什么
设置: 使用react-map-gl的基本react应用程序显示 map ,顶部带有deck.gl ScatterplotLayer以可视化数据 目标: 1) 将 map 上的点显示为给定半径和颜色的
该程序应该使用 ArrayList 来创建一副纸牌。用户输入要抽多少张牌并打印这些牌,然后打印这副牌中剩余的其余牌。我已经打印了用户的卡片,但我不知道如何打印这副卡片中的剩余卡片。任何帮助将不胜感激。
我有一组图像。每张图片都有一个“稀有度”键,告诉我它是“常见”、“不常见”还是“稀有”。例如,数组可能看起来像这样: Array ( [0] => Array (
首先我要说的是,这与其说是如何让它发挥作用的问题,不如说是这是否是好的做法的问题。 我想用自定义的 shuffle() 方法来实现一副纸牌(正如在很多游戏中看到的那样,例如 TCG 游戏)...目前它
这实际上是我的第一个 JS 代码,所以请耐心等待,我设法改编了 Deck.Gl 中的示例以显示散点图,现在我不确定如何根据列的值更改颜色“状态”,我知道如何为 1 个值执行此操作,但不确定如何使用 i
我正在使用 deck.js 进行演示。对于一张幻灯片,我想要一个带有数字/图像的静态标题,我可以轮播。这是相关的 HTML: Static Title Text for first imag
当我在 deck.js 演示文稿中的幻灯片内容变得比垂直窗口大时,浏览器会缩小显示的内容。 内容越多,显示越小。效果看起来“页面”变宽,因为幻灯片的左上角远离浏览器窗口的左上角——就好像我正在缩小页面
我正在使用 deck.js 创建演示文稿,我遇到的问题是每当我尝试使用自定义样式(例如向表格添加边框或使用谷歌代码美化)时,它都完全没有效果。可以找到该演示文稿 here . 编辑:我有以下用于显示源
我正在尝试绘制从中国到美国的弧线,但弧线并未跨越太平洋。他们飞越大西洋,飞越欧洲。 有没有办法让弧线划过太平洋? 最佳答案 这是一个旧帖子,但可以帮助新人。您可以使用 deck.gl 中的一些更现代的
我正在尝试使用 Deck.gl 制作交互式图表,该图表结合了 HexagonLayer(用于人口数据)和 IconLayer(用于零售链式店的位置)。 deck.gl documentation表示可
我正在构建一个基本的可视化系统,可以从控制箱切换图层。我有 layers 将各个层合并为一个层。 const [layers, setLayers] = useState([densityLayer,
我是 deckgl 的新手。我想向我的层(任何类型的层)添加一些文本,但我不能 这是我的例子: const layer = new PointCloudLayer({ id: 'point-c-l
我已经为这个问题摸不着头脑太久了。我有最简单的 React 应用程序,它将一些数据作为 props 传递给 WhateverMap(之所以这么说是因为我一直在尝试许多不同的 Map 库)。 但是,当我
我已经编写了一个 Deck 类,现在必须对其进行洗牌,然后打印出几手牌来检查它是如何工作的。然而,它似乎并没有洗牌任何东西,而是给出了完全相同的牌组。 public void makeHands ()
大家好,我遇到了一个问题。 我的问题是,我想要一个程序,制作一副普通的牌,洗牌并随机发9手牌(两张牌),然后是3张牌,然后是1张牌,然后是1张牌,然后计算你获得口袋的频率对(两张相同等级的牌),这必须
我知道关于这个永恒的实现存在大量问题,但作为一名新的 OOP 程序员,我正在努力掌握必要的概念以取得任何进展。 我是否正在构建一个真正的随机牌组,可以作为任何纸牌游戏的纸牌牌组?还是我通过创建 4 套
我是一名优秀的程序员,十分优秀!