Openlayers 3: how to select a feature programmatically using ol.interaction.Select?

前端 未结 1 2408
别跟我提以往
别跟我提以往 2020-12-15 00:57

I\'m using OpenLayers v3.6 (this is important, because most of solutions that I found and would potentialy work are for OpenLayers 2).

I have a table and when

相关标签:
1条回答
  • 2020-12-15 01:46

    The way to do is in the linked question. So, push a ol.Feature into the selected collection:

    var select = new ol.interaction.Select({
        //some options
    });
    map.addInteraction(select);
    
    var selected_collection = select.getFeatures();
    selected_collection.push(featurePoint);
    

    If you want to trigger the select event:

    select.dispatchEvent('select');
    
    // OR
    
    select.dispatchEvent({
      type: 'select',
      selected: [featurePoly],
      deselected: []
    });
    

    See demo!

    0 讨论(0)
提交回复
热议问题