简体   繁体   中英

Openlayers 4 set style clear feature

if set style, features doesn't display

new ol.layer.Vector({
source: vectorSource1,
style: new ol.style.Style({
    stroke: new ol.style.Stroke({
            color: 'red'
        })  
    })
})

if clear styling

new ol.layer.Vector({
source: vectorSource1
})

all display ok

var featurething = new ol.Feature({
        });
        featurething.setGeometry(new ol.geom.Point( ol.proj.fromLonLat([29, 29]) ));
        //console.log(value);
        vectorSource1.addFeature( featurething );

See default ol.style of ol.layer.Vector http://openlayers.org/en/latest/apidoc/ol.style.html

stroke needs some shape of feature such as circle, polygon, etc,. simple ol.geom.point doesn't have a shape. that's why nothing appears when you set style only with stroke

If you change your style like below, it will work as you expect:

var style = new ol.style.Style({
  image: new ol.style.Circle({ // add this
    stroke: new ol.style.Stroke({
      color: 'red'
    }),
    radius: 5
  }),
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM