[OpenLayers-Users] Vector layers changing style on zoom in/out?

Planet)x andrew.stewart at reddeer.ca
Mon Apr 4 18:13:33 EDT 2011


I have several controls to draw vector layers which I have declared below for
a line, polygon, point and text tool. I am using just several buttons that
basically activate/decative the controls based on what buttons are pressed.
I am also changing the style of the vector layer when the button is pressed
so that it can use text and an invisible point for the text control and then
regular lines/polygon/point for the others. I am doing so like -
vlayer.styleMap = styleMap_redline

My styles are defined like - 

var styleMap_redline =  new
OpenLayers.StyleMap(OpenLayers.Util.applyDefaults(
       {fillColor: "red", fillOpacity: 0.3, strokeColor: "red", strokeWidth:
2},
       OpenLayers.Feature.Vector.style["default"]));


And my text style  -

  //style_text 
        var style_text = new OpenLayers.StyleMap({
                "default": new OpenLayers.Style({
                    strokeColor: "#00FF00",
                    strokeOpacity: 0,
                    strokeWidth: 3,
                    fillColor: "#FF5500",
                    fillOpacity: 0,
                    pointRadius: 6,
                    label : "${getLabel}",
                    fontColor: "red",
                    fontSize: "12px",
                    fontFamily: "Arial",
                    fontWeight: "bold",
                    labelXOffset: "10",
                    labelYOffset: "10",
                    //externalGraphic: "${getGraphic}",
                cursor: 'hand'
                },{
                    context: {
                                getLabel:function(feature) 
                                {
                                    return redline_text_label;
                                }
                            }
                })
               }); 

My issue is when I select either drawLine, drawPoint or drawPolygon first
and draw the selected vector features then switch to text it works fine. I
can add some text features and the polygon/point/line remain.. until I zoom
in or out. When I zoom in/out all of the other features besides text get
converted to whatever the text was (everything is now text instead of
lines/polygons).. is this a bug and is there anyway I can correct this?
Appreciate any advice!

var drawLine = new OpenLayers.Control.DrawFeature(vlayer,
OpenLayers.Handler.Path);
var drawPolygon = new OpenLayers.Control.DrawFeature(vlayer,
OpenLayers.Handler.Polygon);
var drawPoint = new OpenLayers.Control.DrawFeature(vlayer,
OpenLayers.Handler.Point);
var drawText = new OpenLayers.Control.DrawFeature(vlayer,
OpenLayers.Handler.Point);

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Vector-layers-changing-style-on-zoom-in-out-tp6240410p6240410.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list