[OpenLayers-Users] Displaying Cluster count and/or certain attributes

Christian Ledermann christian.ledermann at gmail.com
Thu Dec 19 03:10:08 PST 2013


something along the lines (I just cut and copied some of my code here so
you have to modify it for your needs):

                            for (var i=0; i<event.feature.cluster.length;
++i ) {
                                try {
                                        message +=
makeLink(event.feature.cluster[i].attributes['name'],event.feature.cluster[i].attributes['description']);


                                } catch(e) {
                                        //
                                };
                            }


HTH


On Thu, Dec 19, 2013 at 1:27 PM, Frederick Löbig
<frederick.loebig at live.de>wrote:

> Hey list,
>
> I have a question on the OpenLayers Cluster strategy and displaying
> attributes:
>
> The situation: I have a map loading quite a number of points from a
> dynamically generated GML. Currently, I am not using a cluster strategy,
> but the handling gets more and more difficult. When I hover the points, I
> send the feature.attributes.Name content (Content of the Name attribute
> in the GML) to a function for displaying a tooltip. No problem until I want
> to cluster the features. I understand, that after clustering, the attribute
> "Name" doesn't exist anymore. What I want to do now is, when it is a
> cluster of more than one feature, I want to send "Cluster of
> feature.attributes.count" to my tooltip function, which is also not a
> problem, but, if there is only one feature in the cluster, I want to send
> the feature.attributes.Name of that feature to the tooltip function. I
> hope you understand what I am trying to achieve.
>
> Here are the code fragments I am using at the moment:
>
> --- The layer is generated with the following function (already including
> the cluster strategy): ---
>
> ...
>
> pointLayer = new OpenLayers.Layer.Vector("Wasserhäuschen", {
>             strategies: [new OpenLayers.Strategy.Fixed(), new
> OpenLayers.Strategy.Cluster()],
>             attribution:"Dateneigentum: <a href='http://www.linie11.org'
> target='_blank'>linie11.org</a> <a href='http://www.l-11.de'
> target='_blank'><img src='./img/l11_attr.png' border='0'></a><br><br>",
>             protocol: new OpenLayers.Protocol.HTTP({
>                 url: "./geoData/data.xml.gml",
>                 format: new OpenLayers.Format.GML()
>             }),
> styleMap: new OpenLayers.StyleMap({'default':defaultStyle,
>
>  'select':selectStyle,
>
>  'temporary':tempStyle
> },{
>                 context: {
>                   // ...
>                   label: function(feature) {
>                     // clustered features count or blank if feature is not
> a cluster
>                     return feature.cluster ? feature.cluster.count : "";
>                   }
>                   // ..
>                 }
>
> })});
>
> ...
>
> --- EOF ---
>
> --- The code of the hover listener, that sends the data to the function
> openToolTip: ---
>
> ...
>
>                 var highlightCtrl = new OpenLayers.Control.SelectFeature(
>                     pointLayer,
>                     {
>                             hover: true,
>                             highlightOnly: false,
>                             clickout: false,
>                             toggle: false,
>                             multiple: false,
>                             renderIntent: "select",
>                             overFeature: function(feature) {
>                                     console.log('hover out:  ' +
> feature.attributes.count);
>                                     openToolTip('Cluster of ' +
> feature.attributes.count);
>                             },
>                             outFeature: function(feature) {
>                                     console.log('hover out:  ' +
> feature.attributes.count);
>                                     closeToolTip();
>                             },
>                     }
>                 );
>
> ...
>
> --- EOF ---
>
> To my understanding, I somehow need to access the attributes of the
> feature selected. But I have absolutely no idea how to do this, and I hope
> to get a little help from you guys!
>
> Thanks in advance,
> Freddy
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>



-- 
Best Regards,

Christian Ledermann

Nairobi - Kenya
Mobile : +254 702978914

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20131219/0fe131bd/attachment-0001.html>


More information about the Users mailing list