我想画一张代表一个城市交通状况的地图。所以我有一些流量指标,我想在地图上可视化。我希望根据当前的交通状况给每条道路涂上不同的颜色。
大概是这样的:

我试图找到关于如何将样式仅应用于部分道路的教程,但我找不到如何做到这一点。
非常感谢,这将会有很大的帮助,谢谢!
发布于 2019-02-01 16:59:40
你应该为一个向量层使用一个layer函数:
https://openlayers.org/en/v4.6.5/apidoc/ol.html#.StyleFunction
来自OL3的示例:
http://openlayersbook.github.io/ch11-creating-web-map-apps/example-02.html
详细说明上面的示例
function flickrStyle(feature) {
var style = null;
if (feature.get("name")=="Küstenschwalbe") {
style = new ol.style.Style({
image: new ol.style.Circle({
radius: 6,
stroke: new ol.style.Stroke({
color: 'white',
width: 2
}),
fill: new ol.style.Fill({
color: 'green'
})
})
});
}
else {
style = new ol.style.Style({
image: new ol.style.Circle({
radius: 6,
stroke: new ol.style.Stroke({
color: 'yellow',
width: 2
}),
fill: new ol.style.Fill({
color: 'red'
})
})
});
}
return [style];
}
var flickrLayer = new ol.layer.Vector({
source: flickrSource,
style: flickrStyle
});https://stackoverflow.com/questions/54452990
复制相似问题