Completed
Push — master ( f2c63f...720388 )
by Donata
02:09
created

Marker.js ➔ ???   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
dl 0
loc 45
rs 8.8571
c 0
b 0
f 0
nop 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A Marker.js ➔ ... ➔ ??? 0 3 1
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) => {
0 ignored issues
show
Unused Code introduced by
The parameter marker is not used and could be removed.

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.

Loading history...
24
25
                },
26
27
                onMouseover: (marker) => {
0 ignored issues
show
Unused Code introduced by
The parameter marker is not used and could be removed.

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.

Loading history...
28
29
                },
30
31
                onMouseout: (marker) => {
0 ignored issues
show
Unused Code introduced by
The parameter marker is not used and could be removed.

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.

Loading history...
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]);
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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]);
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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', () => {
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
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', () => {
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
111
                    this.options.events.onMouseover(this);
112
113
                    this.open();
114
                });
115
116
                google.maps.event.addListener(this.instance, 'mouseout', () => {
0 ignored issues
show
Bug introduced by
The variable google seems to be never declared. If this is a global, consider adding a /** global: google */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
117
                    this.options.events.onMouseout(this);
118
119
                    this.close();
120
                });
121
122
                break;
123
124
            default:
125
                return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
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;