Hopefully the following will help you:

        var myStyleMap = new OpenLayers.StyleMap({
                'default': new OpenLayers.Style({
                        backgroundGraphic: "../images/myhadow.png",
                        backgroundWidth: 29,
                        backgroundHeight: 19,
                        backgroundGraphicZIndex: 10,
                        backgroundXOffset: -10,
                        backgroundYOffset: -10,
                        externalGraphic: "${getExternalGraphic}",
                        graphicWidth: "${getGraphicWidth}",
                        graphicHeight: "${getGraphicHeight}",
                        graphicZIndex: 11,

                        cursor: 'default',

                        label: "${getLabel}",
                        labelAlign: "lt",
                        labelXOffset: "-10",
                        labelYOffset: "-14",

                        fontColor: "black",
                        fontSize: "${getFontSize}",
                        fontFamily: "'Arial'",
                        fontWeight: "bold",

                        labelOutlineColor: "#FFFFC0",
                        labelOutlineWidth: 4
                },{
                context: {
                        getExternalGraphic: function(feature) {
                                if (feature.cluster) {
                                        return "../images/mycluster.png";
                                } else {
                                        return "../images/my.png";
                                }

                        },
                        getGraphicWidth: function(feature) {
                                if (feature.cluster) {
                                        return 32;
                                } else {
                                        return 19;
                                }
                        },
                        getGraphicHeight: function(feature) {
                                if (feature.cluster) {
                                        return 31;
                                } else {
                                        return 19;
                                }
                        },
                        getLabel: function(feature) {
        
if(document.getElementById('OLBtnWaterInfo').className=='OverlayButtonOn') {
                                        if (feature.cluster) {
                                                var label = "";
                                                for (i=0;i  <=
feature.cluster.length - 1; i++) {
                                                        label = label +
feature.cluster[i].attributes["MyData1"] + "\n";
                                                }
                                                return label;
                                        } else {
                                                return
feature.attributes["ConnectedPipeDiameter"];
                                        }
                                } else {
                                        return '';
                                }
                        },
                        getFontSize: function(feature) {
                                if
(document.getElementById('OLBtnMagnify').className=='OverlayButtonOn') {
                                        return "30px";
                                } else {
                                        return "16px";
                                }
                        }
                }
        })});

        //====== my Cluster Strategy ======

        var myCluster = new OpenLayers.Strategy.Cluster({
                distance: 50,
                threshold: 2,
                clusteringActivated: false,
                deactivate: function() {
                        if (this.clusteringActivated) {
                                this.clusteringActivated = false;
                                var deactivated =
OpenLayers.Strategy.prototype.deactivate.call(this);
                                if(deactivated) {
                                        var features = [];
                                        var clusters = this.layer.features;
                                        for (var i=0; i < clusters.length;
i++) {
                                                var cluster = clusters[i];
                                                if (cluster.cluster) {
                                                        for (var j=0; j <
cluster.cluster.length; j++) {
        
features.push(cluster.cluster[j]);
                                                        }
                                                } else {
                                                features.push(cluster);
                                        }
                                }
                                this.layer.removeAllFeatures();
                                this.layer.events.un({
                                        "beforefeaturesadded":
this.cacheFeatures,
                                        "moveend": this.cluster,
                                        scope: this
                                });
                                this.layer.addFeatures(features);
                                        this.clearCache();
                                }
                                return deactivated;
                        }
                },
                activate: function() {
                        if (!this.clusteringActivated) {
                                this.clusteringActivated = true;
                                var activated =
OpenLayers.Strategy.prototype.activate.call(this);
                                if(activated) {
                                        var features = [];
                                        var clusters = this.layer.features;
                                        for (var i=0; i < clusters.length;
i++) {
                                                var cluster = clusters[i];
                                                if (cluster.cluster) {
                                                        for (var j=0; j <
cluster.cluster.length; j++) {
        
features.push(cluster.cluster[j]);
                                                        }
                                                } else {
        
features.push(cluster);
                                                }
                                        }
                                        this.layer.removeAllFeatures();
                                        this.layer.events.on({
                                                "beforefeaturesadded":
this.cacheFeatures,
                                                "moveend": this.cluster,
                                                scope: this
                                        });
                                        this.layer.addFeatures(features);
                                        this.clearCache();
                                }
                                return activated;
                        }
                }
        });

        //====== my WFS ======

        my = new OpenLayers.Layer.Vector('my',{
                strategies: [new OpenLayers.Strategy.BBOX(), myCluster],
                styleMap: myStyleMap,
                visibility: false,
                minScale: maxShowOverlayScale,
                protocol: new OpenLayers.Protocol.WFS({
                        url: WFS_Host, 
                        featureType: 'my',
                        featureNS: 'http://mapserver.gis.umn.edu/mapserver',
                        featurePrefix: 'ms',
                        geometryName: 'msGeometry',
                        srsName: 'EPSG:27700',
                        version: '1.1.0' 
                })
        });
        MapOS.addLayer(my);


Regards,

Donald



 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of robertico
Sent: 26 January 2013 12:37
To: [email protected]
Subject: Re: [OpenLayers-Users] Cluster strategy (using different icon)

There seem to be more questions than answers here



--
View this message in context:
http://osgeo-org.1560.n6.nabble.com/Cluster-strategy-using-different-icon-tp
5028447p5030035.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2890 / Virus Database: 2639/6056 - Release Date: 01/25/13

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

Reply via email to