When doing a PointInPolyJoin, there is the Join object key with method, table, and Where clause. Use Having to specify aggregate Where clauses (using the same format as normal Where blocks) that will filter results based on the post-join aggregate values (sum, avg, count).

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