我有一个带有节点功能的图层,我可能想要显示两个图像,一个是主图像,一个是背景图像。这个页面:http://openlayers.org/dev/examples/marker-shadow.html显示我想要的东西:阴影在黄金项目下(当我们用开发工具移动png时更明显)。 为此,他们使用:
// Set the external graphic and background graphic images.
externalGraphic: "../img/marker-gold.png",
backgroundGraphic: "./img/marker_shadow.png",
// Makes sure the background graphic is placed correctly relative
// to the external graphic.
backgroundXOffset: 0,
backgroundYOffset: -7,
// Set the z-indexes of both graphics to make sure the background
// graphics stay in the background (shadows on top of markers looks
// odd; let's not do that).
graphicZIndex: MARKER_Z_INDEX, //11
backgroundGraphicZIndex: SHADOW_Z_INDEX, //10
显然,它不是真正的CSS z-index,因为DOM元素最终都有z-index: auto
。但无论如何,我想亲自尝试(不是在层结构,而是在之后):
style["backgroundGraphic"] = './img/marker-shadow.png';
style["externalGraphic"] ='./img/marker-gold.png';
style['graphicZIndex'] = 1;
style['backgroundGraphicZIndex'] = style['graphicZIndex']-1;
显示图像。但是,虽然人们可以认为backgroundGraphic会自动进入外部图形,但事实恰恰相反。好吧,我只是添加z-index的东西:
style['graphicZIndex'] = 1;
style['backgroundGraphicZIndex'] = style['graphicZIndex']-1;
但它绝对没有变化。如何获得我的背景?
答案 0 :(得分:0)
这有点棘手。样式和样式图是您的要素所在图层的属性。您应该定义样式,将它们放在样式图中并在图层构造中使用它。您可以通过更改特征renderIntent来“随时随地”更改要素的样式。 renderIntent引用样式图中的样式名称。然后调用layer.redraw()
你应该使用的实际zIndex也让我困惑。我使用10的步骤总是可以选择在两者之间添加一些东西,而不必改变整个lott。