2011-02-23 52 views
2

我可以使用OpenLayers在多邊形上自定義背景(例如圖像)嗎?我可以在OpenLayers中自定義多邊形的背景嗎?

感謝您的答覆

+0

哪裏是你的多邊形來的? – 2011-02-23 21:09:29

+0

試試我在這個鏈接發佈的答案https://stackoverflow.com/questions/46455477/vector-tiles-on-top-of-raster-tiles-is-not-getting-displayed-in-openlayers/46538341# 46538341 – 2017-10-03 07:18:41

回答

2

所有WFS /矢量樣式屬性是對http://docs.openlayers.org/library/feature_styling.html
根據該鏈接,你不能爲多邊形設置背景圖片。嘗試在服務器端進行,如果使用它,可以使用MapServer。

+1

我可以通過轉換爲WMS圖層並更新Mapfile以使用[符號系統](http://mapserver.org/mapfile/symbology/examples.html)來獲得它與Mapserver一起工作的唯一方法。查看[hatch示例](http://mapserver.org/mapfile/symbology/examples.html#example-7-using-the-symbol-type-hatch-new-in-4-6)在裏面畫對角線多邊形。 – Pete 2015-01-06 19:11:42

0

好的,問題和答案都很舊,但無論如何。 您現在可以在OL 2.13.1使用此snippset:

var _styleMap = new OpenLayers.StyleMap(); 
var _ruleDef = [new OpenLayers.Rule({ 
    symbolizer: { 
     externalGraphic: "vertical1.png", //use your bitmap 
     graphic: true, 
     graphicFormat: "image/png", 
    }, 
    elseFilter: true 
})]; 
_styleMap.styles["default"].addRules(_ruleDef); 
yourLayer.styleMap = _styleMap; // put the new StyleMap on your Layer 
yourLayer.redraw(); 

的結果應該是這樣的: enter image description here