Openlayers-3 - 1 source, to create multiple layers?

المشرف العام

Administrator
طاقم الإدارة
I have an GeoJSON source with the following specifications:

"properties": { "sensorid": 500, "Locatie": "Prinsestraat 18", "9_13_kw1": 513585.0, "13_18_kw1": 806317.0, "18_22_kw1": 545899.0, "22_9_kw1": 477801.0, "9_13_kw2": 519198.0, "13_18_kw2": 800637.0, "18_22_kw2": 550001.0, "22_9_kw2": 514971.0, "9_13_kw3": 615974.0, "13_18_kw3": 916019.0, "18_22_kw3": 562191.0, "22_9_kw3": 575459.0, "9_13_kw4": 615016.0, "13_18_kw4": 967845.0, "18_22_kw4": 557373.0, "22_9_kw4": 559056.0, "Totaal": 10097342 }, Every value in a field in this JSON with the format "22_9_kw1" has to be in a different layer.

The only way I know how to do this is to create a lot (16) different ol.layer.Vector's and check the properties during styling. Like this:

var meetpuntenSource = new ol.source.Vector ({ url: 'points.geojson', format: new ol.format.GeoJSON() }); var meetpuntenObject1 = new ol.layer.Vector ({ source: meetpuntenSource, style: styleFunction }); var meetpuntenObject2 = new ol.layer.Vector ({ source: meetpuntenSource, style: styleFunction }); ect. With styleFunction:

var styleFunction = function(feature, resolution){ var properties = feature.getProperties(); if(meetpuntenObject2Toggle) {style = blablabla} I hope you get the idea. I want to be able to create different layers from the same source, because otherwise I have to load in a lot of the same data. Is there a better way?



أكثر...
 
أعلى