177 lines
5.6 KiB
JavaScript
177 lines
5.6 KiB
JavaScript
import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ElementRef, IterableDiffers, ChangeDetectorRef, NgZone, Input, Output, NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
class GMap {
|
|
constructor(el, differs, cd, zone) {
|
|
this.el = el;
|
|
this.cd = cd;
|
|
this.zone = zone;
|
|
this.onMapClick = new EventEmitter();
|
|
this.onOverlayClick = new EventEmitter();
|
|
this.onOverlayDblClick = new EventEmitter();
|
|
this.onOverlayDragStart = new EventEmitter();
|
|
this.onOverlayDrag = new EventEmitter();
|
|
this.onOverlayDragEnd = new EventEmitter();
|
|
this.onMapReady = new EventEmitter();
|
|
this.onMapDragEnd = new EventEmitter();
|
|
this.onZoomChanged = new EventEmitter();
|
|
this.differ = differs.find([]).create(null);
|
|
}
|
|
ngAfterViewChecked() {
|
|
if (!this.map && this.el.nativeElement.offsetParent) {
|
|
this.initialize();
|
|
}
|
|
}
|
|
initialize() {
|
|
this.map = new google.maps.Map(this.el.nativeElement.children[0], this.options);
|
|
this.onMapReady.emit({
|
|
map: this.map
|
|
});
|
|
if (this.overlays) {
|
|
for (let overlay of this.overlays) {
|
|
overlay.setMap(this.map);
|
|
this.bindOverlayEvents(overlay);
|
|
}
|
|
}
|
|
this.map.addListener('click', (event) => {
|
|
this.zone.run(() => {
|
|
this.onMapClick.emit(event);
|
|
});
|
|
});
|
|
this.map.addListener('dragend', (event) => {
|
|
this.zone.run(() => {
|
|
this.onMapDragEnd.emit(event);
|
|
});
|
|
});
|
|
this.map.addListener('zoom_changed', (event) => {
|
|
this.zone.run(() => {
|
|
this.onZoomChanged.emit(event);
|
|
});
|
|
});
|
|
}
|
|
bindOverlayEvents(overlay) {
|
|
overlay.addListener('click', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayClick.emit({
|
|
originalEvent: event,
|
|
'overlay': overlay,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
overlay.addListener('dblclick', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayDblClick.emit({
|
|
originalEvent: event,
|
|
'overlay': overlay,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
if (overlay.getDraggable()) {
|
|
this.bindDragEvents(overlay);
|
|
}
|
|
}
|
|
ngDoCheck() {
|
|
let changes = this.differ.diff(this.overlays);
|
|
if (changes && this.map) {
|
|
changes.forEachRemovedItem((record) => {
|
|
google.maps.event.clearInstanceListeners(record.item);
|
|
record.item.setMap(null);
|
|
});
|
|
changes.forEachAddedItem((record) => {
|
|
record.item.setMap(this.map);
|
|
record.item.addListener('click', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayClick.emit({
|
|
originalEvent: event,
|
|
overlay: record.item,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
if (record.item.getDraggable()) {
|
|
this.bindDragEvents(record.item);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
bindDragEvents(overlay) {
|
|
overlay.addListener('dragstart', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayDragStart.emit({
|
|
originalEvent: event,
|
|
overlay: overlay,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
overlay.addListener('drag', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayDrag.emit({
|
|
originalEvent: event,
|
|
overlay: overlay,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
overlay.addListener('dragend', (event) => {
|
|
this.zone.run(() => {
|
|
this.onOverlayDragEnd.emit({
|
|
originalEvent: event,
|
|
overlay: overlay,
|
|
map: this.map
|
|
});
|
|
});
|
|
});
|
|
}
|
|
getMap() {
|
|
return this.map;
|
|
}
|
|
}
|
|
GMap.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-gmap',
|
|
template: `<div [ngStyle]="style" [class]="styleClass"></div>`,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None
|
|
},] }
|
|
];
|
|
GMap.ctorParameters = () => [
|
|
{ type: ElementRef },
|
|
{ type: IterableDiffers },
|
|
{ type: ChangeDetectorRef },
|
|
{ type: NgZone }
|
|
];
|
|
GMap.propDecorators = {
|
|
style: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
options: [{ type: Input }],
|
|
overlays: [{ type: Input }],
|
|
onMapClick: [{ type: Output }],
|
|
onOverlayClick: [{ type: Output }],
|
|
onOverlayDblClick: [{ type: Output }],
|
|
onOverlayDragStart: [{ type: Output }],
|
|
onOverlayDrag: [{ type: Output }],
|
|
onOverlayDragEnd: [{ type: Output }],
|
|
onMapReady: [{ type: Output }],
|
|
onMapDragEnd: [{ type: Output }],
|
|
onZoomChanged: [{ type: Output }]
|
|
};
|
|
class GMapModule {
|
|
}
|
|
GMapModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule],
|
|
exports: [GMap],
|
|
declarations: [GMap]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { GMap, GMapModule };
|
|
//# sourceMappingURL=primeng-gmap.js.map
|