Completed
Push — Component-MapsGoogle ( 93e8ff...519692 )
by
unknown
03:25
created

helper.js ➔ getLocationFromContainer   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

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