When styling by the rules method, you can now include aggregate column values in the Where portion of each rule. These operate exactly like normal Where clauses, except for the following:
You include the extra .sum, .avg, or .count onto the end of the column.
You must include the table name in the column definition.
Example: account/table.column.avg (or account/table/version.column.avg).
As per normal rules, they will be applied to data in the order defined.
Example 1
<html> <head> <script type="text/javascript" src="/JS"></script> <script type="text/javascript"> ml.onload(function () { var county = { query: { table: { name: 'census/BlockGroup' }, select: { type: 'geo.poly' }, where: [{ col: 'census/BlockGroup.inc', test: 'Greater', value: 60000 }], join: { method: "PointInPolyJoin", table: "hms/hotels", where: [ //where contains hilton && 3 star [ { col: "ChainID", test: "Contains", value: "hilton" } ], //OR where contains marriott && 3.5 star [ { col: "ChainID", test: "Contains", value: "marriott" } ], //OR [ { col: "LowRate", test: "Less", value: 15000 } ] ] } }, style: { //having clauses (totals on grouped points) are supported using the intervals method for shading //(see below) //however, free form rules using having clauses are not supported yet //so for now you can't do this, but this feature is on our api road maps //having:[col:'hms/hotels.LowRate.avg', test:'Greater' value:100] //if you need this feature ASAP contact our development team for a custom build quote method: 'rules', //{ col: "StarRating", test: "Greater", value: 3.5 } rules: [ { style: { fillColor: 'Red' }, where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '300' }] }, { style: { fillColor: 'Blue' }, where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '200' }] }, { style: { fillColor: 'Green' }, where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '100' }] }, { style: { fillColor: 'Yellow' }, where: 'CatchAll' } ] }, onHover: function (data, layer) { return "Avg. Low Rate: $" + Math.round(data.subTotals.LowRate.avg); }, //listing the hms/hotels table here is mandatory because we have two tables //.avg represents the average of the "LowRate" column points in this County hoverFields: ['hms/hotels.LowRate.avg'], onClick: 'debug' //when you click debug notice the shape data is under data.data //and how the point totals are under data.subTotals }; //create a new div and add to document //you could also fetch the element by id var div = ml.create('div', "width:100%; height:100%;", document.body); var map = new ml.map(div, { lat: 34, lng: -84, z: 5 }); var layer = new ml.layer(map, county); layer.show(); }); </script> </head> <body> </body> </html>
Example 3
Example 4
Here is an example that uses both multiple columns for Having clause filtering and multiple columns for aggregate rules.