OpenLayers 3 multiple feature selection -


i use click interaction select multiple features , show division names.

using following code, if add new feature (using shift key) infobox2 updated additional feature name (division) repeated again in infobox2 when try remove feature selection (with altkey).

i whould deselect feature , have division name removed infobox2. how possible? thanks

var infobox2 = document.getelementbyid('info2');      var selectclick = new ol.interaction.select({        addcondition: ol.events.condition.shiftkeyonly ,     togglecondition: ol.events.condition.never,     removecondition: ol.events.condition.altkeyonly, });   select = selectclick;   map.addinteraction(select);  var features = select.getfeatures();     var info = [];  var displayfeatureinfoclick = function(pixel) {     var features = [];     map.foreachfeatureatpixel(pixel, function(feature, layer) {          features.push(feature);      });      if ( features.length > 0) {         (var = 0, ii = features.length; < ii; ++i) {             info.push(features[i].get('division'));         }         infobox2.innerhtml = info.join(', ');     } else {         infobox2.innerhtml = '&nbsp;';     } };  map.on('click', function(evt) {     displayfeatureinfoclick(evt.pixel);  });  

as understand it, wish keep track of (and display information about) features selected select interaction.

if that's case, don't handle click events yourself. use events provided ol.interaction.select.

the select interaction emits ol.selectevent each time selection changes. replace displayfeatureinfoclick with

select.on('select', function() {     var info = [];      this.getfeatures().foreach(function(feature){         info.push(feature.get('division'));     });      infobox2.innerhtml = info.length ? info.join(', ') : '&nbsp;'; }); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -