Commits

sweemeng  committed 98fd608 Merge

added new dynamic list, and js

  • Participants
  • Parent commits f419c54, 7bbf4db

Comments (0)

Files changed (1)

File goproj/www/index.html

     var mgr = new MarkerManager(map, {trackMarkers: true, maxZoom: 15});
     var right_panel_width = 200;
     
+    var mgr2 = new MarkerManager(map, {trackMarkers: true, maxZoom: 15});
+    
     $(window).bind('resize', function(){
         $('#map_panel').width($(window).width() - right_panel_width);
     });
               position: new google.maps.LatLng(
                   details.location[0], details.location[1]),
               clickable: false,
-              draggable: true,
+              draggable: false,
               flat: true
             });
+            
           }
+      
+        return markers;
+    }
+    function array_to_markers2(array) {
+        var markers = [];
+        
+        for (var i = 0; i < array.length; i++) {
+            var details = array[i];
+            markers[i] = new google.maps.Marker({
+              title: details.name,
+              position: new google.maps.LatLng(
+                  details.location[0], details.location[1]),
+              clickable: false,
+              draggable: false,
+              flat: true
+            });
+            
+          }
+      
         return markers;
     }
     
             google.maps.event.addListener(mgr, 'loaded', function() {
                 // Have to wait for mgr to be ready, or else we can't draw
                 mgr.clearMarkers();
-                mgr.addMarkers(a , 0, 12);
+                mgr.addMarkers(a , 0, 15);
                 mgr.refresh();
             });
         }
         mylocation = latlng;
     });
+    var marker_location = null;
+    var update_interval = 1000; // milliseconds
+    var update_markers = function() {
+        //console.debug('ping');
+        $.ajax({
+            url: '/position/',
+            dataType: 'json',
+            success: function(data) {
+                var d = [];
+                //console.debug(data.Location);
+                /*
+                if (data.Location[0] > 3) {
+                    var lat = data.Location[1];
+                    data.Location[1] = data.Location[0];
+                    data.Location[0] = lat;
+                }*/
+                d.push({'name': data.Name, 'location': data.Location});
+                var b = array_to_markers2(d);
+                marker_location = data.Location;
+                mgr2.clearMarkers();
+                mgr2.addMarkers(b, 0, 15);
+                mgr2.refresh();
+                
+            }
+        });
+        setTimeout(update_markers, update_interval);
+    }
+    setTimeout(update_markers, update_interval);
     
     $('#current_location').click(function() {
         if (mylocation) {
         map.panTo(latlng);
         return false;
     });
+    $('#goto_marker').click(function() {
+        if (!marker_location) {
+            return false;
+        }
+        var latlng = new google.maps.LatLng(marker_location[0],  marker_location[1]);
+        //console.debug(marker_location);
+        map.panTo(latlng);
+        return false;
+    });
 });
 </script>
     
     <ul>
         <li><a href='#' id='goto_malaysia'>Zoom Malaysia</a></li>
         <li><a href='#' id='current_location'>Go to current Location</a></li>
+        <li><a href='#' id='goto_marker'>Go to marker position</a></li>
     </ul>
 </div>