[OpenLayers-Dev] Vector layer isFixed

Christopher Schmidt crschmidt at metacarta.com
Sun Dec 17 08:30:08 EST 2006


Currently, the vector layer isFixed. This is a problem, because it means
that in order to keep an updated drawing on the screen, the layer has to
redraw dozens or hundreds of times when moving. 

In the past, we resolved this with the canvas layer by making the
drawing window always start at 0,0 (rather than at the geometric
location of that point), and then all drawing was done in pixel space
from that 0,0 origin using the map.getPixelFromLonLat functions.

Using the getPixelFromLonLat functionality on the map is also what
created support for drawing on things like Google Maps, where the pixel
-> geo space coordinates aren't uniform. 

It seems that the current vector code doesn't do this.

I'm wondering if there's a way we can pow-wow on this and we can
either:
  
  1. Help me understand why it can't be done that way
  2. Help me understand what code I need to change to help fix it.

I looked at the code, and my first inclination was to look at the
Renderer/Svg.js code. setExtent calls:

 this.svgRoot.setAttributeNS(null, "viewBox",  x + " " + -y + " " + width
                                                 + " " + height);

It seems like what I want this to do is "0 0 width height" instead. This
would then require changing the drawing functions: currently, they are:

node.setAttributeNS(null, "cx", geometry.x);

Instead, geometry.x would need to be calculated based on the relative
position of the layer, and use the LonLat -> pixel conversion code.
Paul's original Canvas layer did this with:

    convertToPx: function(lonLat) {
        if (this.vectorLayer) {
            var px = this.vectorLayer.map.getLayerPxFromLonLat(lonLat);
            var dX = -parseInt(this.vectorLayer.canvas.style.left);
            var dY = -parseInt(this.vectorLayer.canvas.style.top);
            px.x += dX;
            px.y += dY;
            return px;
        }
    } 

If you look at:

http://dev.openlayers.org/sandbox/pagameba/vector-original/examples/vector.html

You can see the difference in performance with a similar number of features 
to the current WFS-T demo. When the screen redraws, you see slow
loading, but not when dragging.   

If someone who has worked on the current vector rendering code could
look this over and let me know what they think, I'd appreciate it.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list