/// <summary> Constructor for a new instance of the Metadata_Browse_AggregationViewer class </summary> /// <param name="Current_Mode"> Mode / navigation information for the current request</param> /// <param name="Current_Aggregation"> Current item aggregation object to display </param> /// <param name="Tracer">Trace object keeps a list of each method executed and important milestones in rendering</param> public Map_Browse_AggregationViewer(SobekCM_Navigation_Object Current_Mode, Item_Aggregation Current_Aggregation, Custom_Tracer Tracer) : base(Current_Aggregation, Current_Mode) { // Get the coordinate information DataTable coordinates = SobekCM_Database.Get_All_Coordinate_Points_By_Aggregation(Current_Aggregation.Code, Tracer); // Add the google script information StringBuilder scriptBuilder = new StringBuilder(10000); scriptBuilder.AppendLine("<script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=false\"></script>"); scriptBuilder.AppendLine("<script type=\"text/javascript\" src=\"" + Current_Mode.Base_URL + "default/scripts/keydragzoom_packed.js\"></script>"); scriptBuilder.AppendLine("<script type=\"text/javascript\">"); scriptBuilder.AppendLine(" //<![CDATA["); scriptBuilder.AppendLine(" // Global values"); scriptBuilder.AppendLine(" var map, bounds, custom_icon, info_window, last_center;"); scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Initialize the map on load "); scriptBuilder.AppendLine(" function load() { "); string center_latitude = "27.75"; string center_longitude = "-84"; if ((coordinates != null) && (coordinates.Rows.Count == 1)) { center_latitude = coordinates.Rows[0]["Point_Latitude"].ToString(); center_longitude = coordinates.Rows[0]["Point_Longitude"].ToString(); } scriptBuilder.AppendLine(" // Create the map and set some values"); scriptBuilder.AppendLine(" var latlng = new google.maps.LatLng(" + center_latitude + ", " + center_longitude + ");"); scriptBuilder.AppendLine(" var myOptions = { zoom: 7, center: latlng, mapTypeId: google.maps.MapTypeId.TERRAIN, streetViewControl: false };"); scriptBuilder.AppendLine(" map = new google.maps.Map(document.getElementById('sbkMbav_MapDiv'), myOptions);"); scriptBuilder.AppendLine(" map.enableKeyDragZoom();"); if ((coordinates != null) && (coordinates.Rows.Count > 0)) { scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Create the custom icon / marker image"); scriptBuilder.AppendLine(" var iconSize = new google.maps.Size(11, 11);"); scriptBuilder.AppendLine(" var iconAnchor = new google.maps.Point(5, 5);"); scriptBuilder.AppendLine(" var pointer_image = '" + currentMode.Base_URL + "/default/images/map_point.png';"); scriptBuilder.AppendLine(" custom_icon = new google.maps.MarkerImage(pointer_image, iconSize, null, iconAnchor);"); scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Create the bounds"); scriptBuilder.AppendLine(" bounds = new google.maps.LatLngBounds();"); scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Create the info window for display"); scriptBuilder.AppendLine(" info_window = new google.maps.InfoWindow();"); scriptBuilder.AppendLine(" google.maps.event.addListener(info_window, 'closeclick', function() { if (last_center != null) { map.panTo(last_center); last_center = null; } });"); scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Add all the points"); string last_latitude = coordinates.Rows[0]["Point_Latitude"].ToString(); string last_longitude = coordinates.Rows[0]["Point_Longitude"].ToString(); List <DataRow> bibids_in_this_point = new List <DataRow>(); foreach (DataRow thisRow in coordinates.Rows) { string latitude = thisRow["Point_Latitude"].ToString(); string longitude = thisRow["Point_Longitude"].ToString(); // Is this upcoming point new? if ((latitude != last_latitude) || (longitude != last_longitude)) { // Write the last point, if there was one if (bibids_in_this_point.Count > 0) { // Add the point add_single_point(last_latitude, last_longitude, Current_Mode, bibids_in_this_point, scriptBuilder); // Assign this as the last value last_latitude = latitude; last_longitude = longitude; // Clear the list of newspapers linked to this point bibids_in_this_point.Clear(); } // Start a new list and include this bib id bibids_in_this_point.Add(thisRow); } else { // Add this bibid to the list bibids_in_this_point.Add(thisRow); } } // Write the last point, if there was one if (bibids_in_this_point.Count > 0) { // Add the point add_single_point(last_latitude, last_longitude, Current_Mode, bibids_in_this_point, scriptBuilder); // Clear the list of newspapers linked to this point bibids_in_this_point.Clear(); } } scriptBuilder.AppendLine(" }"); scriptBuilder.AppendLine(); scriptBuilder.AppendLine(" // Add a single point "); scriptBuilder.AppendLine(" function add_point(latitude, longitude, window_content) {"); scriptBuilder.AppendLine(" var point = new google.maps.LatLng(latitude, longitude);"); scriptBuilder.AppendLine(" bounds.extend(point);"); scriptBuilder.AppendLine(" var marker = new google.maps.Marker({ position: point, draggable: false, map: map, icon: custom_icon });"); scriptBuilder.AppendLine(" google.maps.event.addListener(marker, 'click', function() { info_window.setContent(window_content); last_center = map.getCenter(); info_window.open(map, marker); });"); scriptBuilder.AppendLine(" }"); scriptBuilder.AppendLine(" //]]>"); scriptBuilder.AppendLine("</script>"); scriptIncludeName = scriptBuilder.ToString(); }