Добавить несколько объектов в векторный слой по нажатию OpenLayers 5 Typescript - PullRequest
1 голос
/ 16 мая 2019

Я пытаюсь добавить объекты в слой по щелчку, и я добился успеха, но кажется, что при добавлении объекта другая функция скрывается?

Я создаю части нужного мне слоя ...

    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);

 }

Я добавляю свою функцию в коллекцию

 mapValues.highlightCollection.push(Feature1);

это будет добавлено, и стиль будет отображаться для "Feature 1", но последовательный вызов этого добавит еще одну функцию ...

mapValues.highlightCollection.push(Feature2);

Feature2 появится, а Feature1 останется в коллекции, но Feature1 потеряет свой стиль или будет скрыт ... Я не уверен?

Любая помощь очень ценится!

...