最近需要画拥堵路线在网上找的方法也看不太明白,好在最终搞了出来,记录一下大家互相交流
//拥堵路线方法
drawRoutes() {
let _this = this;
let polyLintArray = new Array();
if (!this.lineData) {
return console.log("获取拥堵路线失败!");
}
this.lineData.map((item) => {
let flat = [];
flat = item;
polyLintArray.push(flat);
});
let sub = [];
for (const item of polyLintArray) {
var feature = new Feature({
type: "LineString",
geometry: new LineString(item.geom.coordinates),
});
let color = "#F8D34A";
if (item.color == "red") {
color = "#DF2116";
} else if (item.color == "peony") {
color = "#AE1207";
}
let lineStyle = new Style({
stroke: new Stroke({
color: color,
width: 4,
}),
});
// 添加线的样式
feature.setStyle(lineStyle);
// 添加线的fature
_this.layers.lineLayer.getSource().addFeature(feature);
}
},