简体   繁体   English

如何在openlayers中设置点数4

[英]How to style points in openlayers 4

I'm trying to style points in a vector source in OpenLayers 4. 我正在尝试在OpenLayers 4中的矢量源中设置点的样式。

I've defined a style: 我定义了一种风格:

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

and added the style in the layer definition 并在图层定义中添加了样式

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

Commenting the style definition makes the point appear on the map so I'm assuming the rest of the code is fine. 注释样式定义使得该点出现在地图上,所以我假设其余的代码都没问题。 But I can't get my point to appear in red on the map. 但我无法明白地图上的红色。

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

Where am I going wrong? 我哪里错了?

If you want to use fill and stroke 如果你想使用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
        })
      })
    })

You can use ol.style.icon for that. 你可以使用ol.style.icon

This is a example: 这是一个例子:

<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