2011-02-23 106 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