0

I have created a style map like following:

    var scadaPointStyle = new OpenLayers.StyleMap({
        "default": new OpenLayers.Style("null", {
            "rules": [
                new OpenLayers.Rule({
                    "symbolizer": {
                        "Point": {
                            pointRadius: 15,
                            fillColor: "#3DCDE0",
                            fillOpacity: 0.9,
                            strokeColor: "white",
                            label: "${point_id}",
                            fontColor: "white",
                            cursor: "pointer"
                        }
                    }
                })
            ]
        }),
        "select": new OpenLayers.Style("null", {
            "rules": [
                new OpenLayers.Rule({
                    "symbolizer": {
                        "Point": {
                            pointRadius: 15,
                            fillColor: "#323D34",
                            fillOpacity: 0.9,
                            strokeColor: "white",
                            label: "${point_id}",
                            fontColor: "white",
                            cursor: "pointer"
                        }
                    }
                })
            ]
        })
});

And my vector layer is like this:

    var vector = new OpenLayers.Layer.Vector(null, {
            "protocol": new OpenLayers.Protocol.WFS({
                featureType: featureType,
                version: "1.1.0",
                url: myurl,
                featurePrefix: myeaturePrefix,
                geometryName: myGeometryName,
                srsName: mysrs,
                isBaseLayer: false
            }),
            "styleMap": scadaPointStyle,
            "strategies": [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Cluster()],
            "eventListeners": {
                "featureselected": onSelected,
                "featureunselected": onUnselected,
                "loadstart": onLoadStarted,
                "loadend": onLoadEnd
            }
    });

Point style is working and appearing on map. But label text is undefined.

I added contecxt to style like this:

context:function(feature){
       return faeture.attributes.point_id;
}

but didn't worked.

May be about cluster strategy?

I removed cluster strategy but this time pint style didn't appear.

1

At OpenLayers Cookbook code examples (http://acanimal.github.io/Openlayers-Cookbook/) there is a working example, see "Chapter7 - Styling - Improving style using StyleMap and feature's attributes replacement".

Create your style intent without using rules, really you are not using them because you are not setting any condition to filter. For example try creating the default style as:

var style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style["default"]);
style.pointRadius = "${radius}";
style.fillColor = '${colorFunction}';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.