javascript - OpenLayers 3: how to set fill style of a vector feature -
i trying set fill colour of seperate features of vector layer. using code below, thought able iterate through features , set fill style individually, strange issue happens. without setstyle function, various properties of features logged in console. id, name , geometry. there 5 or features logged. like
room1 room2 room3 room4 room5
with data underneath each 1 (id, geometry)
but when add line setting fill of feature, strange problem. seems hang loop on first feature , console fills logs of features properties, like:
room1 room1 room1 room1 room1 room1 room1
for long time, point firefox log limit reached , tells me 2000 entries not shown!
but on plus side, first feature fill colour changed! think line of code used @ least half right! there definately drastically wrong it.
the code:
vector.getsource().on('change', function (evt) { var source = evt.target; if (source.getstate() === 'ready') { var features = vector.getsource().getfeatures() (var k in features) { console.log(features[k].getproperties()['name']); console.log(features[k].getproperties()['id']); console.log(features[k].getgeometry()['n']); features[k].setstyle(new ol.style.style({fill: fill})); } } });
i not know ol3 or styling features , arrived @ through lot of trial , guessing. can point me in right direction?
so, here your plunk modified.
first of all, unless have specific reason, use latest library version. main reason kml not loading.
and secondly, setfill
became this:
vector.getsource().foreachfeature(function(feature){ console.log(feature.getproperties()); style = new ol.style.style({ //i don't know how color of kml fill each room //fill: new ol.style.fill({ color: '#000' }), stroke: new ol.style.stroke({ color: '#000' }), text: new ol.style.text({ text: feature.get('name'), font: '12px calibri,sans-serif', fill: new ol.style.fill({ color: '#000' }), stroke: new ol.style.stroke({ color: '#fff', width: 2 }) }) }); feature.setstyle(style); });
Comments
Post a Comment