openlayers 矢量特征 z 索引
我很难理解矢量特征的 z 索引。
当我在网上搜索信息时,我发现了这些链接: http://openlayers.org/dev/examples/ordering.html http://osgeo-org.1803224.n2 .nabble.com/Bug-in-using-graphicZIndex-td2648665.html 和 http://osgeo-org.1803224.n2 .nabble.com/graphicZIndex-of-vector-features-td3919627.html
我所做的是设置样式,如第一个链接上所示:
this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
styleMap: new OpenLayers.StyleMap({
"default": {
'strokeColor': "#ff9933",
'strokeWidth': 5
},
"select": {
'strokeColor': "#3399ff"
}
})
}
);
this.carsLayer = new OpenLayers.Layer.Vector("Cars", {'rendererOptions': {yOrdering: false, zIndexing: true}});
this.startIconStyle = {'externalGraphic':this.startIconUrl};
this.parkIconStyle = {'externalGraphic':this.parkIconUrl};
this.endIconStyle = {'externalGraphic':this.endIconUrl};
this.defaultStyles = {
//'label':getLabel(),
'graphicZIndex':745,
'graphicXOffset':-13,
'graphicYOffset':-41,
'graphicWidth':26,
'graphicHeight':41,
'strokeLinecap':'round',
'strokeColor':"#000000",
'strokeWidth':2,
'strokeOpacity':1,
'fillOpacity':1}
//style of path that car has used
this.drivedStyle = {
'strokeWidth': 3,
'strokeOpacity': 1,
'strokeColor': "#3399ff",
'strokeDashstyle': "dash"
}
当我创建标记时,我会这样做:
var routePoint = this.points[this.routePos].clone();
var newstyleSite = OpenLayers.Util.extend(this.startIconStyle, this.defaultStyles ,OpenLayers.Feature.Vector.style['default']);
this.routePointFeature = new OpenLayers.Feature.Vector(routePoint, {}, newstyleSite);
this.vectorsLayer.addFeatures(this.routePointFeature);
当我查看该标记的 z 索引 - z 索引设置为 auto 而不是 745,它位于 this.defaultStyles 中。
这将我们带到第三个链接......我根本无法理解,因为其他地方的设置样式给出的效果与我现在得到的一样多。
两者都没有
this.routePointFeature.attributes.zIndex = 745;
改变任何事情。尽管它显然适用于第一个链接/示例。
这个 z 索引应该如何工作?为什么它在我的情况下不起作用?我做错了什么?或者是那里有什么东西被窃听了?
编辑:很多人都看过这个问题并赞成答案。然而我不得不处理其他事情,并且已经有一段时间没有使用 oplayers 了。有些看过这个答案的人可以确认这个答案有效,这样我就可以接受它吗?
艾伦
Im having hard time trying to understand the z-indexing of the vector features.
When i was searching the web for info i found these links:
http://openlayers.org/dev/examples/ordering.html
http://osgeo-org.1803224.n2.nabble.com/Bug-in-using-graphicZIndex-td2648665.html
and
http://osgeo-org.1803224.n2.nabble.com/graphicZIndex-of-vector-features-td3919627.html
What i did, was setting up styles like they are shown on first link:
this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
styleMap: new OpenLayers.StyleMap({
"default": {
'strokeColor': "#ff9933",
'strokeWidth': 5
},
"select": {
'strokeColor': "#3399ff"
}
})
}
);
this.carsLayer = new OpenLayers.Layer.Vector("Cars", {'rendererOptions': {yOrdering: false, zIndexing: true}});
this.startIconStyle = {'externalGraphic':this.startIconUrl};
this.parkIconStyle = {'externalGraphic':this.parkIconUrl};
this.endIconStyle = {'externalGraphic':this.endIconUrl};
this.defaultStyles = {
//'label':getLabel(),
'graphicZIndex':745,
'graphicXOffset':-13,
'graphicYOffset':-41,
'graphicWidth':26,
'graphicHeight':41,
'strokeLinecap':'round',
'strokeColor':"#000000",
'strokeWidth':2,
'strokeOpacity':1,
'fillOpacity':1}
//style of path that car has used
this.drivedStyle = {
'strokeWidth': 3,
'strokeOpacity': 1,
'strokeColor': "#3399ff",
'strokeDashstyle': "dash"
}
And when i create markers, i do it like that:
var routePoint = this.points[this.routePos].clone();
var newstyleSite = OpenLayers.Util.extend(this.startIconStyle, this.defaultStyles ,OpenLayers.Feature.Vector.style['default']);
this.routePointFeature = new OpenLayers.Feature.Vector(routePoint, {}, newstyleSite);
this.vectorsLayer.addFeatures(this.routePointFeature);
And when i look at the z-index of that marker - z-index is set to auto not 745, which is in this.defaultStyles.
This brings us to 3rd link... which i cant understand at all, cause setting styles anywhere else gives exactly as much, as im getting right now.
Neither does
this.routePointFeature.attributes.zIndex = 745;
change anything at all. Even though it apparently works on that first link/example.
How is this z-indexing supposed to work? And why doesnt it work in my case? What am i doing wrong? Or is something bugged there?
Edit: Alot of people have viewed this question and upvoted the answer. Yet i have had to deal with other stuff and have not worked with opelayers for a while now. Can some people who have seen this answer confirm that the answer works so i can accept it?
Alan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须为矢量图层启用 z 索引。
另外,OpenLayers.Util.extend只接受两个参数,第一个参数是目的地(即第二个参数源将被合并到其中)。如果要组合多个对象,可以使用 jQuery.extend 或多次调用 OpenLayers.Util.extend:
或者
这两者都会导致 this.startIconStyle 包含 this.startIconStyle、OpenLayers.Feature.Vector.style[ 的并集'default'] 和 this.defaultStyles。
您真正想要的是:
You have to enable z-indexing for the vector layer.
Additionally, OpenLayers.Util.extend only takes two parameters, and the first parameter is the destination (i.e., the second parameter, source, will be combined into it). If you want to combine multiple objects, you can use jQuery.extend or multiple calls to OpenLayers.Util.extend:
or
Both of these will result in this.startIconStyle containing the union of this.startIconStyle, OpenLayers.Feature.Vector.style['default'], and this.defaultStyles.
What you may really want is: