“打开图层3”功能填充“画布”未固定到该功能 [英] Open Layers 3 feature fill with Canvas is not fixed to the feature

查看:108
本文介绍了“打开图层3”功能填充“画布”未固定到该功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 openlayers 3 ,并使用 canvasPattern 创建了一个填充。填充工作,问题是它没有按预期工作。



我希望填充随着它填充的几何体移动,但是当你将在此示例中看到:





I've been working with openlayers 3 and created a fill with canvasPattern. The fill works, the problem is that it doesn't work as expected.

I'd expect the fill to move with the geometry that it is filling, but as you will see in this example:

http://fiddle.jshell.net/luigibosca/Lwrbuxfd/14/

if you move the map around you'll notice that the fill is absolutely positioned, and not relative to the geometry it fills.

  • Am I using the fill wrong?
  • Does any one know how to get the fill to move with the geometry?

Thanks in advance for any help!

解决方案

As far as I can see, there is no way to make the fill pattern origin follow the map or geometry as it is panned or moved when using it with vector layers. Openlayers just uses the pattern as the fill without translating it, so it will always be statically positioned relative to the the canvas.

However, PR #5854 introduces an example where it works. It's not live on the examples page yet, but can be viewed on http://jsfiddle.net/61b7szjn/.

The difference between this and your example is that it uses an ImageVector source (making it an Image layer). Doing that would make it work, such as in your example:

var imageVectorLayer = new ol.layer.Image({
    source: new ol.source.ImageVector({
      source: vectorSource,
    style: styleFunction
  }),
})

Using Image layers for vector data might not be suitable for all situations, so adding support for translating the fill pattern seems like great PR material.

Edit:

Upon further testing, it seems like the ImageVector solutions is not a guaranteed fix. The pattern generally follows along as I pan, but is sometimes moves to different offsets in unpredictable ways. I assume it's because of how the rendered source canvas is clipped:

这篇关于“打开图层3”功能填充“画布”未固定到该功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆