是否仍然可以指定单层上特征的z顺序
Is there anyway to specify z-order of feature on single layer?
我使用的是带有三个功能的单层,我想指定z顺序,但无论如何都不能工作。
根据我的理解,功能是按照我添加的相同顺序绘制,所以我尝试按相反的顺序添加,但对我不起作用。
添加功能的代码
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索引的最终样式函数。
`
//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
相关文章:
- ajax请求的顺序总是不同的
- 按照选项卡索引的顺序循环一个jQuery选择
- 匹配一个单词,其中候选人可以跨越顺序组(跨度)
- 按顺序添加和删除类
- 按我自己的类克隆另一个元素的内容和顺序
- Javascript-根据赋值顺序,按键合并对象数组
- 2个backbone.js集合,具有相同的模型,但排序顺序不同
- querySelector/getElementByClassName嵌套项的顺序
- 以不同的顺序输出数据
- 重新排列HTML元素的顺序并更改内容
- 更改图层中单个矢量特征的图标
- 在Javascript中列出顺序子集元素
- 是否“;对于的“;循环迭代遵循JavaScript中的数组顺序
- Mongodb$in以与数组中相同的顺序获取结果
- 如何使用phonegap从安卓设备中提取联系人的字母顺序
- 在表单OnChange中交换数字顺序
- 如何按对象反转Angular ngRepeat的顺序's键,这些键是数字键
- 预保存钩子:mongoose中回调的顺序如何
- 为什么生成器中的console.log会按这样的顺序出现
- 是否仍然可以指定单层上特征的z顺序