Angular Openlayers同一层上的不同颜色形状?

Angular Openlayers同一层上的不同颜色形状?,angular,openlayers,Angular,Openlayers,因此,我编写了代码,允许我向地图添加形状,绘图函数如下所示 addInteraction() { this.coreMap.map.addInteraction(this.modifyLayer); this.draw = new Draw({ source: this.vectorSource, style: this.style, type: 'Point' }); this.coreMap.map.addInterac

因此,我编写了代码,允许我向地图添加形状,绘图函数如下所示

  addInteraction() {
    this.coreMap.map.addInteraction(this.modifyLayer);
    this.draw = new Draw({
      source: this.vectorSource,
      style: this.style,
      type: 'Point'
    });
    this.coreMap.map.addInteraction(this.draw);
    this.snap = new Snap({source: this.vectorSource});
    this.coreMap.map.addInteraction(this.snap);
  }
这很好,让我在地图上画ect,但是如果我尝试改变矢量层上的样式,比如说从一个绿色的点到一个红色的点,它会把每个点都变成红色,而不是新的,我已经尝试了一些事情

  • 尝试将新的styles对象推入vectorLayer.styles和setStyle([styleOneOpts,styleTwoOpts])

  • 将Draw属性的style属性设置为不同的颜色,这会将光标更改为所述颜色,但绘制的点仍然是vectorLayers样式颜色

  • 尝试创建一个新的绘图对象,并将其作为一个全新的交互添加到地图中


目前,我认为每次我想用不同的颜色创建一个新形状时,我都必须创建一个新的层,如果没有办法,这是很好的,但我更希望它保持在一个层内

您可以为每个新创建的功能设置样式,或者为每个功能设置颜色属性,例如
feature.set('color','red')并对图层使用样式功能。这将使用功能上设置的颜色,如果未设置,则默认为黑色

style: function(feature) {
  return new Style({

    ...

      color: feature.get('color') || 'black',

   ...

  })
}