Advertisement
m1nga

Continental

May 8th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta name="viewport" content="initial-scale=.5, user-scalable=no">
  5.         <meta charset="utf-8">
  6.         <title>LocalizacaoServicosLabmetro</title>
  7.         <link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
  8.         <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false"></script>
  9.         <script src="jshash-2.2/md5.js"></script>
  10.         <script>
  11.  
  12.             var map;
  13.             var locations = [
  14.                 [16,'Viana do Castelo', 41.6872711837914, -8.82476806640625, 0],
  15.                 [3,'Braga', 41.54944320851238, -8.414154052734375, 0],
  16.                 [13,'Porto', 41.15875373498798, -8.610706329345703, 0],
  17.                 [1,'Aveiro', 40.63896734381723, -8.648300170898438, 0],
  18.                 [17,'Vila Real', 41.30050773444147, -7.752227783203125, 0],
  19.                 [4,'Bragança', 41.80535774441799, -6.760368347167969, 0],
  20.                 [18,'Viseu', 40.64730356252251, -7.8936767578125, 0],
  21.                 [9,'Guarda', 40.53258931069557, -7.25921630859375, 0],
  22.                 [6,'Coimbra', 40.20195268954057, -8.433380126953125, 0],
  23.                 [10,'Leiria', 39.7462660621837, -8.81103515625, 0],
  24.                 [14,'Santarem', 39.774769485295465, -8.5693359375, 0],
  25.                 [5,'Castelo Branco', 39.82013946676259, -7.505035400390625, 0],
  26.                 [12,'Portalegre', 39.28860847419942, -7.42950439453125, 0],
  27.                 [11,'Lisboa', 38.72891158257716, -9.139251708984375, 0],
  28.                 [7,'Évora', 38.56749535882734, -7.9046630859375, 0],
  29.                 [15,'Setúbal', 38.5299046000139, -8.876953125, 0],
  30.                 [2,'Beja', 38.01509916686995, -7.862606048583984, 0],
  31.                 [8,'Faro', 37.017905231730914, -7.922515869140625, 0],
  32.                 [98,'Madrid', 40.429178,-3.705139, 25000],
  33.                 [99,'Barcelona', 41.392006,2.174263, 13000],
  34.                 [100,'Elgoibar', 43.216092,-2.412744, 8000]
  35.             ];
  36.  
  37.             // Create an object containing LatLng, population.
  38.             var citymap = {};
  39.             var cityCircle;
  40.             var cityPoint; 
  41.  
  42.             function Replace() {
  43.                 var i, j;                
  44.                 for (i = 0; i < parsed.length; i += 1) {
  45.                     for (j = 0; j < locations.length; j += 1) {
  46.                         if (parsed[i][0] == locations[j][0]) {
  47.                             locations[j][4] = (2000 * parsed[i][3]+3000);
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.  
  53.             // CSV to Array function. Returns Parsed array.
  54.             function CSVToArray(strData, strDelimiter) {
  55.                 strDelimiter = (strDelimiter || ",");
  56.                 var objPattern = new RegExp(
  57.                         ("(\\" + strDelimiter + "|\\r?\\n|\\r|^)"
  58.                                 + "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|"
  59.                                 + "([^\"\\" + strDelimiter + "\\r\\n]*))"
  60.                                 ),
  61.                         "gi"
  62.                         );
  63.                 var arrData = [[]];
  64.                 var arrMatches = null;
  65.                 while (arrMatches = objPattern.exec(strData)) {
  66.                     var strMatchedDelimiter = arrMatches[1];
  67.                     if (strMatchedDelimiter.length && (strMatchedDelimiter !== strDelimiter)) {
  68.                         arrData.push([]);
  69.                     }
  70.                     if (arrMatches[2]) {
  71.                         var strMatchedValue = arrMatches[2].replace(
  72.                                 new RegExp("\"\"",
  73.                                 "g"),
  74.                                 "\""
  75.                                 );
  76.                     } else {
  77.                         var strMatchedValue = arrMatches[3];
  78.                     }
  79.                     arrData[arrData.length - 1].push(strMatchedValue);
  80.                 }
  81.                 return arrData;
  82.             }
  83.            
  84.             //Start-up function
  85.             function initialize() {
  86.                 var mapOptions = {
  87.                     zoom: 7,
  88.                     center: new google.maps.LatLng(39.5, -3.2),
  89.                     disableDefaultUI: true,
  90.                     mapTypeId: google.maps.MapTypeId.ROADMAP   
  91.                 };
  92.  
  93.                 var map = new google.maps.Map(document.getElementById('map-canvas'),
  94.                         mapOptions);
  95.                
  96.                     /*if(citymap[city].population > 2500){
  97.                         var markerOptions = {
  98.                             position: citymap[city].center,
  99.                             map: map
  100.                         };
  101.                         cityPoint = new google.maps.Marker(markerOptions);
  102.                     }*/
  103.                
  104.                 function Marker(city) {
  105.                     var populationOptions = {
  106.                         strokeColor: '#FF0000',
  107.                         strokeOpacity: 0.8,
  108.                         strokeWeight: 2,
  109.                         fillColor: '#FF0000',
  110.                         fillOpacity: 0.35,
  111.                         map: map,
  112.                         center: citymap[city].center,
  113.                         radius: citymap[city].population
  114.                     };
  115.                     cityCircle = new google.maps.Circle(populationOptions);
  116.                 }
  117.                 var i;
  118.                 for (var city in citymap) {
  119.                     var t = setTimeout(function(){Marker(city);},i*2000);
  120.                     i++;
  121.                 }
  122.             }  
  123.  
  124.  
  125.             // initializing connection:
  126.             if (window.XMLHttpRequest) {
  127.                 txtFile = new XMLHttpRequest();
  128.             } else if (window.ActiveXObject) {
  129.                 txtFile = new ActiveXObject("Microsoft.XMLHTTP");
  130.                 // no ie8 entra aqui!
  131.             }
  132.  
  133.             var allText;
  134.  
  135.             txtFile.open("GET", "http://foo/f4/stats/nServsCodigoPostal.csv", false);
  136.  
  137.             txtFile.onreadystatechange = function() {
  138.                 if (txtFile.readyState === 4) {  // Makes sure the document is ready to parse.
  139.                     if (txtFile.status === 200) {  // Makes sure it's found the file.
  140.                         allText = txtFile.responseText;
  141.                     }
  142.                 }
  143.             };
  144.             txtFile.send(null);
  145.  
  146.             var parsed = CSVToArray(allText, ";");
  147.  
  148.             /* coloca a magnitude na variavel locations */
  149.             Replace();
  150.  
  151.             for (i = 0; i < locations.length; i++) {
  152.                 distrito = locations[i][1];
  153.                 latitude = locations[i][2];
  154.                 longitude = locations[i][3];
  155.                 magnitude = locations[i][4];
  156.  
  157.                 citymap[distrito] = {
  158.                     center: new google.maps.LatLng(latitude, longitude),
  159.                     population: magnitude
  160.                 };
  161.             }
  162.            
  163.             google.maps.event.addDomListener(window, 'load', initialize);
  164.            
  165.         </script>
  166.     </head>
  167.     <body>
  168.         <div id="map-canvas" style="height:1050px; width:1200px;"></div>
  169.     </body>
  170. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement