JSFiddle - React, Tailwind, and code Playground
HTML
<ul class="list"></ul>
<div id="map"></div>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA3FpNuRMglMzadaYh9gp03ekJrZNHNiFA&callback=initMap">
</script>
CSS
.list {
border-radius: 20px;
background-color: #253574;
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
z-index: 999;
display: flex;
align-items: center;
list-style-type: none;
padding: 20px 30px;
margin: 0;
}
.list li + li {
margin-left: 15px;
}
.list a {
color: #fff;
font-weight: 500;
text-decoration: none;
}
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
function initMap() {
const map = new google.maps.Map(document.getElementById('map'), {
center: new google.maps.LatLng(11.397, 30.644),
zoom: 3,
});
const icons = {
info: {
icon: 'http://web-dnepr.ru/earth/img/map-marker.svg'
}
};
const features = [ {
position: new google.maps.LatLng(18.425498298, -64.620497518),
type: 'info',
title: 'Road Town',
}, {
position: new google.maps.LatLng(19.333332, -81.2166658),
type: 'info',
}, {
position: new google.maps.LatLng(46.204391, 6.143158),
type: 'info',
}, {
position: new google.maps.LatLng(48.864716, 2.349014),
type: 'info',
title: 'Paris',
}, {
position: new google.maps.LatLng(25.276987, 55.296249),
type: 'info',
title: 'Dubai',
}, {
position: new google.maps.LatLng(55.751244, 37.618423),
type: 'info',
title: 'Moscow',
}, {
position: new google.maps.LatLng(50.45466, 30.5238),
type: 'info',
}, {
position: new google.maps.LatLng(31.963158, 35.930359),
type: 'info',
}, {
position: new google.maps.LatLng(1.290270, 103.851959),
type: 'info',
}, {
position: new google.maps.LatLng(53.350140, -6.266155),
type: 'info',
} ];
function onMarkerClick(e) {
map.setZoom(10);
map.panTo(e.latLng);
}
for (const f of features) {
const marker = new google.maps.Marker({
position: f.position,
icon: icons[f.type].icon,
map,
});
marker.addListener('click', onMarkerClick);
}
const ul = document.querySelector('ul');
ul.innerHTML = features
.map((n, i) => n.title && `<li data-index="${i}"><a href="#">${n.title}</a></li>`)
.filter(Boolean)
.join('');
ul.addEventListener('click', function(e) {
const li = e.target.closest('li');
if (li) {
map.setZoom(10);
map.setCenter(features[li.dataset.index].position);
}
});
}