JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,places&ext=.js"></script>
<div id="map-canvas" style="border: 2px solid #3872ac;"></div>
<input id="hide" type="button" value="hide" />
<input id="show" type="button" value="show" />
CSS
html, body, #map-canvas {
height: 500px;
width: 500px;
margin: 0px;
padding: 0px
}
JavaScript
function initialize() {
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0, -180),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(37.772323, -122.214897),
new google.maps.LatLng(21.291982, -157.821856),
new google.maps.LatLng(-18.142599, 178.431),
new google.maps.LatLng(-27.46758, 153.027892)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
google.maps.event.addDomListener(document.getElementById('hide'), 'click', function() {
flightPath.setOptions({strokeOpacity:0});
});
google.maps.event.addDomListener(document.getElementById('show'), 'click', function() {
flightPath.setOptions({strokeOpacity:1.0});
});
}
google.maps.event.addDomListener(window, 'load', initialize);