javascript - 传单:使用图层在地图上一起显示动态折线
问题描述
我正在使用传单在我的地图上显示所有(不同颜色的)折线。我正在获取所有动态折线的纬度和经度及其颜色,但是当我使用图层合并它时,它只需要最后一条折线并显示它。
我想我在分层时犯了一些错误。有人可以推荐在传单中分层折线的正确方法吗?
这是发生这种情况的代码示例 -
let newColour = this.returnMapColor(moment(startDate).day());
var layerGroups = {}
console.log("colour", newColour, startDate );
let range = this.props.history.filter((v) => { return moment(v.time).format("YYYY-MM-DD") == moment(startDate).format("YYYY-MM-DD") });
startDate = moment(startDate).add(1, 'days');
range.map((row)=> {
positions.push([row.latitude,row.longitude,row.sp] )
});
if(this.props.map){
const leafletMap = this.props.map.leafletElement;
this.hotlineLayer = L.layerGroup(L.polyline(positions, {color: newColour})).addTo(leafletMap);
}
++i;
解决方案
一条折线至少需要两组lat, longs
. 你能指出你的代码在哪里形成polylines
吗?
在您的代码中,range.map
该操作只会导致创建一个位置数组。因此,您的代码正在呈现单行。
如果您打算创建多条折线并使用 渲染它们LayerGroup
,我会建议以下内容:
var latlngs1 = [
[45.51, -122.68,0],
[37.77, -122.43,1],
[34.04, -118.2,2]
];
var latlngs2 = [
[34.04, -118.2,2],
[32.08, -110.5,2]
];
const polyline1 = L.polyline(latlngs1, {color: 'red'})
var polyline2 = L.polyline(latlngs2, {color: 'blue'})
var hotlineLayer = L.layerGroup([polyline1, polyline2]).addTo(map);
推荐阅读
- php - 我如何将默认值设置为 Symfony 的日期时间过滤器
- storage - Anylogic中的存储系统
- azure - 如何在 Azure 中实时使用 ML 模型,其中模型依赖于点击流?
- javascript - Three.js:无法使用 THREE.ExtrudeGeometry 冲压(切割)线条形状
- amazon-web-services - AWS RDS 和 TIG
- c++ - 当我使用 std::cout.imbue(std::locale("en_US.UTF-8")); 时没有输出 在 C++ 中
- dns - ejabberd 集群的适当扩展
- javascript - 赛普拉斯 - 从表中删除所有行
- django - Django Polls-App:动态更改 create-poll-form 中的选择数量
- inheritance - 在 odoo 中继承模型并为其创建新的 xml 文件