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
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6. var county = {
  7. query: {
  8. table: { name: 'census/BlockGroup' },
  9. select: { type: 'geo.poly' },
  10. where: [{ col: 'census/BlockGroup.inc', test: 'Greater', value: 60000 }],
  11. join: {
  12. method: "PointInPolyJoin",
  13. table: "hms/hotels",
  14. where:
  15. [
  16. //where contains hilton && 3 star
  17. [
  18. { col: "ChainID", test: "Contains", value: "hilton" }
  19. ],
  20. //OR where contains marriott && 3.5 star
  21. [
  22. { col: "ChainID", test: "Contains", value: "marriott" }
  23. ],
  24. //OR
  25. [
  26. { col: "LowRate", test: "Less", value: 15000 }
  27. ]
  28. ]
  29. }
  30. },
  31. style: {
  32. //having clauses (totals on grouped points) are supported using the intervals method for shading
  33. //(see below)
  34. //however, free form rules using having clauses are not supported yet
  35. //so for now you can't do this, but this feature is on our api road maps
  36. //having:[col:'hms/hotels.LowRate.avg', test:'Greater' value:100]
  37. //if you need this feature ASAP contact our development team for a custom build quote
  38. method: 'rules',
  39. //{ col: "StarRating", test: "Greater", value: 3.5 }
  40. rules: [
  41. {
  42. style: { fillColor: 'Red' },
  43. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '300' }]
  44. },
  45. {
  46. style: { fillColor: 'Blue' },
  47. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '200' }]
  48. },
  49. {
  50. style: { fillColor: 'Green' },
  51. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '100' }]
  52. },
  53. {
  54. style: { fillColor: 'Yellow' },
  55. where: 'CatchAll'
  56. }
  57. ]
  58. },
  59. onHover: function (data, layer) {
  60. return "Avg. Low Rate: $" + Math.round(data.subTotals.LowRate.avg);
  61. },
  62. //listing the hms/hotels table here is mandatory because we have two tables
  63. //.avg represents the average of the "LowRate" column points in this County
  64. hoverFields: ['hms/hotels.LowRate.avg'],
  65. onClick: 'debug'
  66.  
  67. //when you click debug notice the shape data is under data.data
  68. //and how the point totals are under data.subTotals
  69. };
  70.  
  71. //create a new div and add to document
  72. //you could also fetch the element by id
  73. var div = ml.create('div', "width:100%; height:100%;", document.body);
  74.  
  75. var map = new ml.map(div, { lat: 34, lng: -84, z: 5 });
  76. var layer = new ml.layer(map, county);
  77. layer.show();
  78. });
  79. </script>
  80. </head>
  81. <body>
  82.  
  83. </body>
  84. </html>
Example 2
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6. var county = {
  7. query: {
  8. table: { name: 'census/BlockGroup' },
  9. select: { type: 'geo.poly' },
  10. where: [{ col: 'census/BlockGroup.inc', test: 'Greater', value: 60000 }],
  11. join: {
  12. method: "PointInPolyJoin",
  13. table: "hms/hotels",
  14. where:
  15. [
  16. //where contains hilton && 3 star
  17. [
  18. { col: "ChainID", test: "Contains", value: "hilton" }
  19. ],
  20. //OR where contains marriott && 3.5 star
  21. [
  22. { col: "ChainID", test: "Contains", value: "marriott" }
  23. ],
  24. //OR
  25. [
  26. { col: "LowRate", test: "Less", value: 15000 }
  27. ]
  28. ]
  29. }
  30. },
  31. style: {
  32. //having clauses (totals on grouped points) are supported using the intervals method for shading
  33. //(see below)
  34. //however, free form rules using having clauses are not supported yet
  35. //so for now you can't do this, but this feature is on our api road maps
  36. //having:[col:'hms/hotels.LowRate.avg', test:'Greater' value:100]
  37. //if you need this feature ASAP contact our development team for a custom build quote
  38. method: 'rules',
  39. //{ col: "StarRating", test: "Greater", value: 3.5 }
  40. rules: [
  41. {
  42. style: { fillColor: 'Red' },
  43. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '300' }]
  44. },
  45. {
  46. style: { fillColor: 'Blue' },
  47. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '200' }]
  48. },
  49. {
  50. style: { fillColor: 'Green' },
  51. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '100' }]
  52. },
  53. {
  54. style: { fillColor: 'Yellow' },
  55. where: 'CatchAll'
  56. }
  57. ]
  58. },
  59. onHover: function (data, layer) {
  60. return "Avg. Low Rate: $" + Math.round(data.subTotals.LowRate.avg);
  61. },
  62. //listing the hms/hotels table here is mandatory because we have two tables
  63. //.avg represents the average of the "LowRate" column points in this County
  64. hoverFields: ['hms/hotels.LowRate.avg'],
  65. onClick: 'debug'
  66.  
  67. //when you click debug notice the shape data is under data.data
  68. //and how the point totals are under data.subTotals
  69. };
  70.  
  71. //create a new div and add to document
  72. //you could also fetch the element by id
  73. var div = ml.create('div', "width:100%; height:100%;", document.body);
  74.  
  75. var map = new ml.map(div, { lat: 34, lng: -84, z: 5 });
  76. var layer = new ml.layer(map, county);
  77. layer.show();
  78. });
  79. </script>
  80. </head>
  81. <body>
  82. </body>
  83. </html>

Here is an example that uses both multiple columns for Having clause filtering and multiple columns for aggregate rules.

Example 3
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/JS"></script>
  4. <script type="text/javascript">
  5. ml.onload(function () {
  6. var county = {
  7. query: {
  8. table: { name: 'census/BlockGroup' },
  9. select: { type: 'geo.poly' },
  10. where: [{ col: 'census/BlockGroup.inc', test: 'Greater', value: 60000 }],
  11. join: {
  12. method: "PointInPolyJoin",
  13. table: "hms/hotels",
  14. where:
  15. [
  16. //where contains hilton && 3 star
  17. [
  18. { col: "ChainID", test: "Contains", value: "hilton" }
  19. ],
  20. //OR where contains marriott && 3.5 star
  21. [
  22. { col: "ChainID", test: "Contains", value: "marriott" }
  23. ],
  24. //OR
  25. [
  26. { col: "LowRate", test: "Less", value: 15000 }
  27. ]
  28. ]
  29. }
  30. },
  31. style: {
  32. //having clauses (totals on grouped points) are supported using the intervals method for shading
  33. //(see below)
  34. //however, free form rules using having clauses are not supported yet
  35. //so for now you can't do this, but this feature is on our api road maps
  36. //having:[col:'hms/hotels.LowRate.avg', test:'Greater' value:100]
  37. //if you need this feature ASAP contact our development team for a custom build quote
  38. method: 'rules',
  39. //{ col: "StarRating", test: "Greater", value: 3.5 }
  40. rules: [
  41. {
  42. style: { fillColor: 'Red' },
  43. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '300' }]
  44. },
  45. {
  46. style: { fillColor: 'Blue' },
  47. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '200' }]
  48. },
  49. {
  50. style: { fillColor: 'Green' },
  51. where: [{ col: 'hms/hotels.LowRate.avg', test: 'Greater', value: '100' }]
  52. },
  53. {
  54. style: { fillColor: 'Yellow' },
  55. where: 'CatchAll'
  56. }
  57. ]
  58. },
  59. onHover: function (data, layer) {
  60. return "Avg. Low Rate: $" + Math.round(data.subTotals.LowRate.avg);
  61. },
  62. //listing the hms/hotels table here is mandatory because we have two tables
  63. //.avg represents the average of the "LowRate" column points in this County
  64. hoverFields: ['hms/hotels.LowRate.avg'],
  65. onClick: 'debug'
  66.  
  67. //when you click debug notice the shape data is under data.data
  68. //and how the point totals are under data.subTotals
  69. };
  70.  
  71. //create a new div and add to document
  72. //you could also fetch the element by id
  73. var div = ml.create('div', "width:100%; height:100%;", document.body);
  74.  
  75. var map = new ml.map(div, { lat: 34, lng: -84, z: 5 });
  76. var layer = new ml.layer(map, county);
  77. layer.show();
  78. });
  79. </script>
  80. </head>
  81. <body>
  82. </body>
  83. </html>