-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleInfoWindow.ts
65 lines (50 loc) · 1.59 KB
/
GoogleInfoWindow.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @project MyGPService v4
* @author Žan Kafol on 7.1.2019
*/
import {MapInfoWindow, MapPosition, MarkerOptions} from './MapInterface'
import {GoogleMap} from './GoogleMap'
import {GoogleObject} from './GoogleObject'
export class GoogleInfoWindow extends GoogleObject<google.maps.InfoWindow> implements MapInfoWindow<google.maps.InfoWindow, google.maps.Map> {
private closeCallback: Function;
private parent: google.maps.MVCObject;
public map: GoogleMap;
public instance: google.maps.InfoWindow;
public constructor(map: GoogleMap, position: MarkerOptions, parent?: any) {
super(map)
this.instance = new google.maps.InfoWindow()
if(position) {
this.setPosition(position)
}
if(parent) {
this.parent = parent.instance
}
this.addInternalListeners(this.instance)
this.instance.addListener('closeclick', this.close.bind(this))
this.open()
}
public setPosition(position: MapPosition): void {
this.instance.setPosition({lat: position.lat, lng: position.lon})
}
public getPosition(): MapPosition {
return {lat: this.instance.getPosition().lat(), lon: this.instance.getPosition().lng()}
}
public setParent(parent: any) {
this.parent = parent.instance
}
public setContent(content: string | HTMLElement) {
this.instance.setContent(content)
}
public onClose(callback: Function): void {
this.closeCallback = callback
}
public open(): void {
this.instance.open(this.map.instance, this.parent)
}
public close(): void {
this.instance.close()
if(this.closeCallback) {
this.closeCallback()
}
}
}