单击OpenLayers 5 Typescript向矢量层添加多个功能

单击OpenLayers 5 Typescript向矢量层添加多个功能,openlayers,openlayers-3,openlayers-5,Openlayers,Openlayers 3,Openlayers 5,我试图在单击时向图层添加功能,我已经成功了,但是当添加一个功能时,另一个功能似乎被隐藏了 我创建我需要的层的部分 public static highlightOverlay = new olLayerVector({}); public static highlightCollection: olCollection = new olCollection(); public static highlightVectorSource: olSourceVe

我试图在单击时向图层添加功能,我已经成功了,但是当添加一个功能时,另一个功能似乎被隐藏了

我创建我需要的层的部分

    public static highlightOverlay = new olLayerVector({});        
    public static highlightCollection: olCollection = new olCollection();
    public static highlightVectorSource: olSourceVector = ({features:mapValues.highlightCollection})
我创建了将在其上显示特征的图层

public static addHighlightOverlay(){
let highlightStyleCache = {}; 
mapValues.highlightVectorSource = new olSourceVector({
  features: mapValues.highlightCollection
 })
mapValues.highlightOverlay = new olLayerVector({
source: mapValues.highlightVectorSource,
map: mapValues.map,
style: function(feature,resolution){
 let text = resolution * 100000 < 10 ? feature.get('text') : '';
 if(!highlightStyleCache[text]){
   highlightStyleCache[text] = new Style({
     stroke: new Stroke({color: '#ffcc33', width:2}),
     fill: new Fill({color: 'rgba(255,255,255,0.2'}),
     text: new Text({
       font: '12px Calibri,sans-serif',
       text: text,
       fill: new Fill({
         color: '#000'
       }),
       stroke: new Stroke({
         color: '#f00',
         width: 3
       }),
       zIndex: 10000})
   })
 }

 return highlightStyleCache[text]

 }


 })     
 mapValues.highlightOverlay.setMap(mapValues.map);

 }
这将被添加,样式将显示在“功能1”中,但对它的连续调用将添加另一个功能

mapValues.highlightCollection.push(Feature2);
Feature2将出现,Feature1将保留在收藏中,但Feature1将失去其风格或将被隐藏…我不确定

非常感谢您的帮助

mapValues.highlightCollection.push(Feature2);