Please take a look at code: https://plnkr.co/edit/wF8VZnnLtRLHPkfrKGu5?p=preview (OpenLayers v.3.8.2)
I would like to retrieve GeoJSON property "zoom". I guess it would be something like this but dont know where to put it in a code:
var zoom = function(feature){ var zoomGeojson = feature.get("zoom"); console.log(zoomGeojson); } And then I would like to compare zoom level of the map to the GeoJSON property "zoom". If they would match, I would like to visualize only that geojson data. (for example: mapzoomlevel = 5, if mapzoomlevel = geojsonpropertyzoom visualize only data from geojson that contains property "zoom"=5)
Edit
Based on @Hicham Zouarhi answer.
I ran into two problems.
1.Code below throws me an error:
var tmpLayer= new ol.layer.Vector(); map.addLayer(tmpLayer); source.forEachFeature(function(feature){ var mapzoom = map.getView().getZoom(); var geojsonzoom = feature.get("zoom"); console.log('MapZoom ' + mapzoom); console.log('GeoJSONZoom ' + geojsonzoom); if(geojsonzoom == mapzoom){ console.log('GeoJSON zoom property and map zoom are equal!'); tmpLayer.getSource().addFeatures(feature); // error: Uncaught TypeError: Cannot read property 'addFeatures' of null(…) } else { console.log('Not equal!'); } }); - Without that error it runs smoothly in a console, however it does not run in my code at all. I guess I am missing something or the order is not right.
I have reorganized code by breaking it into a smaller pieces: https://plnkr.co/edit/DeaVFGBK11jKCT3yHAVd