Odi*_*aeb 3 javascript openlayers
我很难尝试理解矢量特征的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"
}
Run Code Online (Sandbox Code Playgroud)
当我创建标记时,我会这样做:
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);
Run Code Online (Sandbox Code Playgroud)
当我查看该标记的z-index时,z-index设置为auto而不是745,它位于this.defaultStyles中.
这给我们带来了第三个链接...我完全听不懂,导致其他任何地方的设置风格完全一样,就像我现在所说的那样.
也没有
this.routePointFeature.attributes.zIndex = 745;
Run Code Online (Sandbox Code Playgroud)
改变一切.即使它显然适用于第一个链接/示例.
这个z索引应该如何工作?为什么它在我的情况下不起作用?我究竟做错了什么?或者有什么问题吗?
编辑:很多人都看过这个问题,并对答案进行了评价.然而,我不得不处理其他事情,并且暂时没有与opelayers合作.有些人看过这个答案可以证实答案是有效的,所以我可以接受吗?
艾伦
您必须为矢量图层启用z-indexing.
this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
styleMap: <your style map>,
rendererOptions: { zIndexing: true }
});
Run Code Online (Sandbox Code Playgroud)
此外,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 );
Run Code Online (Sandbox Code Playgroud)
要么
jQuery.extend( this.startIconStyle, OpenLayers.Feature.Vector.style['default'], this.defaultStyles );
Run Code Online (Sandbox Code Playgroud)
这两个都将导致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 );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8656 次 |
| 最近记录: |