[OpenLayers-Users] Displaying Cluster count and/or certain attributes
Frederick Löbig
frederick.loebig at live.de
Thu Dec 19 02:27:54 PST 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20131219/6b476722/attachment.html>
More information about the Users
mailing list