-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapWidget.js
36 lines (32 loc) · 1.09 KB
/
mapWidget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(function() {
/**
* Initialize the map widget with user-defined options.
* @param {Object} options - Custom options for the map (center, zoom).
*/
window.MapWidget = function(options) {
// Set default options if not provided
const defaultOptions = {
selector: '#map',
zoom: 10,
center: { lat: 37.7749, lng: -122.4194 } // Default: San Francisco
};
// Merge user options with default options
const mapOptions = { ...defaultOptions, ...options };
// Find the map container element
const mapElement = document.querySelector(mapOptions.selector);
if (!mapElement) {
console.error('Map container not found');
return;
}
// Initialize Google Map
const map = new google.maps.Map(mapElement, {
center: mapOptions.center,
zoom: mapOptions.zoom
});
// Add a marker at the center location
new google.maps.Marker({
position: mapOptions.center,
map: map
});
};
})();