gmap.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var GMap = /** @class */ (function () {
  15. function GMap(el, differs, cd, zone) {
  16. this.el = el;
  17. this.cd = cd;
  18. this.zone = zone;
  19. this.onMapClick = new core_1.EventEmitter();
  20. this.onOverlayClick = new core_1.EventEmitter();
  21. this.onOverlayDblClick = new core_1.EventEmitter();
  22. this.onOverlayDragStart = new core_1.EventEmitter();
  23. this.onOverlayDrag = new core_1.EventEmitter();
  24. this.onOverlayDragEnd = new core_1.EventEmitter();
  25. this.onMapReady = new core_1.EventEmitter();
  26. this.onMapDragEnd = new core_1.EventEmitter();
  27. this.onZoomChanged = new core_1.EventEmitter();
  28. this.differ = differs.find([]).create(null);
  29. }
  30. GMap.prototype.ngAfterViewChecked = function () {
  31. if (!this.map && this.el.nativeElement.offsetParent) {
  32. this.initialize();
  33. }
  34. };
  35. GMap.prototype.initialize = function () {
  36. var _this = this;
  37. this.map = new google.maps.Map(this.el.nativeElement.children[0], this.options);
  38. this.onMapReady.emit({
  39. map: this.map
  40. });
  41. if (this.overlays) {
  42. for (var _i = 0, _a = this.overlays; _i < _a.length; _i++) {
  43. var overlay = _a[_i];
  44. overlay.setMap(this.map);
  45. this.bindOverlayEvents(overlay);
  46. }
  47. }
  48. this.map.addListener('click', function (event) {
  49. _this.zone.run(function () {
  50. _this.onMapClick.emit(event);
  51. });
  52. });
  53. this.map.addListener('dragend', function (event) {
  54. _this.zone.run(function () {
  55. _this.onMapDragEnd.emit(event);
  56. });
  57. });
  58. this.map.addListener('zoom_changed', function (event) {
  59. _this.zone.run(function () {
  60. _this.onZoomChanged.emit(event);
  61. });
  62. });
  63. };
  64. GMap.prototype.bindOverlayEvents = function (overlay) {
  65. var _this = this;
  66. overlay.addListener('click', function (event) {
  67. _this.zone.run(function () {
  68. _this.onOverlayClick.emit({
  69. originalEvent: event,
  70. 'overlay': overlay,
  71. map: _this.map
  72. });
  73. });
  74. });
  75. overlay.addListener('dblclick', function (event) {
  76. _this.zone.run(function () {
  77. _this.onOverlayDblClick.emit({
  78. originalEvent: event,
  79. 'overlay': overlay,
  80. map: _this.map
  81. });
  82. });
  83. });
  84. if (overlay.getDraggable()) {
  85. this.bindDragEvents(overlay);
  86. }
  87. };
  88. GMap.prototype.ngDoCheck = function () {
  89. var _this = this;
  90. var changes = this.differ.diff(this.overlays);
  91. if (changes && this.map) {
  92. changes.forEachRemovedItem(function (record) {
  93. google.maps.event.clearInstanceListeners(record.item);
  94. record.item.setMap(null);
  95. });
  96. changes.forEachAddedItem(function (record) {
  97. record.item.setMap(_this.map);
  98. record.item.addListener('click', function (event) {
  99. _this.zone.run(function () {
  100. _this.onOverlayClick.emit({
  101. originalEvent: event,
  102. overlay: record.item,
  103. map: _this.map
  104. });
  105. });
  106. });
  107. if (record.item.getDraggable()) {
  108. _this.bindDragEvents(record.item);
  109. }
  110. });
  111. }
  112. };
  113. GMap.prototype.bindDragEvents = function (overlay) {
  114. var _this = this;
  115. overlay.addListener('dragstart', function (event) {
  116. _this.zone.run(function () {
  117. _this.onOverlayDragStart.emit({
  118. originalEvent: event,
  119. overlay: overlay,
  120. map: _this.map
  121. });
  122. });
  123. });
  124. overlay.addListener('drag', function (event) {
  125. _this.zone.run(function () {
  126. _this.onOverlayDrag.emit({
  127. originalEvent: event,
  128. overlay: overlay,
  129. map: _this.map
  130. });
  131. });
  132. });
  133. overlay.addListener('dragend', function (event) {
  134. _this.zone.run(function () {
  135. _this.onOverlayDragEnd.emit({
  136. originalEvent: event,
  137. overlay: overlay,
  138. map: _this.map
  139. });
  140. });
  141. });
  142. };
  143. GMap.prototype.getMap = function () {
  144. return this.map;
  145. };
  146. __decorate([
  147. core_1.Input(),
  148. __metadata("design:type", Object)
  149. ], GMap.prototype, "style", void 0);
  150. __decorate([
  151. core_1.Input(),
  152. __metadata("design:type", String)
  153. ], GMap.prototype, "styleClass", void 0);
  154. __decorate([
  155. core_1.Input(),
  156. __metadata("design:type", Object)
  157. ], GMap.prototype, "options", void 0);
  158. __decorate([
  159. core_1.Input(),
  160. __metadata("design:type", Array)
  161. ], GMap.prototype, "overlays", void 0);
  162. __decorate([
  163. core_1.Output(),
  164. __metadata("design:type", core_1.EventEmitter)
  165. ], GMap.prototype, "onMapClick", void 0);
  166. __decorate([
  167. core_1.Output(),
  168. __metadata("design:type", core_1.EventEmitter)
  169. ], GMap.prototype, "onOverlayClick", void 0);
  170. __decorate([
  171. core_1.Output(),
  172. __metadata("design:type", core_1.EventEmitter)
  173. ], GMap.prototype, "onOverlayDblClick", void 0);
  174. __decorate([
  175. core_1.Output(),
  176. __metadata("design:type", core_1.EventEmitter)
  177. ], GMap.prototype, "onOverlayDragStart", void 0);
  178. __decorate([
  179. core_1.Output(),
  180. __metadata("design:type", core_1.EventEmitter)
  181. ], GMap.prototype, "onOverlayDrag", void 0);
  182. __decorate([
  183. core_1.Output(),
  184. __metadata("design:type", core_1.EventEmitter)
  185. ], GMap.prototype, "onOverlayDragEnd", void 0);
  186. __decorate([
  187. core_1.Output(),
  188. __metadata("design:type", core_1.EventEmitter)
  189. ], GMap.prototype, "onMapReady", void 0);
  190. __decorate([
  191. core_1.Output(),
  192. __metadata("design:type", core_1.EventEmitter)
  193. ], GMap.prototype, "onMapDragEnd", void 0);
  194. __decorate([
  195. core_1.Output(),
  196. __metadata("design:type", core_1.EventEmitter)
  197. ], GMap.prototype, "onZoomChanged", void 0);
  198. GMap = __decorate([
  199. core_1.Component({
  200. selector: 'p-gmap',
  201. template: "<div [ngStyle]=\"style\" [class]=\"styleClass\"></div>"
  202. }),
  203. __metadata("design:paramtypes", [core_1.ElementRef, core_1.IterableDiffers, core_1.ChangeDetectorRef, core_1.NgZone])
  204. ], GMap);
  205. return GMap;
  206. }());
  207. exports.GMap = GMap;
  208. var GMapModule = /** @class */ (function () {
  209. function GMapModule() {
  210. }
  211. GMapModule = __decorate([
  212. core_1.NgModule({
  213. imports: [common_1.CommonModule],
  214. exports: [GMap],
  215. declarations: [GMap]
  216. })
  217. ], GMapModule);
  218. return GMapModule;
  219. }());
  220. exports.GMapModule = GMapModule;
  221. //# sourceMappingURL=gmap.js.map