Javascript 访问默认OpenLayers样式
我在一个图层上设置了一个Javascript 访问默认OpenLayers样式,javascript,openlayers-3,Javascript,Openlayers 3,我在一个图层上设置了一个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, r
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();
您是否尝试了返回特性.getStyle()代码>??????如果不提供,则应指定。@pavlos正确,好主意!