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
},
'geometry': {
'type': 'Point',
'coordinates': [x, y]
}
Every value in a field in this JSON with the format "number_number_string" has to be in a different layer. E.g. 22_9_kw3 has to be in it's own layer, just as 18_22_kw4. The result will look look like this:
As you can see in my example, there are multiple points displayed. Each point has it's own layer, but all the data is in 1 (see above) GeoJSON file.
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?
EDIT
To illustrate this further, I explain what you see in my JSON:
- ["9_13_kw1"] = the "name" of the property
- [513585.0] = the value of the property, this value is the radius of the displayed circle (divided by a factor ofc.)
The points represent a sensor-point on the map. The value represents the measured value of that sensor. The more measured, the bigger the circle.
To display all these circles I have to create a layer of EACH of these "name"-value combinations.
Every coordinate will have thus 16 different layers: 4x ..kw1, 4x ..kw2, 4x ..kw3 and 4x ..kw4.
Best Answer
UPDATE: Trying to formulate an answer:
Load you json file with some AJAX function (a custom one here), and add to a new
ol.layer.Vector
depending on some parameter, called herecategory
:Missing
functions
see http://jsfiddle.net/jonataswalker/z10de36z/.Original answer
There is somewhat not OK with your logic. Take this GeoJSON object for example:
This part (below) is a feature:
But when you say "Every value in a field in this JSON with the format "22_9_kw1" has to be in a different layer.", you are trying to add a single feature to several layers, I think this is not what you want.
I think you should have a single
property
like acategory
to add the feature to different layer based on it.