Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 930
jethro Avatar asked Feb 14 '11 12:02

jethro


2 Answers

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.

like image 181
colllin Avatar answered Nov 15 '22 06:11

colllin


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.
like image 1
Adrien Avatar answered Nov 15 '22 08:11

Adrien