[OpenLayers-Users] Cluster Strategy WKT Vectors - not clustering

Andreas Hocevar ahocevar at opengeo.org
Mon Mar 16 08:11:14 EDT 2009


Hi,

there are several things wrong in your code.

if what you pasted below is your code, then you should get JavaScript
errors because you messed up the braces:

On Tue, Mar 3, 2009 at 5:21 PM, RFeagin
<ryan.feagin at peachtreegeographics.com> wrote:
>
> I am having problems with getting a clustering strategy to work on my vector
> layer.  Here is my layer definition...
>        vResultsLayer = new OpenLayers.Layer.Vector("Results"),
>                    { strategies: [new OpenLayers.Strategy.Fixed(),
>                                       new OpenLayers.Strategy.Cluster()],
>                       'sphericalMercator': true,
>                        styleMap: new OpenLayers.StyleMap({
>                            "default": style,
>                            "select": {
>                                fillColor: "#8aeeef",
>                                strokeColor: "#32a8a9"
>                            }
>                        })
>                    };

This should read

       vResultsLayer = new OpenLayers.Layer.Vector("Results",
                   { strategies: [new OpenLayers.Strategy.Fixed(),
                                      new OpenLayers.Strategy.Cluster()],
                      'sphericalMercator': true,
                       styleMap: new OpenLayers.StyleMap({
                           "default": style,
                           "select": {
                               fillColor: "#8aeeef",
                               strokeColor: "#32a8a9"
                           }
                       })
                   });


> and here is my code that creates the features...
>    getWKT_Results: function() {
>        respWKT = OpenLayers.Request.GET({
>            url: "Map_GetQueryResult.ashx?" + guid(),
>            success: function(request) {
>                wkt = new OpenLayers.Format.WKT({
>                    'internalProjection': new
> OpenLayers.Projection("EPSG:900913"),
>                    'externalProjection': new
> OpenLayers.Projection("EPSG:4326")
>                });
>
>                format = new OpenLayers.Format.XML();
>                var xmlParser = format.read(respWKT.responseText);
>
>                var featureNodes = format.getElementsByTagNameNS(xmlParser,
> '*', 'QueryResults');
>
>                var ftrArray = new Array();
>
>                for (var i = 0; i < format.getElementsByTagNameNS(xmlParser,
> '*', 'QueryResults').length; i++) {
>                    try {
>
> ftrArray.push(wkt.read(format.getElementsByTagNameNS(featureNodes[i], '*',
> 'WKT')[0].text)[0]);
>                        ftrArray[ftrArray.length - 1].fid =
> format.getElementsByTagNameNS(featureNodes[i], '*', 'featureID')[0].text;
>                    }
>                    catch (e) {
>                        test = e.toString();
>                    }
>                }
>                vResultsLayer .addFeatures(ftrArray);
>                //try to force clustering because it isn't getting set for
> the layer for some reason
>                //adding these lines did force clustering on, but caused
> "this.layer.events" error trying to unregister "beforefeaturesadded" event
>                //vResultsLayer .strategies = [new
> OpenLayers.Strategy.Cluster()];
>                //vResultsLayer .strategies[0].active = true;
>                //vResultsLayer .strategies[0].clustering = true;
>            }

You shouldn't do this manually. Add a HTTP Protocol with a WKT Format
to your layer. See
http://www.openlayers.org/dev/examples/behavior-fixed-http-gml.html
for a similar use case. You just have to replace the Fixed strategy
with your Cluster strategy and the GML format with a WKT format.

Regards,
Andreas.


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list