Completed
Pull Request — develop (#232)
by
unknown
04:13 queued 02:00
created

helper.js ➔ addInfoWindowToMarker   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 11
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
A helper.js ➔ ... ➔ ??? 0 3 1
1
/* globals google */
2
3
import $ from 'jquery'
4
5
/**
6
 * Concatenates default settings and user-defined settings to one object for use in maps object
7
 * @param  {object} location    [object containing latitude, longitude and zoom value]
8
 * @param  {object} mapSettings [google maps api configuration object]
9
 * @param  {object} mapStyles   [google maps styling configuration object]
10
 * @return {object}             [concatenated object with all options]
11
 */
12
export function assignMapsSettings (location, mapSettings, mapStyles) {
13
  Object.assign(mapSettings, {
14
    scrollwheel: false,
15
    styles: mapStyles,
16
    center: {
17
      lat: location.lat,
18
      lng: location.lng
19
    },
20
    zoom: location.zoom
21
  })
22
23
  return mapSettings
24
}
25
26
/**
27
 * Concatenates default settings and user-defined settings to one object for use in marker object
28
 * @param  {object} location        [object containing lat and lang value]
29
 * @param  {object} markerSettings  [google maps api marker configuration object]
30
 * @param  {object} map             [google maps object]
31
 * @return {object}                 [concatenated object with all options]
32
 */
33
export function assignMarkerSettings (location, markerSettings, map) {
34
  Object.assign(markerSettings, {
35
    position: {
36
      lat: location.lat,
37
      lng: location.lng
38
    },
39
    map: map
40
  })
41
42
  return markerSettings
43
}
44
45
/**
46
 * Adds a Google Maps Info Window to a marker
47
 * @param {string} content  [HTML content for the marker]
48
 * @param {object} marker   [Google maps marker object]
49
 * @param {object} map      [Google maps map object]
50
 * @return {object}         [Google maps info window object]
51
 */
52
export function addInfoWindowToMarker (content, marker, map) {
53
  const infoWindow = new google.maps.InfoWindow({
54
    content: content
55
  })
56
57
  marker.addListener('click', () => {
58
    infoWindow.open(map, marker)
59
  })
60
61
  return infoWindow
62
}
63
64
/**
65
 * Resets a google map to a certain location
66
 * @param {object} location [object containing lat and lang values]
67
 * @param {object} map      [google maps object]
68
 */
69
export function resetMap (location, map) {
70
  map.setCenter({
71
    lat: location.lat,
72
    lng: location.lng
73
  })
74
75
  map.setZoom(location.zoom)
76
}
77
78
/**
79
 * Returns location of a container containing lat, lng and zoom values in data-attributes
80
 * @param  {object} $container [jQuery object of the container]
81
 * @return {object}            [object containing lat, lng and zoom values]
82
 */
83
export function getLocationFromContainer ($container) {
84
  return {
85
    'lat': parseFloat($container.data('lat')),
86
    'lng': parseFloat($container.data('lng')),
87
    'zoom': parseFloat($container.data('zoom'))
88
  }
89
}
90