簡體   English   中英

訪問默認的OpenLayers樣式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM