openlayers矢量特征z-indexing
我很难试图理解矢量特征的z索引。openlayers矢量特征z-indexing
当我正在寻找的信息网络,我发现这些链接: 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-index - z-index被设置为auto而不是745,这是在this.defaultStyles中。
这给我们带来了第三个环节......我完全不理解,导致设置样式在其他地方给出的数量与我现在正在获取的数量完全一样。
也不对
this.routePointFeature.attributes.zIndex = 745;
改变任何事情。尽管它显然适用于第一个链接/示例。
z-indexing应该如何工作?为什么它不适用于我的情况?我究竟做错了什么?或者是在那里窃听?
编辑:很多人都看过这个问题,并提出了答案。然而我不得不面对其他的东西,现在还没有和opelayers合作过。可以看到这个答案的一些人确认答案有效,所以我可以接受它吗?
Alan
您必须为矢量图层启用z-indexing。
this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
styleMap: <your style map>,
rendererOptions: { zIndexing: true }
});
此外,仅OpenLayers.Util.extend需要两个参数,第一参数是目标(即,第二个参数,源,将被合并成它)。如果您希望将多个对象组合,您可以使用jQuery.extend或多次调用OpenLayers.Util.extend:
OpenLayers.Util.extend(this.startIconStyle, OpenLayers.Feature.Vector.style['default']);
OpenLayers.Util.extend(this.startIconStyle, this.defaultStyles);
或
jQuery.extend(this.startIconStyle, OpenLayers.Feature.Vector.style['default'], this.defaultStyles);
这两个将导致包含this.startIconStyle的this.startIconStyle的联合,OpenLayers.Feature.Vector.style ['default']和this.defaultStyles。
你可以真正想要的是:
var newstyleSite = {};
jQuery.extend(newstyleSite, OpenLayers.Feature.Vector.style['default'], this.defaultStyles, this.startIconStyle);