1

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

1

You have a layer with amount as a field in attributes, passing the value will be as follow

var qty = 1000; //Example of value to be compare.

rules: [
    new OpenLayers.Rule({
        filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.EQUAL_TO,
        property: "amount", 
        value: qty 
        }),
        symbolizer: {
        fillColor: '#34f2f9'
        }
    }),
    new OpenLayers.Rule({

        elseFilter: true,
        symbolizer: {
        fillColor: '#fff'
        }
    })
 ]

Full example:
http://dev.openlayers.org/examples/filter-strategy.html

JS code:
http://dev.openlayers.org/examples/filter-strategy.js

  • my doubt is from where i will get 'amount' (value of 'amount') – user123 May 2 '17 at 4:29
  • Do you filter the data based on specific column ? – Shiko May 2 '17 at 4:37
  • yes..the amount will be from the database and want to filter(EQUAL_TO) & fillColor based on the comparison/filter. – user123 May 2 '17 at 4:40
  • Well, if you have the value of amount fetched from the database and your feature class has a column called amount and you want to filter data based on amount of 100 for example, then you can pass it as in example. qty is the variable to hold the value and in OpenLayers.Rule payloads, there is a value property to set the value to be compared. – Shiko May 2 '17 at 4:48
  • no...i am not getting the value of amount..I have updated the question with whole code..please have a look on it – user123 May 2 '17 at 7:28
1

When inspecting the source of the Extended Clustering Example you can see that the property takes an attribute of the vector as input.

// creating the feature with an attribute "clazz"
var f = new OpenLayers.Feature.Vector(p, {clazz: clazz});

// defining the rule using the attribute "clazz" comparing with the value
new OpenLayers.Rule({
    filter: new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LESS_THAN,
        property: "clazz",
        value: 4
    })
})
  • let me try it.. – user123 Apr 28 '17 at 11:16
  • its not working..I have updated the question – user123 May 2 '17 at 7:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.