source : map-type.js

  1. /**
  2. * @ngdoc directive
  3. * @name map-type
  4. * @param Attr2MapOptions {service}
  5. * convert html attribute to Google map api options
  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. * <map-type name="coordinate" object="coordinateMapType"></map-type>
  15. * </map>
  16. */
  17. (function() {
  18. 'use strict';
  19. angular.module('ngMap').directive('mapType', ['$parse', 'NgMap',
  20. function($parse, 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 mapTypeName = attrs.name, mapTypeObject;
  27. if (!mapTypeName) {
  28. throw "invalid map-type name";
  29. }
  30. mapTypeObject = $parse(attrs.object)(scope);
  31. if (!mapTypeObject) {
  32. throw "invalid map-type object";
  33. }
  34. NgMap.getMap().then(function(map) {
  35. map.mapTypes.set(mapTypeName, mapTypeObject);
  36. });
  37. mapController.addObject('mapTypes', mapTypeObject);
  38. }
  39. }; // return
  40. }]);
  41. })();