9

I've a layer with multiple markers with rather big icons, so they overlap. Via the list on the side of the map users can select a marker and the map will pan (and zoom) to it. But it will still be behind some other makers. How do I get a individual makers z-index and set it? I would be useful to get the highest used z-index and just add one. (another solution is to add the total number of markers to the z-index)

The markers (or features) are in a myLib.features array. The console doesn't show any z-index type functions.

I can't find a appropriate example or api function for this.

EDIT:

I found this example: http://dev.openlayers.org/examples/ordering.html I don't really understand it. Somehow the created feature takes the next z-index given by the layer via somekind of symbolizer. I have no idea how to work this static sort into a dynamic one.

4

1 回答 1

3

尝试这个:

首先,确保您使用的是 OpenLayers.Layer.Vector 图层,而不是 OpenLayers.Layer.Markers 图层。显然 Markers 层是旧消息,所有新的开发都是在 Vector 层中完成的。它有更多的功能。(我自己在标记层上浪费了很多时间)。

然后,您的每个标记都需要是一个 OpenLayers.Feature.Vector 对象。构造函数接受三个参数,其中第三个称为样式。样式是您设置图像属性、背景阴影、鼠标悬停文本和 z-index 的地方,它的属性名称为“graphicZIndex”。我想这就是你要找的。

http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.OpenLayers.Feature.Vector.style

使用 addFeatures 函数将“标记”(即矢量)添加到矢量层。并且忽略“选项”参数。

http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Layer/Vector-js.html#OpenLayers.Layer.Vector.addFeatures

我也找到了那个示例页面,我也觉得它很混乱。它在 Vector 层的构造函数中设置所有标记的样式(如果省略标记样式,则作为默认值使用)而不是标记的构造函数。我认为在标记构造函数中设置标记样式更有意义。

要实时更改样式,请使用您的 OpenLayers.Feature.Vector 标记之一,称为“标记”并执行此操作。我们称向量层为“层”。

marker.style.graphicZIndex = 13;
layer.redraw();
于 2012-07-30T16:17:58.763 回答