我通过读取地图的WKT-String来增加地图的功能:
var feature = wkt.readFeature(entity.WellKnownText);
feature.bxObject = entity;
src.addFeature(feature);每个特性都有一个bxObject属性,该属性包含"radius"-Property。
我对图层进行了样式化,其中添加了如下特性:
var layer = new ol.layer.Vector({
source: src,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 6,
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
}),
fill: new ol.style.Fill({ color: [0, 0, 255, 0.1] })
})
})
});我想要风格的半径属性是动态的。我所做的和作为解决办法的方法如下:
var layer = new ol.layer.Vector({
source: src,
style: function (feature, resolution) {
return [
new ol.style.Style({
image: new ol.style.Circle({
radius: feature.bxObject.radius || 6,
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
}),
fill: new ol.style.Fill({ color: [0, 0, 255, 0.1] })
})
})
];
}
});但这为每个功能创造了一个新的风格..。我可能会画出1000多个特征,我甚至有一个主观的观点,那就是它减慢了一切。真的是这样做的吗?
我找到了这个stackoverflow post。但我没有运气尝试插入“${.}”。我想这是openLayers 2的一个特性:
var layer = new ol.layer.Vector({
source: src,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: "${bxObject.radius}",
stroke: new ol.style.Stroke({
color: 'blue',
width: 1
}),
fill: new ol.style.Fill({ color: [0, 0, 255, 0.1] })
})
})
});发布于 2015-11-06 14:11:03
是的,这是真正的方式,但你应该保持一个风格缓存和重用时,如果可能的话。例如,见:http://openlayers.org/en/v3.10.1/examples/kml-earthquakes.html
https://stackoverflow.com/questions/33568301
复制相似问题