简体   繁体   中英

OpenLayers features redraw only after mouse moveend

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 becomes 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.

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.org/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.

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.org/openlayers/wiki/Release/2.11/Notes

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

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

I don't have a solution, but made an observation. Looking at this example onVector Behavior on the OL Examples website, if features are partially visible (ie 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. :-)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM