ol3 - setStyle(null) if row is not visible in attribute table

المشرف العام

Administrator
طاقم الإدارة
I have a map showing points, and a table which lists the attributes of the features shown in the map.

I am trying to remove features from the map which are not visible in the table. As such, when the table is changed, an array of unique values ('DocumentID') representing the visible rows is stored in the 'data' array. My intention is to change the style of all the features not visible in the table (i.e. whose unique ID is not in the 'data' array) to null.

The code I have so far is

var table = $('#mainTable').DataTable();table.on('draw.dt search.dt stateLoaded.dt', function (){ var data = table.columns(0).data(); function styleFunction() { var ruleStyle = [new ol.style.Style({ fill: new ol.style.Fill({color: 'olive'}), stroke: new ol.style.Stroke({color: 'black', width: 1}) })]; return function(feature, resolution) { if ( $.inArray(feature.get('DocumentID'), data[0]) > -1) { return ruleStyle; } else { return null; } }; }; wayleavesLayer.setStyle(styleFunction);});Unfortunately, I keep getting the error Uncaught TypeError: Cannot read property 'f' of undefined, suggesting that the 'feature' is undefined. I am not sure why the feature is undefined - my code seems to follow the same format as that at http://openlayers.org/ol3-workshop/vector-style/style.html

How can I change the style of the features in wayleavesLayer to null which are not visible in the table?



أكثر...
 
أعلى