heatmap-layer.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @ngdoc directive
  3. * @name heatmap-layer
  4. * @requires Attr2Options
  5. * @description
  6. * Requires: map directive
  7. * Restrict To: Element
  8. *
  9. * @example
  10. * Example:
  11. *
  12. * <map zoom="11" center="[41.875696,-87.624207]">
  13. * <heatmap-layer data="taxiData"></heatmap-layer>
  14. * </map>
  15. */
  16. /*jshint -W089*/
  17. ngMap.directive('heatmapLayer', ['Attr2Options', '$window', function(Attr2Options, $window) {
  18. var parser = Attr2Options;
  19. return {
  20. restrict: 'E',
  21. require: '^map',
  22. link: function(scope, element, attrs, mapController) {
  23. var filtered = parser.filter(attrs);
  24. /**
  25. * set options
  26. */
  27. var options = parser.getOptions(filtered);
  28. options.data = $window[attrs.data] || scope[attrs.data];
  29. if (options.data instanceof Array) {
  30. options.data = new google.maps.MVCArray(options.data);
  31. } else {
  32. throw "invalid heatmap data";
  33. }
  34. var layer = new google.maps.visualization.HeatmapLayer(options);
  35. /**
  36. * set events
  37. */
  38. var events = parser.getEvents(scope, filtered);
  39. console.log('heatmap-layer options', layer, 'events', events);
  40. mapController.addObject('heatmapLayers', layer);
  41. }
  42. }; // return
  43. }]);