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

javascript - OpenLayers features redraw only after mouse moveend - Stack Overflow

programmeradmin0浏览0评论

In this case I use Map control from OpenLayers 2.10. On map I have base layer which is OpenLayers.Layer.OSM and OpenLayers.Layer.Vector with custom features. Now when I move map using mouse the features that weren't previously visible won't redraw until release of mouse button. I have noticed the same issue in all OpenLayers examples. Can anyone provide some kind of work around to change this behaviour? What I want to achieve is to draw features immediately after feature bees visible or always draw all features (I work with small number of features so performance of map control isn't critical).

My current idea is to handle some specific events on map (like mouse move with click) and force features redraw.

In this case I use Map control from OpenLayers 2.10. On map I have base layer which is OpenLayers.Layer.OSM and OpenLayers.Layer.Vector with custom features. Now when I move map using mouse the features that weren't previously visible won't redraw until release of mouse button. I have noticed the same issue in all OpenLayers examples. Can anyone provide some kind of work around to change this behaviour? What I want to achieve is to draw features immediately after feature bees visible or always draw all features (I work with small number of features so performance of map control isn't critical).

My current idea is to handle some specific events on map (like mouse move with click) and force features redraw.

Share Improve this question asked Feb 14, 2011 at 12:10 jethrojethro 18.8k7 gold badges48 silver badges42 bronze badges 2
  • Are your 'hidden' features already on the client or do you fetch them when you move map using mouse? It will be easier to find solution if you post some code you are using – igorti Commented Feb 14, 2011 at 15:58
  • I also need a solution for this problem. Maybe someone can help. – user942352 Commented Sep 13, 2011 at 10:52
Add a ment  | 

4 Answers 4

Reset to default 6

Update

The SVG2 renderer was introduced in v2.11, and then immediately deprecated in v2.12 for reliability reasons (See this pull request). For OL >= 2.12, set the layer's ratio property to have it render all features within a wider area as a ratio of the screen size. The trade-off is performance, and if your user "throws" their map in some direction, they will fly past the features, but at that point they probably expect to have some rendering delays.

new OpenLayers.Layer.Vector("My Layer", {
    ratio: 2
});

Original Answer

From http://lists.osgeo/pipermail/openlayers-dev/2011-March/007345.html :

the new OpenLayers.Renderer.SVG2 renderer does what you are requesting. It is available on trunk (and will be in 2.11). To use it, configure the renderers array for your OpenLayers.Layer.Vector like this:

new OpenLayers.Layer.Vector("My Layer", {
    renderers: ["SVG2", "VML", "Canvas"]
});

Or set it on the prototype:

OpenLayers.Layer.Vector.renderers = ["SVG2", "VML", "Canvas"];

Note that VML (used in IE6,7,8) and Canvas (used on Android devices) behave like Renderer.SVG and don't draw features while panning.

With OpenLayer v6.4.3 you can set the following property of VectorLayer:

  • updateWhileAnimating boolean (defaults to false) When set to true, feature batches will be recreated during animations. This means that no vectors will be shown clipped, but the setting will have a performance impact for large amounts of vector data. When set to false, batches will be recreated when no animation is active.
  • updateWhileInteracting boolean (defaults to false) When set to true, feature batches will be recreated during interactions. See also updateWhileAnimating.

I don't have a solution, but made an observation. Looking at this example on Vector Behavior on the OL Examples website, if features are partially visible (i.e. placed on the border of the viewport), they remain partially hidden when dragged into full view. Only fully visible upon release of the mouse button. My point being that it seems to be a display issue more than a load issue, if that wasn't apparent already...

Will keep an eye on the question, curious to the answer. :-)

Just in case anyone stumbles across this question (as I did) OpenLayers 2.11 resolves this issue. I tested it on my web application and it now redraws vector features instantly, whereas with an older version of OL installed it would do what was written above. Something I had never noticed before either so nice one for spotting it!

Here are the release notes.

http://trac.osgeo/openlayers/wiki/Release/2.11/Notes

This sort of shows it in action. Best example I could find I'm afraid :P

http://openlayers/dev/examples/rotate-features.html

发布评论

评论列表(0)

  1. 暂无评论