[英]Access default OpenLayers style
我在ol.StyleFunction
设置了ol.StyleFunction
。
function style(feature: ol.Feature, resolution: number): ol.style.Style {
return ol.style.Style({
// stuff from the feature properties
});
}
并非所有功能都包含自己的样式信息。 在这种情况下,我想回到默认样式。
function style(feature: ol.Feature, resolution: number): ol.style.Style {
if (!hasOwnStyle(feature)) {
// defaultStyle is private :(
return ol.style.Style.defaultStyle();
}
return ol.style.Style({
// stuff from the feature properties
});
}
有没有办法访问默认样式?
您可以返回默认样式
import style from 'ol/style';
var fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)'
});
var stroke = new ol.style.Stroke({
color: '#3399CC',
width: 1.25
});
var styles = [
new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
];
如文档中所示 。
返回默认样式的样式函数将分配给新创建的矢量图层。 您可以通过运行该函数来获取样式数组
var defaultStyles = new ol.layer.Vector().getStyleFunction()();
编辑样式是一个需要具有几何特征的功能
var defaultEditingStyleFunction = new ol.interaction.Select().getOverlay().getStyleFunction();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.