OpenLayers 3 (3.3.0) Select Feature one at a time -


using openlayer 3.3.0, have map divided counties, each county 'feature', want select feature , change border colour, when select feature, want selected feature revert original style , new feature have selected style applied.

so use add interactions.

var select = new ol.interaction.select({              condition: ol.events.condition.click,         }); select.on('select', function(evt){     var features = evt.target.getfeatures();     features.foreach(function(feature){         feature.setstyle(new ol.style.style({                 stroke: new ol.style.stroke({                     color: '#007aa9',                     width: 1.5;                 }))     } }) map.addinteraction(select); 

this works fine, doesn't 'unselect' selected feature, if click around features select style

the way can seem fix is, set 'previouslyselectedfeature' variable, , reset style in 'on' event, seems bit clunky though, shouldn't there way detect when feature has been 'unselected' , reset style?

would appear solution might update version 3.4 (it doesn't work in 3.3) , access 'selected' , 'deselected' properties. refactored event code

            select.on('select', function(evt){                 var selectedfeatures = evt.selected;                 selectedfeatures.foreach(function(feature){                     feature.setstyle(new ol.style.style({                         stroke: new ol.style.stroke({                         color: '#007aa9',                         width: 1.5;                        }));                 });                 var deselectedfeatures = evt.deselected;                 deselectedfeatures.foreach(function(feature){                     feature.setstyle(new ol.style.style({                         stroke: new ol.style.stroke({                         color: '#000000',                         width: 0.4;                        })                     })                 });             }); 

right or wrong?


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -