I have one KML layer that has roughly 900 features and I added OpenLayer.Cluster.Strategy to help the layer display a little quicker.
My KML displays the attributes when clicked on before clustering was enabled, but now the bubble displays 'undefined, undefined'.
How did the clustering change the extractAttributes property?
var state = new OpenLayers.Layer.Vector("State Probation", {
projection: map.displayProjection,
strategies: [new OpenLayers.Strategy.Fixed(), new OpenLayers.Strategy.Cluster()],
protocol: new OpenLayers.Protocol.HTTP({
url: "state.kml",
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true
})
})
});
select = new OpenLayers.Control.SelectFeature([sample, state],
{
clickout: true, toggle: false,
multiple: true, hover: false,
toggleKey: "ctrlKey", // ctrl key removes from selection
multipleKey: "shiftKey" // shift key adds to selection
});
sample.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
state.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
map.addControl(new OpenLayers.Control.LayerSwitcher());
function onPopupClose(evt) {
select.unselectAll();
}
function onFeatureSelect(event) {
var feature = event.feature;
var selectedFeature = feature;
var popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
"<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description,
null, true, onPopupClose
);
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}