source : heatmap-layer.js

  1. /**
  2. * @ngdoc directive
  3. * @name heatmap-layer
  4. * @param Attr2Options {service} convert html attribute to Google map api options
  5. * @description
  6. * Requires: map directive
  7. * Restrict To: Element
  8. *
  9. * @example
  10. *
  11. * <map zoom="11" center="[41.875696,-87.624207]">
  12. * <heatmap-layer data="taxiData"></heatmap-layer>
  13. * </map>
  14. */
  15. (function() {
  16. 'use strict';
  17. angular.module('ngMap').directive('heatmapLayer', [
  18. 'Attr2MapOptions', '$window', function(Attr2MapOptions, $window) {
  19. var parser = Attr2MapOptions;
  20. return {
  21. restrict: 'E',
  22. require: ['?^map','?^ngMap'],
  23. link: function(scope, element, attrs, mapController) {
  24. mapController = mapController[0]||mapController[1];
  25. var filtered = parser.filter(attrs);
  26. /**
  27. * set options
  28. */
  29. var options = parser.getOptions(filtered, {scope: scope});
  30. options.data = $window[attrs.data] || parseScope(attrs.data, scope);
  31. if (options.data instanceof Array) {
  32. options.data = new google.maps.MVCArray(options.data);
  33. } else {
  34. throw "invalid heatmap data";
  35. }
  36. var layer = new google.maps.visualization.HeatmapLayer(options);
  37. /**
  38. * set events
  39. */
  40. var events = parser.getEvents(scope, filtered);
  41. console.log('heatmap-layer options', layer, 'events', events);
  42. mapController.addObject('heatmapLayers', layer);
  43. //helper get nexted path
  44. function parseScope( path, obj ) {
  45. return path.split('.').reduce( function( prev, curr ) {
  46. return prev[curr];
  47. }, obj || this );
  48. }
  49. }
  50. }; // return
  51. }]);
  52. })();