source : overlay-map-type.js

  1. /**
  2. * @ngdoc directive
  3. * @name overlay-map-type
  4. * @param Attr2MapOptions {service} convert html attribute to Google map api options
  5. * @param $window {service}
  6. * @description
  7. * Requires: map directive
  8. * Restrict To: Element
  9. *
  10. * @example
  11. * Example:
  12. *
  13. * <map zoom="13" center="34.04924594193164, -118.24104309082031">
  14. * <overlay-map-type index="0" object="coordinateMapType"></map-type>
  15. * </map>
  16. */
  17. (function() {
  18. 'use strict';
  19. angular.module('ngMap').directive('overlayMapType', [
  20. 'NgMap', function(NgMap) {
  21. return {
  22. restrict: 'E',
  23. require: ['?^map','?^ngMap'],
  24. link: function(scope, element, attrs, mapController) {
  25. mapController = mapController[0]||mapController[1];
  26. var initMethod = attrs.initMethod || "insertAt";
  27. var overlayMapTypeObject = scope[attrs.object];
  28. NgMap.getMap().then(function(map) {
  29. if (initMethod == "insertAt") {
  30. var index = parseInt(attrs.index, 10);
  31. map.overlayMapTypes.insertAt(index, overlayMapTypeObject);
  32. } else if (initMethod == "push") {
  33. map.overlayMapTypes.push(overlayMapTypeObject);
  34. }
  35. });
  36. mapController.addObject('overlayMapTypes', overlayMapTypeObject);
  37. }
  38. }; // return
  39. }]);
  40. })();