簡體   English   中英

如何在openlayers中設置點數4

[英]How to style points in openlayers 4

我正在嘗試在OpenLayers 4中的矢量源中設置點的樣式。

我定義了一種風格:

var pStyle = new ol.style.Style({
          stroke: new ol.style.Stroke({
          width: 6, color: [255, 0, 0, 1]
          })
});

並在圖層定義中添加了樣式

var pLayer = new ol.layer.Vector({
        source: new ol.source.Vector({
          features: [p]
        }),
        style: pStyle
});

注釋樣式定義使得該點出現在地圖上,所以我假設其余的代碼都沒問題。 但我無法明白地圖上的紅色。

小提琴: https//codepen.io/fundef/pen/VXKYjP

我哪里錯了?

如果你想使用fillstroke

    var myStyle = new ol.style.Style({
      image: new ol.style.Circle({
        radius: 7,
        fill: new ol.style.Fill({color: 'black'}),
        stroke: new ol.style.Stroke({
          color: [255,0,0], width: 2
        })
      })
    })

你可以使用ol.style.icon

這是一個例子:

<script>

iconFeature.setStyle(new ol.style.Style({
        image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
          color: '#8959A8',
          crossOrigin: 'anonymous',
          src: 'https://openlayers.org/en/v4.6.4/examples/data/dot.png'
        }))
      }));

<script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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