circles.js 2.32 KB
Newer Older
sistem17user committed
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/* ------------------------------------------------------------------------------
*
*  # Circles
*
*  Specific JS code additions for maps_google_drawings.html page
*
*  Version: 1.0
*  Latest update: Aug 1, 2015
*
* ---------------------------------------------------------------------------- */

$(function() {

    // This example creates circles on the map, representing
    // populations in North America.

    // First, create an object containing LatLng and population for each city.
    var citymap = {};
    citymap['wroclaw'] = {
        center: new google.maps.LatLng(51.112, 17.052),
        population: 271485
    };
    citymap['budapest'] = {
        center: new google.maps.LatLng(47.481, 19.130),
        population: 840583
    };
    citymap['kernstadt'] = {
        center: new google.maps.LatLng(51.720, 8.764),
        population: 385779
    };
    citymap['nancy'] = {
        center: new google.maps.LatLng(48.688, 6.173),
        population: 603502
    };
    citymap['munich'] = {
        center: new google.maps.LatLng(48.154, 11.541),
        population: 594039
    };
    citymap['warsaw'] = {
        center: new google.maps.LatLng(52.232, 21.061),
        population: 492093
    };


    // Initialize
    var cityCircle;
    function initialize() {

        // Options
        var mapOptions = {
            zoom: 6,
            center: new google.maps.LatLng(50.059, 14.465),
            mapTypeId: google.maps.MapTypeId.TERRAIN
        };

        // Apply options
        var map = new google.maps.Map($('.map-drawing-circles')[0], mapOptions);


        // Construct the circle for each value in citymap.
        // Note: We scale the area of the circle based on the population.
        for (var city in citymap) {

            // Options
            var populationOptions = {
                strokeColor: '#b41b1b',
                strokeOpacity: 0.5,
                strokeWeight: 1,
                fillColor: '#b41b1b',
                fillOpacity: 0.2,
                map: map,
                center: citymap[city].center,
                radius: Math.sqrt(citymap[city].population) * 100
            };

            // Add the circle for this city to the map.
            cityCircle = new google.maps.Circle(populationOptions);
        }
    }

    // Load map
    google.maps.event.addDomListener(window, 'load', initialize);

});