最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Apply hash pattern to polygon in openlayers - Stack Overflow

programmeradmin6浏览0评论

I am creating a vector layer prised of polygons from a KML file using Openlayers and I need to apply a "hash" pattern (diagonal striping) to the polygons. I know Openlayers doesn't natively support adding a background image to a polygon in a vector layer but I'm wondering if anyone has any ideas on how to acplish this? The styling of a vector polygon appears to be limited to solid colors and opacity. If need be I'll extend OpenLayers to add this functionality in by manually drawing the hash lines within the polygon boundaries but I'm hoping someone has a simpler suggestion before I head down that road.

I am creating a vector layer prised of polygons from a KML file using Openlayers and I need to apply a "hash" pattern (diagonal striping) to the polygons. I know Openlayers doesn't natively support adding a background image to a polygon in a vector layer but I'm wondering if anyone has any ideas on how to acplish this? The styling of a vector polygon appears to be limited to solid colors and opacity. If need be I'll extend OpenLayers to add this functionality in by manually drawing the hash lines within the polygon boundaries but I'm hoping someone has a simpler suggestion before I head down that road.

Share Improve this question asked Feb 22, 2012 at 15:43 TheOxTheOx 2,22825 silver badges30 bronze badges 3
  • Do you mean styling polygon borders (exterior) or internal polygon ? – Myra Commented Feb 23, 2012 at 13:56
  • @Myra - internal polygon – TheOx Commented Feb 23, 2012 at 16:37
  • I was going to say,polygon has only outer boundary stroke style as hash,but currently no support for internal style except for color & opacity – Myra Commented Feb 24, 2012 at 6:03
Add a ment  | 

2 Answers 2

Reset to default 5

Using SLD this can now be done. Not sure if it's in version 2.11 or the trunk development but i saw the addition was mitted about 6 months ago.

It uses an ExternalGraphic so you can set an image of whatever pattern or color you want.

Here's the Example

I have not try this yet, but I have similar problem.
The solution I will try is svg pattern.
OpenLayers has SVG.js which is used to draw polygons. I will modify that to support patterns.
Look Image -->
http://i2.aijaa./b/00653/9707550.jpg
In this example i have modified http://openlayers/dev/examples/behavior-fixed-http-gml.html example to demonstrate pattern usage. --> Could this be good solution?

发布评论

评论列表(0)

  1. 暂无评论