Circles

by adnan lutfi

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Circles</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBIwzALxUPNbatRBj3Xi1Uhp0fFzwWNBkE&callback=initMap&libraries=&v=weekly"
      defer
    ></script>
    <!-- jsFiddle will insert css and js -->
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

CSS

/* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
#map {
  height: 100%;
}

/* Optional: Makes the sample page fill the window. */
html,
body {
  height: 100vh;
  margin: 0;
  padding: 0;
}

JavaScript

"use strict";

const citymap = {
  center: {
    lat: 37.09,
    lng: -95.712
  },
  population: 2714856
};

function initMap() {
  // Create the map.
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 5,
    center: citymap.center,
    mapTypeId: "roadmap"
  }); // Construct the circle for each value in citymap.
  // Note: We scale the area of the circle based on the population.

  const circle = new google.maps.Circle({
      strokeColor: "#FF0000",
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: "#FF0000",
      fillOpacity: 0.35,
      map,
      center: citymap.center,
      radius: Math.sqrt(citymap.population) * 100,
      editable: true
    });
}