source : map-data.js

  1. /**
  2. * @ngdoc directive
  3. * @name map-data
  4. * @param Attr2MapOptions {service}
  5. * convert html attribute to Google map api options
  6. * @description
  7. * set map data
  8. * Requires: map directive
  9. * Restrict To: Element
  10. *
  11. * @wn {String} method-name, run map.data[method-name] with attribute value
  12. * @example
  13. * Example:
  14. *
  15. * <map zoom="11" center="[41.875696,-87.624207]">
  16. * <map-data load-geo-json="https://storage.googleapis.com/maps-devrel/google.json"></map-data>
  17. * </map>
  18. */
  19. (function() {
  20. 'use strict';
  21. angular.module('ngMap').directive('mapData', [
  22. 'Attr2MapOptions', 'NgMap', function(Attr2MapOptions, NgMap) {
  23. var parser = Attr2MapOptions;
  24. return {
  25. restrict: 'E',
  26. require: ['?^map','?^ngMap'],
  27. link: function(scope, element, attrs, mapController) {
  28. mapController = mapController[0] || mapController[1];
  29. var filtered = parser.filter(attrs);
  30. var options = parser.getOptions(filtered, {scope: scope});
  31. var events = parser.getEvents(scope, filtered, events);
  32. console.log('map-data options', options);
  33. NgMap.getMap(mapController.map.id).then(function(map) {
  34. //options
  35. for (var key in options) {
  36. var val = options[key];
  37. if (typeof scope[val] === "function") {
  38. map.data[key](scope[val]);
  39. } else {
  40. map.data[key](val);
  41. }
  42. }
  43. //events
  44. for (var eventName in events) {
  45. map.data.addListener(eventName, events[eventName]);
  46. }
  47. });
  48. }
  49. }; // return
  50. }]);
  51. })();