访问默认 OpenLayers 样式

Ili*_*oly 6 javascript openlayers-3

ol.StyleFunction在图层上有一组。

function style(feature: ol.Feature, resolution: number): ol.style.Style {
  return ol.style.Style({
    // stuff from the feature properties
  });
}
Run Code Online (Sandbox Code Playgroud)

并非所有功能都包含自己的样式信息。在这种情况下,我想退回到默认样式。

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
  });
}
Run Code Online (Sandbox Code Playgroud)

有没有办法访问默认样式?

Doc*_*tor 3

您可以设置回默认样式

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
   })
 ];
Run Code Online (Sandbox Code Playgroud)

如文档所示。