I am using single layer with three feature and would like to specify z-order but not working anyway.
As per my understanding feature is drawing in same order in which I am adding so I tried by adding in reverse order but it not worked for me.
Code to add feature
var features=[];
jQuery.each(data.route, function (key, val)
{
var localfeature = new ol.Feature({ geometry: objGeoJSON.readGeometry(JSON.parse(val.simpleRoute)).transform('EPSG:4326', 'EPSG:3857') });
localfeature.set("rtype", "R" + (key + 1));
features.push(localfeature);
});
currentRoute.routingSource.addFeatures(features);
Style function of layer
//function to apply color based on rtype attribute.
function styleFunction(feature, resolution) {
var level = feature.get('rtype');
if (!level || !RouteType[level]) {
return [defaultStyle];
}
if (!styleCache[level]) {
styleCache[level] = new ol.style.Style({
stroke: new ol.style.Stroke({
color: RouteType[level],
width: 4
})
});
}
// at this point, the style for the current level is in the cache
// so return it (as an array!)
return [styleCache[level]];
}
Finally I got solution,Here is the final style function that will rearrange feature z-index.
`
you can check example here http://bl.ocks.org/wboykinm/cc509eb2763ca1ba9293