无论如何,是否可以在单层上指定特征的z顺序? [英] Is there anyway to specify z-order of feature on single layer?
本文介绍了无论如何,是否可以在单层上指定特征的z顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用具有三个功能的单层,并且想指定z顺序,但是无论如何都无法正常工作.
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.
添加功能的代码
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);
图层的样式功能
//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]];
}
推荐答案
最后我得到了解决方案,这是将重新排列功能z-index的最终样式功能.
Finally I got solution,Here is the final style function that will rearrange feature z-index.
`
//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
}),
zIndex: zIndexValue
});
}
// at this point, the style for the current level is in the cache
// so return it (as an array!)
return [styleCache[level]];
}`
您可以在此处查看示例 http://bl.ocks.org/wboykinm/cc509eb2763ca1ba9293
you can check example here http://bl.ocks.org/wboykinm/cc509eb2763ca1ba9293
这篇关于无论如何,是否可以在单层上指定特征的z顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文