function initMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 13, center: { lat: 33.678, lng: -116.243 }, mapTypeId: google.maps.MapTypeId.TERRAIN }); var drawingManager = new google.maps.drawing.DrawingManager({ drawingMode: google.maps.drawing.OverlayType.POLYGON, drawingControl: true, drawingControlOptions: { position: google.maps.ControlPosition.TOP_CENTER, drawingModes: [ google.maps.drawing.OverlayType.POLYGON ] } }); drawingManager.setMap(map); google.maps.event.addListener(drawingManager, "overlaycomplete", function (event) { var polygon = event.overlay; google.maps.event.addListener(polygon, 'click', function (e) { autoRotatePolygon(polygon, 5); }); }); } function autoRotatePolygon(polygon, angle) { window.setInterval(function () { rotatePolygon(polygon, 5); }, 250); } function rotatePolygon(polygon,angle) { var map = polygon.getMap(); var prj = map.getProjection(); var origin = prj.fromLatLngToPoint(polygon.getPath().getAt(0));
html, body { height: 100%; margin: 0; padding: 0; } #map { height: 100%; }
<div id="map"></div> <script async defer src="https://maps.googleapis.com/maps/api/js?callback=initMap&libraries=drawing"></script>