chrislkeller

Script for Wis. Senate Recall Map

Jul 11th, 2011
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //global variables
  2.     var tableid = 1101908;
  3.     var tableid2 = 1101642;
  4.     var latlng = new google.maps.LatLng(43.802819,-90.834961);
  5.     var zoom = 7;
  6.     var map;
  7.     var layer;
  8.     var layer2;
  9.     var infowindow;
  10.     var infoWindowContent = '';
  11.     var geocoder = new google.maps.Geocoder();
  12.     var coordinate;
  13.  
  14. function initialize() {
  15.  
  16.     // Initialize the map
  17.     map = new google.maps.Map(document.getElementById('map_canvas'), {
  18.         center: latlng,
  19.         zoom: zoom,
  20.         scrollwheel: false,    
  21.         disableDragging: true,
  22.         mapTypeControl: false,
  23.         navigationControl: true,
  24.         streetViewControl: false,
  25.         scaleControl: false,
  26.         mapTypeId: google.maps.MapTypeId.ROADMAP,
  27.         navigationControlOptions: {
  28.             style: google.maps.NavigationControlStyle.LARGE,
  29.             position: google.maps.ControlPosition.RIGHT_TOP}
  30.     });
  31.  
  32.  
  33.   //style the map
  34.     var style = [
  35.     {
  36.       featureType: 'all',
  37.       elementType: 'all',
  38.       stylers: [
  39.         { saturation: -50 }
  40.       ]
  41.     } ,
  42.     {
  43.       featureType: 'road.arterial',
  44.       elementType: 'all',
  45.       stylers: [
  46.         { visibility: 'off' }
  47.       ]
  48.     } ,
  49.     {
  50.       featureType: 'road.local',
  51.       elementType: 'all',
  52.       stylers: [
  53.         { visibility: 'off' }
  54.       ]
  55.     } ,
  56.     {
  57.       featureType: 'administrative.province',
  58.       elementType: 'all',
  59.       stylers: [
  60.         { visibility: 'on' }
  61.       ]
  62.     } ,
  63.     {
  64.       featureType: 'administrative.locality',
  65.       elementType: 'all',
  66.       stylers: [
  67.         { visibility: 'on' }
  68.       ]
  69.     } ,
  70.     {
  71.       featureType: 'administrative.neighborhood',
  72.       elementType: 'all',
  73.       stylers: [
  74.         { visibility: 'off' }
  75.       ]
  76.     } ,
  77.     {
  78.       featureType: 'administrative.land_parcel',
  79.       elementType: 'all',
  80.       stylers: [
  81.         { visibility: 'off' }
  82.       ]
  83.     } ,
  84.     {
  85.       featureType: 'poi',
  86.       elementType: 'all',
  87.       stylers: [
  88.         { visibility: 'off' }
  89.       ]
  90.     } ,
  91.     {
  92.       featureType: 'transit',
  93.       elementType: 'all',
  94.       stylers: [
  95.         { visibility: 'off' }
  96.       ]
  97.     }
  98.   ];
  99.  
  100.     var styledMapType = new google.maps.StyledMapType(style, {
  101.         map: map,
  102.         name: 'Styled Map'
  103.     });
  104.  
  105.     map.mapTypes.set('map-style', styledMapType);
  106.     map.setMapTypeId('map-style');
  107.  
  108.     //hansen only fusion layer & supress fusion info window
  109.     layerHansen = new google.maps.FusionTablesLayer(tableid2, {suppressInfoWindows: true});
  110.     layerHansen.setQuery("SELECT geometry FROM " + tableid2);
  111.     layerHansen.setMap(map);
  112.  
  113.     //intial fusion layer & supress fusion info window
  114.     layer = new google.maps.FusionTablesLayer(tableid, {suppressInfoWindows: true});
  115.     layer.setQuery("SELECT geometry FROM " + tableid);
  116.     layer.setMap(map);
  117.  
  118. //click listener on initial fusion layer
  119.     google.maps.event.addListener(layer, 'click', function(e) {
  120.     map.setZoom(7);
  121.     if(infowindow) infowindow.close();
  122.     else infowindow = new google.maps.InfoWindow();
  123.  
  124.         //info window on initial fusion layer
  125.         infoWindowContent = infowindow.setContent(
  126.             '<h3>' + e.row['NAMELSAD10'].value + '</h3>' +
  127.             '<div id ="recall-date">' +
  128.             '<table>' +
  129.             '<tbody>' +
  130.             '<p style="font-size: 12px; line-height: 8px;"><strong>Recall Primary Election: </strong>' +
  131.             e.row['DATE_OF_RECALL_PRIMARY'].value + '</p>' +
  132.             '<p style="font-size: 12px; line-height: 8px;"><strong>Recall General Election: </strong>' +
  133.             e.row['DATE_OF_RECALL_GENERAL'].value + '</p>' +
  134.             '</tbody>' +
  135.             '</table>' +
  136.             '</div>' +
  137.  
  138.             '<div id ="recall-candidate">' +
  139.             '<table id>' +
  140.             '<tbody>' +
  141.             '<tr>' +
  142.             '<th style="width: 90px; color: #ffffff; background-color:' + e.row['LAYER_COLOR'].value + ';">Incumbent</th>' +
  143.             '<th style="width: 90px; color: #4F4D4D;">Challenger</th>' +
  144.             '<th style="width: 90px; color: #4F4D4D;">Challenger</th>' +
  145.             '</tr>' +
  146.            
  147.             '<tr>' + '<td><img src="' + e.row['INCUMBENT_PHOTO_PATH'].value +
  148.             '" width="87" height="106" alt="' + e.row['INCUMBENT_NAME'].value + '" />' +
  149.             '<td><img src="' + e.row['CHALLENGER1_PHOTO_PATH'].value +
  150.             '" width="87" height="106" alt="' + e.row['CHALLENGER1_NAME'].value + '" />' + 
  151.             '<td><img src="' + e.row['CHALLENGER2_PHOTO_PATH'].value +
  152.             '" width="87" height="106" alt="' + e.row['CHALLENGER2_NAME'].value + '" />' + '</tr>' +
  153.            
  154.             '<tr>' + '<td style="font-size: 14px;"><span class="bolder">' + e.row['INCUMBENT_NAME'].value + '</span><br>' +
  155.             e.row['INCUMBENT_PARTY'].value + '<br>' + e.row['INCUMBENT_CITY'].value + '</td>' +
  156.             '<td style="font-size: 14px;"><span class="bolder">' + e.row['CHALLENGER1_NAME'].value + '</span><br>' +
  157.             e.row['CHALLENGER1_PARTY'].value + '<br>' + e.row['CHALLENGER1_CITY'].value + '</td>' +
  158.             '<td style="font-size: 14px;"><span class="bolder">' + e.row['CHALLENGER2_NAME'].value + '</span><br>' +
  159.             e.row['CHALLENGER2_PARTY'].value + '<br> ' + e.row['CHALLENGER2_CITY'].value + '</td>' + '</tr>' +
  160.            
  161.             '<tr>' +
  162.             '<td><a href="' + e.row['INCUMBENT_CAMPAIGN_PAGE'].value + '" target="_blank">Campaign Website</a><br>' +
  163.             '<a href="' + e.row['INCUMBENT_STATE_WEB_SITE'].value + '" target="_blank">State Website</a><br>' +
  164.             '<a href="' + e.row['INCUMBENT_PROFILE_PAGE'].value + '" target="_blank">MyGov365 Profile</a></td>' +
  165.             '<td><a href="' + e.row['CHALLENGER1_SITE'].value + '" target="_blank">Campaign Website</a></td>' +
  166.             //'<td><a href="' + e.row['CHALLENGER2_SITE'].value + '" target="_blank">Campaign Website</a></td>' +
  167.             '</tr>' +
  168.             '</tbody>' +
  169.             '</table>' +
  170.             '<p style="font-size: 11px;">In 2008, ' +
  171.             e.row['INCUMBENT_NAME'].value + ' ' +
  172.             e.row['RAN_AGAINST'].value +
  173.             ' with ' + e.row['2008_VOTE_PERCENT'].value + ' of the vote.</p>' +
  174.             '</div>');
  175.  
  176.         infowindow.setPosition(e.latLng);
  177.         map.setCenter(e.latLng);
  178.         //map.setZoom(9);
  179.         infowindow.open(map);      
  180.     });
  181.    
  182.    
  183.    
  184.     //click listener on hansen fusion layer
  185.     google.maps.event.addListener(layerHansen, 'click', function(e) {
  186.     map.setZoom(7);
  187.     if(infowindow) infowindow.close();
  188.     else infowindow = new google.maps.InfoWindow();
  189.  
  190.         //info window on hansen fusion layer
  191.         infoWindowContent = infowindow.setContent(
  192.             '<h3>' + e.row['NAMELSAD10'].value + '</h3>' +
  193.             '<div id ="recall-date">' +
  194.             '<table>' +
  195.             '<tbody>' +
  196.             '<p style="font-size: 12px; line-height: 8px;"><strong>Recall General Election: </strong>' +
  197.             e.row['DATE_OF_RECALL_GENERAL'].value + '</p>' +
  198.             '</tbody>' +
  199.             '</table>' +
  200.             '</div>' +
  201.  
  202.             '<div id ="recall-candidate">' +
  203.             '<table id>' +
  204.             '<tbody>' +
  205.             '<tr>' +
  206.             '<th style="width: 160px; color: #ffffff; background-color:' + e.row['LAYER_COLOR'].value + ';">Incumbent</th>' +
  207.             '<th style="width: 160px; color: #4F4D4D;">Challenger</th>' +
  208.             '</tr>' +
  209.            
  210.             '<tr>' + '<td><img src="' + e.row['INCUMBENT_PHOTO_PATH'].value +
  211.             '" width="87" height="106" alt="' + e.row['INCUMBENT_NAME'].value + '" />' +
  212.             '<td><img src="' + e.row['CHALLENGER1_PHOTO_PATH'].value +
  213.             '" width="87" height="106" alt="' + e.row['CHALLENGER1_NAME'].value + '" />' + '</tr>' +
  214.            
  215.             '<tr>' + '<td style="font-size: 14px;"><span class="bolder">' + e.row['INCUMBENT_NAME'].value + '</span><br>' +
  216.             e.row['INCUMBENT_PARTY'].value + '<br>' + e.row['INCUMBENT_CITY'].value + '</td>' +
  217.             '<td style="font-size: 14px;"><span class="bolder">' + e.row['CHALLENGER1_NAME'].value + '</span><br>' +
  218.             e.row['CHALLENGER1_PARTY'].value + '<br>' + e.row['CHALLENGER1_CITY'].value + '</td>' + '</tr>' +
  219.            
  220.             '<tr>' +
  221.             '<td><a href="' + e.row['INCUMBENT_CAMPAIGN_PAGE'].value + '" target="_blank">Campaign Website</a><br>' +
  222.             '<a href="' + e.row['INCUMBENT_STATE_WEB_SITE'].value + '" target="_blank">State Website</a><br>' +
  223.             '<a href="' + e.row['INCUMBENT_PROFILE_PAGE'].value + '" target="_blank">MyGov365 Profile</a></td>' +
  224.             '<td><a href="' + e.row['CHALLENGER1_SITE'].value + '" target="_blank">Campaign Website</a></td>' +
  225.             '</tr>' +
  226.             '</tbody>' +
  227.             '</table>' +
  228.             '<p style="font-size: 11px;">In 2008, ' +
  229.             e.row['INCUMBENT_NAME'].value + ' ' +
  230.             e.row['RAN_AGAINST'].value +
  231.             ' with ' + e.row['2008_VOTE_PERCENT'].value + ' of the vote.</p>' +
  232.             '</div>');
  233.  
  234.         infowindow.setPosition(e.latLng);
  235.         map.setCenter(e.latLng);
  236.         //map.setZoom(9);
  237.         infowindow.open(map);      
  238.     });
  239.    
  240. }
  241.  
  242.     //write the map
  243.     window.setTimeout('initialize()', 500);
RAW Paste Data