在 OpenLayers 中,让一层保持在另一层之上。 (Z轴)
我有这张地图,上面显示了一些红色标记,每当从列表中选择一个位置时,当前标记就会涂成蓝色,并且地图以它为中心。
我通过使用两层来实现这一点 - 一层用于在开始时绘制的红色标记,另一层用于在从列表中选择一个点时重新绘制。
我想定义红色标记层将始终出现在蓝色标记层。有效隐藏“当前标记”指示。 (原因很复杂)
此链接是到一个页面这以我不想要的方式工作。蓝色层位于红色层之上。 我尝试通过为向量和 Layers.addFeature 函数定义 GraphicZIndex 属性来颠倒顺序。
我显然做错了什么,也许有人可以指出我错了什么。 我定义 z 轴的方式:
currentPointLayer = new OpenLayers.Layer.Vector("Selected Point Layer", {
style : {
externalGraphic : 'marker-blue.png',
graphicHeight : 15,
graphicWidth : 15,
graphicZIndex : 1
},
rendererOptions: { zIndexing: true }
});
再次,我想将蓝色标记隐藏在红色标记层后面。
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.
I'm obviously doing something wrong and maybe someone can point me to what it is.
The way I define the z-axis:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的
init_map()
函数中,您将在蓝色标记层之前添加红色标记层。尝试切换它们。in your
init_map()
function you're adding the red marker layer before the blue ones. Try switching them.您可以按照 ilia Choly 的说明更改图层的顺序。
或者,如果您想使用 zIndexing,则必须将所有功能放入一个层,因为 zIndexing 仅在单个层内完成。
看看这个关于样式的简单示例,它也使用了 zIndexing。它在地图上随机创建一些点。如果缩小,两个圆圈很可能会重叠,如果将鼠标悬停在一个圆圈上,它将突出显示并放在顶部。
You can either change the order of your layers as ilia choly stated.
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.
Have a look at this simple example about styling, that also uses 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.
那么您想在选择一个点时用不同的颜色突出显示标记吗?用 2 层来管理它确实是大材小用。您应该能够定义具有如下样式的矢量图层:
然后您必须将每个要素(即 feature.attributes.markerUrl)的属性“markerUrl”设置为“marker-red.png” - 这将是所有要素的初始状态特征。
然后,每当选择功能时,您都将所选功能的markerUrl属性更改为“marker-blue.png”并(重要)调用
显然,当选择新功能时,您还必须将先前选择的功能设置为“marker-red.png”。
So you want highlight a marker with different color whenever a point is selected? Managing it with 2 layers is really an overkill. You should be able to define a vector layer with style like this:
Then you have to set attribute 'markerUrl' of every feature(i.e. feature.attributes.markerUrl) to 'marker-red.png' - that would be initial state of all features.
Then whenever feature is selected you change markerUrl attribute of selected feature to 'marker-blue.png' and(important) call
Obviously you'll also have to set previously selected feature to 'marker-red.png' when new feature is selected.