PageSourceSearch

https://www.rod-group.com/wp-content/themes/strukture/scripts/maps.js?ver=1789586078

js rod-group.com collected 2026-09-24 08:56:18 UTC 4,244 bytes, 133 lines download raw bytes

1function acfMapInit() {
2    const mapEls = document.querySelectorAll('.acf-map');
3    if (mapEls) {
4        mapEls.forEach((mapEl) => {
5            let map;
6            const addresses = mapEl.dataset.addresses;
7            if (addresses) {
8                let dataPositions = [];
9                JSON.parse(atob(addresses)).forEach((address) => {
10                    dataPositions.push(
11                        {
12                            position: new google.maps.LatLng(address['address'].lat, address['address'].lng),
13                            icon: mapEl.dataset.markerIcon,
14                            infoWindow: address['info_window']
15                        }
16                    )
17                });
18                // default vars
19                let args = {
20                    zoom: mapEl.dataset.zoom ? mapEl.dataset.zoom : 8,
21                    center: new google.maps.LatLng(0, 0),
22                    styles: JSON.parse(atob(mapEl.dataset.mapStyle)),
23                };
24
25                map = new google.maps.Map(mapEl, args);
26                new_map(mapEl, dataPositions, map);
27            }
28        })
29    }
30}
31
32/* assign to window for google callback */
33window.initMap = function () {
34    acfMapInit();
35};
36
37
38/* handle creation of each mapEL */
39function new_map(mapEl, dataPositions, map) {
40    // add a markers reference
41    map.markers = [];
42    map.activeInfoWindow = null;
43
44    // handle infoWindow logic
45    const customInfoWindowMarkup = mapEl.dataset.infoHtml ? mapEl.dataset.infoHtml : false;
46
47    dataPositions.forEach((pos) => {
48        const marker = new google.maps.Marker({
49            ...pos,
50            map: map,
51        });
52        map.markers.push(marker);
53        if (pos.hasOwnProperty('infoWindow')) {
54            createInfoWindow(pos.infoWindow, marker, map, customInfoWindowMarkup);
55        }
56    });
57
58    // center map
59    center_map(mapEl, map);
60
61    // return
62    return map;
63}
64
65function createInfoWindow(infoWindowData, marker, map, customInfoWindowMarkup) {
66
67    /* we're only going to do it if we actually HAVE something to show. */
68    if (!infoWindowData.content && !infoWindowData.title && !infoWindowData.url) {
69        return;
70    }
71
72    let htmlContent = null;
73
74    if (customInfoWindowMarkup) {
75        /*
76        * todo:
77        *  - customInfoWindowMarkup should be a 100% functional, valid HTML element.
78        *  - go through each infoWindowData property and assign it to a matching el in the customInfoWindowMarkup
79        *  - customInfoWindowMarkup MUST have corresponding HTML element for fields to map and render
80        * */
81    } else {
82        htmlContent =
83            `<div class="info-window">
84                ${infoWindowData.title ?
85                `<div class="info-window__title" data-id="title">${infoWindowData.title}</div>`
86                : ''
87            }
88                 ${infoWindowData.content ?
89                `<div class="info-window__content" data-id="content">${infoWindowData.content}</div>`
90                : ''
91            }
92                ${infoWindowData.url ?
93                `<a href="${infoWindowData.url}">Read More</a>`
94                : ''
95            }
96            </div>`;
97    }
98
99
100    const infoWindow = new google.maps.InfoWindow({
101        content: htmlContent
102    });
103
104    // show info window when marker is clicked
105    google.maps.event.addListener(marker, 'click', function () {
106        if (map.activeInfoWindow) {
107            map.activeInfoWindow.close();
108        }
109        infoWindow.open(map, marker);
110        map.activeInfoWindow = infoWindow;
111    });
112}
113
114function center_map(mapEl, map) {
115
116    // vars
117    const bounds = new google.maps.LatLngBounds();
118
119    // loop through all markers and create bounds
120    map.markers.forEach((marker) => {
121        const latLng = new google.maps.LatLng(marker.position.lat(), marker.position.lng());
122        bounds.extend(latLng);
123    })
124
125    // only 1 marker?
126    if (map.markers.length === 1) {
127        map.setCenter(bounds.getCenter());
128        map.setZoom(mapEl.dataset.zoom ? mapEl.dataset.zoom : 16);
129    } else {
130        map.fitBounds(bounds);
131    }
132
133}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.