UNPKG

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