← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9231: FRED-API: added infoWindow to markers, wip

 

------------------------------------------------------------
revno: 9231
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-12-09 01:33:34 +0300
message:
  FRED-API: added infoWindow to markers, wip
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm	2012-12-08 22:01:14 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/webapp/WEB-INF/api-fred-velocity/v1/facilities.vm	2012-12-08 22:33:34 +0000
@@ -2,6 +2,9 @@
 <script src="$baseUrl/../../api-fred-resources/js/markerclusterer.min.js"></script>
 
 <script>
+    var markers = [];
+    var infoWindows = [];
+
     $(function () {
         $('.activateButton').click(function () {
             if (confirm('Are you sure you want to activate this facility?')) {
@@ -34,6 +37,7 @@
         var facilities = [
             #foreach( $facility in $entity.facilities )
             {
+                id: "$facility.id",
                 name: "$facility.name",
                 coordinates: "$facility.coordinates"
             },
@@ -41,7 +45,6 @@
         ];
 
         $('#mapLink').click(function() {
-            var markers = [];
 
             var lats = 0.0;
             var lngs = 0.0;
@@ -52,6 +55,9 @@
                     var coords = JSON.parse(item.coordinates);
                     var latlng = new google.maps.LatLng(coords[0], coords[1]);
                     var name = item.name;
+                    var id = item.id;
+
+                    console.log(id);
 
                     lats += coords[0];
                     lngs += coords[1];
@@ -63,13 +69,18 @@
                     });
 
                     markers.push(marker);
+
+                    var infoWindow= new google.maps.InfoWindow({
+                        content: "<div><a href='$baseUrl/facilities/" + id + "'>More information</a></div>"
+                    });
+
+                    infoWindows.push(infoWindow);
                 }
             });
 
             lats = lats / n;
             lngs = lngs / n;
 
-            // var latlng = new google.maps.LatLng(9.0131, -12.9487);
             var latlng = new google.maps.LatLng(lats, lngs);
 
             var options = {
@@ -80,8 +91,13 @@
 
             var map = new google.maps.Map(document.getElementById('mapTarget'), options);
 
-            var markerCluster = new MarkerClusterer(map, markers, {
+            $.each(markers, function (idx, item) {
+                google.maps.event.addListener(item, 'click', function() {
+                    infoWindows[idx].open(map, item);
+                });
             });
+
+            var markerCluster = new MarkerClusterer(map, markers);
         });
     });
 </script>