Quoting [email protected]:



Today's Topics:

   1. need a clarification re styleMaps (Puneet Kishor)


----------------------------------------------------------------------

Message: 1
Date: Tue, 4 Oct 2011 10:42:36 -0500
From: Puneet Kishor <[email protected]>
Subject: [OpenLayers-Users] need a clarification re styleMaps
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252

The following code works

    // Add styleMap to layer
    var style_map = new OpenLayers.StyleMap({
        externalGraphic: uri + "/img/arrow.png",
        graphicWidth: 15,
        graphicHeight: res[0].height,
        rotation: res[0].angle
    });
    var lyr = new OpenLayers.Layer.Vector("name", {styleMap: style_map});

    // Points without styleMap
    var points = [];
    points.push(
        new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(res[0].lng, res[0].lat)
        )
    );
    lyr.addFeatures(points);
    map.addLayer(lyr);

everything works. Different points get drawn with symbols of correct
height and rotation. But, if I don't add the styleMap definition to
the lyr when creating it, and instead, add it to the point, like so

    // Layer with styleMap
    var lyr = new OpenLayers.Layer.Vector("name");

    // Add styleMap to each point
    var style_map = new OpenLayers.StyleMap({
        externalGraphic: uri + "/img/arrow.png",
        graphicWidth: 15,
        graphicHeight: res[0].height,
        rotation: res[0].angle
    });

    var points = [];
    points.push(
        new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(res[0].lng, res[0].lat),
            {styleMap: style_map}
        )
    );
    lyr.addFeatures(points);
    map.addLayer(lyr);

then nothing gets drawn. At best, this is counter-intuitive to me…
the style is per point, not per layer. At worst, this creates a
problem for me that I don't know how to solve. I am creating a layer
that I want to reuse. If I follow the first approach above, the
first time around everything works well. But, on subsequent
iterations the points get drawn with the previously set style
(rotation and height).

I had a similar issue not that long ago. While I too find it odd that
adding the stylemap to the point itself did not work, I got what I
needed by adding a uniqueValueRule to the style that determined what
style rules to use based on a an arbitrary property of the point.

http://docs.openlayers.org/library/feature_styling.html#adduniquevaluerules


mike

_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to