I am using a cluster vector layer and have a doubt about the value of 'property' in rule.
My code is:
rules: [
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: "amount",
value: 1
}),
symbolizer: {
fillColor: '#34f2f9'
}
}),
new OpenLayers.Rule({
elseFilter: true,
symbolizer: {
fillColor: '#fff'
}
})
]
My doubt is how to get the value of amount in the above code. From where I will pass the value of amount .
Whole code for adding layer is:
function rqstSubmit(params,url) {
if (featureSubVector){
featureSubVector.removeAllFeatures();
map.removeLayer(featureSubVector);
featureSubVector = null;
}
var style = new OpenLayers.Style(
{
rules: [
new OpenLayers.Rule({
filter: new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.EQUAL_TO,
property: 'amount',
value: 1
}),
symbolizer: {
fillColor: '#34f2f9',
pointRadius: '10',
fillOpacity: 0.6,
strokeColor: '#cc6633',
label: "${getLabel}"
}
}),
new OpenLayers.Rule({
elseFilter: true,
symbolizer: {
fillColor: '#fff',
pointRadius: '10',
fillOpacity: 0.6,
strokeColor: '#cc6633',
label: "${getLabel}"
}
})
]
},
{
context: {
getLabel: function(feature) {
if (feature.cluster) {
if (feature.cluster.length > 1) {
return feature.cluster.length;
}
}
return '';
}
}
});
var featureSubVector = new OpenLayers.Layer.Vector('Search Result', {
strategies: [
new OpenLayers.Strategy.Cluster()
],
styleMap: new OpenLayers.StyleMap({
'default': style,
'select': {fillColor: '#8aeeef'}
})
});
map.addLayer(featureSubVector);
PDGeoJsonFormat=new OpenLayers.Format.GeoJSON();
PDRequest.open('POST',/some/url/,true);
PDRequest.onreadystatechange=function(){
if(PDRequest.readyState==4 && PDRequest.status==200){
if(PDGeoJsonFormat.read(PDRequest.responseText)!=null){
PDJsonFeatures=PDGeoJsonFormat.read(PDRequest.responseText);
if(PDJsonFeatures.length > 0){
content="";
for(i=0;i<PDJsonFeatures.length;i++) {
content = content+"<tr> <td align='center' style='width:35px;'>"+(i+1)+"</td><td href='javascript:void(0);' onClick=\"ResultZoomLoc('"+ PDJsonFeatures[i].attributes['title']+"','"+PDJsonFeatures[i].attributes['name']+"','"+PDJsonFeatures[i].attributes["x"]+"','"+ PDJsonFeatures[i].attributes["y"]+"','"+ PDJsonFeatures[i].attributes['amount'] +"')\" >"+ PDJsonFeatures[i].attributes['nameUnit']+"</td></tr>";
}
var ulcontent = '<table width="99%" align="center"><tr style="background:#aed6e8;"> <th colspan="2">RESULT ('+PDJsonFeatures.length+')</th></tr> '+content+' </table>';
$("#result").html(ulcontent); //--append result to popup div--
featureSubVector.removeFeatures(PDJsonFeatures);
PDJsonFeatures = PDGeoJsonFormat.read(PDRequest.responseText);
var selectControl = new OpenLayers.Control.SelectFeature(featureSubVector,{clickout: true, toggle: false, multiple: false, hover: false });
featureSubVector.events.on({
"featureselected": clusterClick, //--Function-on-cluster-click--
"featureunselected": ClusterCloseCloud //--Function-on-close--
});
map.addControl(selectControl);
selectControl.activate();
featureSubVector.addFeatures(PDJsonFeatures);
}
else dispErrMessage("error_popup","No data found!",2000);
}
}
}
PDRequest.send(params);
}
Where PDJsonFeatures[i].attributes['amount'] values are 1 or 2 or 3 or..10 ResultZoomLoc is function for zooming to the location onclicking result.
Only the ELSE part of openlayers Filter is working here. Also the label "${getLabel}" is getting as undefined