PageSourceSearch

https://www.jims.be/cpresources/c18819eb/js/googlemaps.js?v=1778518854

js jims.be collected 2026-10-09 04:45:31 UTC 10,906 bytes, 366 lines download raw bytes

1// Google Maps plugin JS object
2window.googleMaps = window.googleMaps || {
3
4    // Log progress to console (enabled in devMode)
5    log: (window._gmData ? window._gmData.logging : false),
6
7    // Initialize collection of maps
8    _maps: {},
9
10    // ========================================================================= //
11
12    // Create a new map object
13    map: function (locations, options) {
14
15        // Log status
16        if (this.log) {
17            console.log(`============================================================`);
18            console.log(`Creating a new map object`);
19        }
20
21        // Create a new map object
22        var map = new DynamicMap(locations, options);
23
24        // Store map object for future reference
25        this._maps[map.id] = map;
26
27        // Return the map object
28        return map;
29    },
30
31    // Get a specified map object
32    getMap: function(mapId, assumeSuccess) {
33
34        // Log status (if success is not assumed)
35        if (this.log && !assumeSuccess) {
36            console.log(`============================================================`);
37            console.log(`[${mapId}] Getting existing map`);
38        }
39
40        // Get existing map
41        var map = this._maps[mapId];
42
43        // If map does not exist, emit warning
44        if (!map) {
45            console.warn(`[GM] Unable to find map "${mapId}"`);
46        }
47
48        // Return map
49        return map;
50    },
51
52    // ========================================================================= //
53
54    // Initialize specified maps
55    init: function(mapId, callback) {
56
57        // Initialize
58        var map, dna, matchingContainers;
59
60        // Get selected map containers
61        var containers = this._whichMaps(mapId);
62
63        // If no _gmData object exists, emit warning
64        if (!window._gmData) {
65            console.warn(`[GM] The window._gmData object has not been defined`);
66        }
67
68        // Loop through containers
69        for (var i in containers) {
70
71            // Get each map
72            map = containers[i];
73
74            // If map doesn't exist, skip it
75            if (!map) {
76                console.warn(`[GM] Cannot find specified map container #${mapId}`);
77                continue;
78            }
79
80            // Count the number of matching containers (should ideally be 1)
81            matchingContainers = document.querySelectorAll(`#${map.id}`).length;
82
83            // If no matching containers exist, skip it
84            if (!matchingContainers) {
85                console.warn(`[GM] No DOM element exists using the identifier #${map.id}`);
86                continue;
87            }
88
89            // If multiple matching containers exist, skip it
90            if (1 < matchingContainers) {
91                console.warn(`[GM] Multiple DOM elements are using the identifier #${map.id}`);
92                continue;
93            }
94
95            // Log status
96            if (this.log) {
97                console.log(`============================================================`);
98                console.log(`[${map.id}] Initializing map`);
99            }
100
101            // Get DNA of each map
102            dna = map.dataset.dna;
103
104            // If no DNA exists, skip it
105            if (!dna) {
106                console.warn(`[GM] Map container #${map.id} is missing DNA`);
107                continue;
108            }
109
110            // Render each map
111            this._unpack(dna);
112
113            // Get dynamic map
114            let dynamicMap = this.getMap(map.id, true);
115
116            // If _gmData object exists
117            if (window._gmData ?? null) {
118
119                // Get data for info windows and marker callbacks
120                const _infoWindows     = window._gmData.infoWindows[map.id]     || [];
121                const _markerCallbacks = window._gmData.markerCallbacks[map.id] || [];
122
123                // If any info windows were specified
124                if (Object.keys(_infoWindows).length) {
125
126                    // Log status
127                    if (this.log) {
128                        console.log(`[${map.id}] Activating all info windows`);
129                    }
130
131                    // Loop through info windows of current map
132                    for (let markerId in _infoWindows) {
133                        // Get info window
134                        let infoWindow = _infoWindows[markerId];
135                        // Activate info window function
136                        dynamicMap._initInfoWindow(markerId, infoWindow);
137                    }
138
139                }
140
141                // If any marker callbacks were specified
142                if (Object.keys(_markerCallbacks).length) {
143
144                    // Log status
145                    if (this.log) {
146                        console.log(`[${map.id}] Activating all marker callbacks`);
147                    }
148
149                    // Loop through marker callbacks of current map
150                    for (let markerId in _markerCallbacks) {
151                        // Get marker callback
152                        let callback = _markerCallbacks[markerId];
153                        // Activate marker callback function
154                        dynamicMap._initMarkerClick(markerId, callback);
155                    }
156
157                }
158
159            }
160
161        }
162
163        // If map callback was specified and is a function
164        if (callback && 'function' === typeof callback) {
165
166            // Log status
167            if (this.log) {
168                console.log(`[${map.id}] Running map callback function:\n`,callback);
169            }
170
171            // Execute map callback
172            callback();
173
174        }
175
176    },
177
178    // ========================================================================= //
179
180    // Determine which maps to compile
181    _whichMaps: function(selection) {
182
183        // No map containers by default
184        var containers = [];
185
186        // Switch according to how map IDs were specified
187        switch (typeof selection) {
188
189            // Individual map
190            case 'string':
191                containers = [document.getElementById(selection)];
192                break;
193
194            // Selection of maps
195            case 'object':
196
197                // Add each map container to collection
198                var c;
199                for (var i in selection) {
200                    c = document.getElementById(selection[i]);
201                    containers.push(c);
202                }
203                break;
204
205            // All maps
206            case 'undefined':
207                var allMaps = document.getElementsByClassName('gm-map');
208                containers = Array.prototype.slice.call(allMaps);
209                break;
210
211            // Something went wrong
212            default:
213                containers = [];
214                break;
215
216        }
217
218        // Return collection
219        return containers;
220    },
221
222    // Unpack and initialize map DNA
223    _unpack: function(dna) {
224
225        // Unpack the DNA sequence
226        var sequence = JSON.parse(dna);
227
228        // If no DNA exists, error and bail
229        if (!sequence) {
230            console.warn('[GM] No map DNA provided.');
231            return;
232        }
233
234        // Initialize
235        var map,block;
236
237        // Loop through DNA sequence
238        for (var i = 0; i < sequence.length; i++) {
239
240            // Get map DNA block
241            block = sequence[i];
242
243            // If first block is not a map, error and bail
244            if (0 === i && 'map' !== block.type) {
245                console.warn('[GM] Map DNA is misconfigured.');
246                return;
247            }
248
249            // Switch according to DNA block type
250            switch (block.type) {
251
252                // Create a new map
253                case 'map':
254                    map = new DynamicMap(block.locations, block.options);
255                    break;
256
257                // Add markers to the map
258                case 'markers':
259                    map.markers(block.locations, block.options);
260                    break;
261
262                // Add circles to the map
263                case 'circles':
264                    map.circles(block.locations, block.options);
265                    break;
266
267                // Add KML layer to the map
268                case 'kml':
269                    map.kml(block.url, block.options);
270                    break;
271
272                // Style the map
273                case 'styles':
274                    map.styles(block.styleSet);
275                    break;
276
277                // Zoom the map
278                case 'zoom':
279                    map.zoom(block.level);
280                    break;
281
282                // Center the map
283                case 'center':
284                    map.center(block.coords);
285                    break;
286
287                // Fit the map bounds
288                case 'fit':
289                    map.fit();
290                    break;
291
292                // Refresh the map
293                case 'refresh':
294                    map.refresh();
295                    break;
296
297                // Pan to a specific marker
298                case 'panToMarker':
299                    map.panToMarker(block.markerId);
300                    break;
301
302                // Set icon of an existing marker
303                case 'setMarkerIcon':
304                    map.setMarkerIcon(block.markerId, block.icon);
305                    break;
306
307                // Hide a marker
308                case 'hideMarker':
309                    map.hideMarker(block.markerId);
310                    break;
311
312                // Show a marker
313                case 'showMarker':
314                    map.showMarker(block.markerId);
315                    break;
316
317                // Open the info window of a specific marker
318                case 'openInfoWindow':
319                    map.openInfoWindow(block.markerId);
320                    break;
321
322                // Close the info window of a specific marker
323                case 'closeInfoWindow':
324                    map.closeInfoWindow(block.markerId);
325                    break;
326
327                // Hide a circle
328                case 'hideCircle':
329                    map.hideCircle(block.circleId);
330                    break;
331
332                // Show a circle
333                case 'showCircle':
334                    map.showCircle(block.circleId);
335                    break;
336
337                // Hide a KML layer
338                case 'hideKml':
339                    map.hideKml(block.kmlId);
340                    break;
341
342                // Show a KML layer
343                case 'showKml':
344                    map.showKml(block.kmlId);
345                    break;
346
347            }
348
349        }
350
351        // Check to ensure the map is visible
352        map._checkMapVisibility();
353
354        // Log status
355        if (this.log) {
356            console.log(`[${map.id}
356] Finished initializing map 👍`);
357        }
358
359        // Store map object for future reference
360        this._maps[map.id] = map;
361
362        // Return the map object
363        return map;
364    },
365
366};

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.