summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/adv_graphgen/map.html
blob: f66832d1ce7cc85bef3ab9a32f7179f790d90022 (plain)
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
85
86
87
88
89
90


<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.ui.map.js"></script>
    <script>
      var map;
      var markerlist ={};
      function addInfoWindow(marker, message) {
        var info = message;

        var infoWindow = new google.maps.InfoWindow({
          content: message
        });

        google.maps.event.addListener(marker, 'click', function () {

          // close all the infowindows
          $.each(markerlist,function (k,v){
            v["infowin"].close()
          });
          infoWindow.open(map, marker);
        });
        return infoWindow;
      }
      function initialize() {
        var mapOptions = {
          zoom: 5,
          center: new google.maps.LatLng(51,9),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);

        $.getJSON("marker.json",function (data){
          $.each(data,function (k,v) {
           jitter1=0.005 - Math.random()*0.01
           jitter2=0.005 - Math.random()*0.01

            // add initial marker
            var pt=new google.maps.LatLng(jitter1+v["latitude"],jitter2+v["longitude"])
            var marker= new google.maps.Marker({
              id: k,map:map,title: k,position:pt,content:k})

            // add edges
            $.each(v["to"],function(iter,val){
              var line = [
              pt,
              new google.maps.LatLng(val['latitude'],val['longitude'])
        ]
              
              var  connector = new google.maps.Polyline({
                path:line,
                strokeColor: "#FF0000",
                strokeOpacity: 1.0,
                strokeWeight: 2
              })
              connector.setMap(map);
              val["line"]=connector

            })

          
            marker["infowin"]=addInfoWindow(marker,k+'<br/>'+v["city"]);
            markerlist[k] = marker;
          }); 
        })
      }; 

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

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>