我的openlayers 3应用程序在地图上绘制了几个LineString功能(从几十到2000-3000).
当为LineStrings的每个片段设置不同的颜色时,我遇到了巨大的性能影响(从地图上的几个LineStrings开始).变焦和平移完全没有响应,使我的应用程序无法在此表单中使用.
由于我不想为每个段设置一个新几何(但只改变它的颜色),我想有必要有一个更有效的方法来实现这个?
这是我的代码:
var styleFunction = function(feature, resolution) {
var i = 0, geometry = feature.getGeometry();
geometry.forEachSegment(function (start, end) {
color = colors[i];
styles.push(new ol.style.Style({
geometry: new ol.geom.LineString([start, end]),
fill: new ol.style.Fill({
color: color
}),
stroke: new ol.style.Stroke({
color: color,
width: 2
})
}));
i++;
});
return styles;
}
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
Run Code Online (Sandbox Code Playgroud) openlayers-3 ×1