1
|
|
|
class Marker { |
2
|
|
|
|
3
|
|
|
constructor(options = {}, map) { |
4
|
|
|
this.map = map; |
5
|
|
|
|
6
|
|
|
this.defaults = { |
7
|
|
|
instanceId: null, |
8
|
|
|
location: null, |
9
|
|
|
address: '', |
10
|
|
|
coordinates: '', |
11
|
|
|
displayWindow: false, |
12
|
|
|
content: '', |
13
|
|
|
icon: '', |
14
|
|
|
markerImage: null, |
15
|
|
|
draggable: false, |
16
|
|
|
/** |
17
|
|
|
* show info window event type: |
18
|
|
|
* click - only show window when clicking on marker |
19
|
|
|
* hover - only show window when mouse over/out marker |
20
|
|
|
*/ |
21
|
|
|
infoWindowOn: 'click', |
22
|
|
|
events: { |
23
|
|
|
onClick: (marker) => { |
|
|
|
|
24
|
|
|
|
25
|
|
|
}, |
26
|
|
|
|
27
|
|
|
onMouseover: (marker) => { |
|
|
|
|
28
|
|
|
|
29
|
|
|
}, |
30
|
|
|
|
31
|
|
|
onMouseout: (marker) => { |
|
|
|
|
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
}; |
36
|
|
|
|
37
|
|
|
this.temporary = {}; |
38
|
|
|
|
39
|
|
|
if ('events' in options) { |
40
|
|
|
options.events = Object.assign(this.defaults.events, options.events); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
this.options = Object.assign(this.defaults, options); |
44
|
|
|
|
45
|
|
|
this.createInstance(); |
46
|
|
|
this.bindEvents(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
update(settings = {}) { |
50
|
|
|
this.options = Object.assign(this.options, settings); |
51
|
|
|
|
52
|
|
|
if ('location' in settings) { |
53
|
|
|
this.instance.setPosition(settings.location); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if ('coordinates' in settings) { |
57
|
|
|
let coordinates = settings.coordinates.split(',').map(Number).filter(x => !isNaN(x)); |
58
|
|
|
this.options.location = new google.maps.LatLng(coordinates[0], coordinates[1]); |
|
|
|
|
59
|
|
|
this.instance.setPosition(this.options.location); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
getCoordinates() { |
64
|
|
|
return `${this.instance.getPosition().lat()}, ${this.instance.getPosition().lng()}`; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
getData() { |
68
|
|
|
return { |
69
|
|
|
InstanceId: this.options.instanceId, |
70
|
|
|
Address: this.options.address, |
71
|
|
|
Coordinates: this.getCoordinates(), |
72
|
|
|
Content: this.options.content, |
73
|
|
|
DisplayWindow: this.options.displayWindow |
74
|
|
|
}; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
createInstance() { |
78
|
|
|
if (this.options.location == null && this.options.coordinates != '') { |
79
|
|
|
let coordinates = this.options.coordinates.split(',').map(Number).filter(x => !isNaN(x)); |
80
|
|
|
|
81
|
|
|
this.options.location = new google.maps.LatLng(coordinates[0], coordinates[1]); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
this.instance = new google.maps.Marker({ |
85
|
|
|
map: this.map, |
86
|
|
|
icon: this.options.markerImage || this.options.icon, |
87
|
|
|
position: this.options.location, |
88
|
|
|
draggable: this.options.draggable |
89
|
|
|
}); |
90
|
|
|
|
91
|
|
|
this.instance.infoWindow = new google.maps.InfoWindow({ |
92
|
|
|
content: this.options.content |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
bindEvents() { |
97
|
|
|
switch (this.options.infoWindowOn) { |
98
|
|
|
case 'click': |
99
|
|
|
|
100
|
|
|
google.maps.event.addListener(this.instance, 'click', () => { |
|
|
|
|
101
|
|
|
this.options.events.onClick(this); |
102
|
|
|
|
103
|
|
|
this.open(); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
break; |
107
|
|
|
|
108
|
|
|
case 'hover': |
109
|
|
|
|
110
|
|
|
google.maps.event.addListener(this.instance, 'mouseover', () => { |
|
|
|
|
111
|
|
|
this.options.events.onMouseover(this); |
112
|
|
|
|
113
|
|
|
this.open(); |
114
|
|
|
}); |
115
|
|
|
|
116
|
|
|
google.maps.event.addListener(this.instance, 'mouseout', () => { |
|
|
|
|
117
|
|
|
this.options.events.onMouseout(this); |
118
|
|
|
|
119
|
|
|
this.close(); |
120
|
|
|
}); |
121
|
|
|
|
122
|
|
|
break; |
123
|
|
|
|
124
|
|
|
default: |
125
|
|
|
return; |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
getInstanceId() { |
130
|
|
|
return this.options.instanceId; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
open() { |
134
|
|
|
if (this.options.displayWindow) { |
135
|
|
|
this.instance.infoWindow.open(this.map, this.instance); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
close() { |
140
|
|
|
this.instance.infoWindow.close(); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
export default Marker; |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.