简体   繁体   English

在OpenLayers中,将1层保留在另一层之上。 (Z轴)

[英]In OpenLayers, Getting 1 Layer to stay over the other. (Z-Axis)

I have this map, which I show some red markers over and whenever a location is chosen from a list the current marker is painted blue and the map centers around it. 我有这张地图,在它上面显示一些红色标记,并且每当从列表中选择一个位置时,当前标记就会被涂成蓝色 ,并且地图会围绕它居中。

I achieve this by having 2 layers - one for the red markers which is drawn at the beginning and one which is redrawn whenever a point is chosen from the list. 我通过两层来实现此目的-一层是在开始时绘制的红色标记,另一层是从列表中选择一个点时都会重新绘制的标记。 在此处输入图片说明

I would like to define that the red marker layer will always appear above the blue marker layer. 我想定义红色标记层将始终出现在蓝色标记层上方。 Effectively hiding the "current marker" indication. 有效隐藏“当前标记”指示。 (The reason for this is complicated) (原因很复杂)

This link is to a page that works the way I don't want. 该链接指向的页面以我不想要的方式工作。 The blue layer is on top of the red layer. 蓝色层位于红色层的顶部。 I tried to reverse the order by defining the graphicZIndex property for both the vector and in the layers.addFeature function. 我试图通过定义vector和layers.addFeature函数的graphicZIndex属性来颠倒顺序。

I'm obviously doing something wrong and maybe someone can point me to what it is. 我显然做错了什么,也许有人可以指出我的意思。 The way I define the z-axis: 我定义z轴的方式:

        currentPointLayer = new OpenLayers.Layer.Vector("Selected Point Layer", {
            style : {
                externalGraphic : 'marker-blue.png',
                graphicHeight : 15,
                graphicWidth : 15,
                graphicZIndex : 1
            },
            rendererOptions: { zIndexing: true }
        });

Again , I want to hide the blue marker behind the red markers layer. 同样 ,我想将蓝色标记隐藏在红色标记层后面。

You can either change the order of your layers as ilia choly stated. 您可以按照ilia choly所述更改图层的顺序。

Or, if you want to use zIndexing, you have to put all features into one layer , because zIndexing is only done within a single layer. 或者,如果要使用zIndexing,则必须将所有要素放到一个图层中 ,因为zIndexing仅在单个图层中完成。

Have a look at this simple example about styling, that also uses zIndexing. 看一下有关样式的简单示例该示例也使用zIndexing。 It randomly creates some points in the map. 它在地图中随机创建一些点。 If you zoom out, chances are good that two circles overlap and if you hoover over one, it will be highlighted and put on top. 如果缩小,则很有可能两个圆圈重叠,如果将鼠标悬停在一个圆圈上,它将突出显示并放在顶部。

So you want highlight a marker with different color whenever a point is selected? 因此,无论何时选择一个点,都希望突出显示具有不同颜色的标记? Managing it with 2 layers is really an overkill. 用2层管理它确实是一个过大的杀伤力。 You should be able to define a vector layer with style like this: 您应该能够使用以下样式定义矢量层:

var currentPointLayer = new OpenLayers.Layer.Vector("Selected Point Layer", {
    styleMap: new OpenLayers.StyleMap({
        externalGraphic : '${markerUrl}',
        pointRadius: 20
})});
map.addLayer(currentPointLayer);

Then you have to set attribute 'markerUrl' of every feature(ie feature.attributes.markerUrl) to 'marker-red.png' - that would be initial state of all features. 然后,您必须将每个功能的属性“ markerUrl”(即feature.attributes.markerUrl)设置为“ marker-red.png”-这将是所有功能的初始状态。

Then whenever feature is selected you change markerUrl attribute of selected feature to 'marker-blue.png' and(important) call 然后,只要选择了特征,就将选定特征的markerUrl属性更改为'marker-blue.png'和(重要)调用

currentPointLayer.redraw(); currentPointLayer.redraw();

Obviously you'll also have to set previously selected feature to 'marker-red.png' when new feature is selected. 显然,在选择新功能时,您还必须将先前选择的功能设置为“ marker-red.png”。

in your init_map() function you're adding the red marker layer before the blue ones. 在您的init_map()函数中,您要在蓝色标记层之前添加红色标记层。 Try switching them. 尝试切换它们。

preparePointsOnMap(map, points); //red marker

if (!map.getCenter()) {
    map_set_center(lon, lat, mZoom); //blue marker
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM