openlayers 矢量特征 z 索引

发布于 2024-10-17 17:58:40 字数 2745 浏览 1 评论 0原文

我很难理解矢量特征的 z 索引。

当我在网上搜索信息时,我发现了这些链接: http://openlayers.org/dev/examples/ordering.html http://osgeo-org.1803224.n2 .nabble.com/Bug-in-using-graphicZIndex-td2648665.htmlhttp://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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2024-10-24 17:58:40

您必须为矢量图层启用 z 索引。

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 );

You have to enable z-indexing for the vector layer.

this.vectorsLayer = new OpenLayers.Layer.Vector("Vectors", {
  styleMap: <your style map>,
  rendererOptions: { zIndexing: true }
});

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:

OpenLayers.Util.extend(this.startIconStyle, OpenLayers.Feature.Vector.style['default'] );
OpenLayers.Util.extend( this.startIconStyle, this.defaultStyles );

or

jQuery.extend( this.startIconStyle, OpenLayers.Feature.Vector.style['default'], this.defaultStyles );

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:

var newstyleSite = {};
jQuery.extend( newstyleSite,  OpenLayers.Feature.Vector.style['default'], this.defaultStyles, this.startIconStyle );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文