2012-12-21 21 views
1

我有一個層節點功能,我可能要顯示兩個圖像,主要和背景之一。本頁面:http://openlayers.org/dev/examples/marker-shadow.html顯示了我想要的:陰影在黃金項目下(當我們用開發工具移動png時,這一點更加明顯)。 爲此,他們使用:OpenLayers:如何獲得backgroundGraphic去下externalGraphic

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

的圖像。但是,當人們可以認爲背景圖形會自動進入外部圖形時,實際上會發生相反的情況。好吧,我只是添加Z指數的東西:

style['graphicZIndex'] = 1; 
style['backgroundGraphicZIndex'] = style['graphicZIndex']-1; 

但它絕對沒有改變。我如何獲得我的背景?

回答

0

這有點棘手。樣式和樣式地圖是您的要素所在圖層的屬性。你應該定義樣式,把它們放在一個樣式圖中,並在圖層構造中使用它。您可以通過更改特徵renderIntent來隨時更改特徵的樣式。 renderIntent引用樣式表中的樣式名稱。然後調用layer.redraw()

您應該使用的實際zIndex也令我困惑。我使用10的步驟總是可以選擇添加一些東西,而無需更改整個洛特。

+0

我很想看到這個演示/例子。 – Joel