Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="initial-scale=.5, user-scalable=no">
- <meta charset="utf-8">
- <title>LocalizacaoServicosLabmetro</title>
- <link href="https://developers.google.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
- <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
- <script src="jshash-2.2/md5.js"></script>
- <script>
- var map;
- var locations = [
- [16,'Viana do Castelo', 41.6872711837914, -8.82476806640625, 0],
- [3,'Braga', 41.54944320851238, -8.414154052734375, 0],
- [13,'Porto', 41.15875373498798, -8.610706329345703, 0],
- [1,'Aveiro', 40.63896734381723, -8.648300170898438, 0],
- [17,'Vila Real', 41.30050773444147, -7.752227783203125, 0],
- [4,'Bragança', 41.80535774441799, -6.760368347167969, 0],
- [18,'Viseu', 40.64730356252251, -7.8936767578125, 0],
- [9,'Guarda', 40.53258931069557, -7.25921630859375, 0],
- [6,'Coimbra', 40.20195268954057, -8.433380126953125, 0],
- [10,'Leiria', 39.7462660621837, -8.81103515625, 0],
- [14,'Santarem', 39.774769485295465, -8.5693359375, 0],
- [5,'Castelo Branco', 39.82013946676259, -7.505035400390625, 0],
- [12,'Portalegre', 39.28860847419942, -7.42950439453125, 0],
- [11,'Lisboa', 38.72891158257716, -9.139251708984375, 0],
- [7,'Évora', 38.56749535882734, -7.9046630859375, 0],
- [15,'Setúbal', 38.5299046000139, -8.876953125, 0],
- [2,'Beja', 38.01509916686995, -7.862606048583984, 0],
- [8,'Faro', 37.017905231730914, -7.922515869140625, 0],
- [98,'Madrid', 40.429178,-3.705139, 25000],
- [99,'Barcelona', 41.392006,2.174263, 13000],
- [100,'Elgoibar', 43.216092,-2.412744, 8000]
- ];
- // Create an object containing LatLng, population.
- var citymap = {};
- var cityCircle;
- var cityPoint;
- function Replace() {
- var i, j;
- for (i = 0; i < parsed.length; i += 1) {
- for (j = 0; j < locations.length; j += 1) {
- if (parsed[i][0] == locations[j][0]) {
- locations[j][4] = (2000 * parsed[i][3]+3000);
- }
- }
- }
- }
- // CSV to Array function. Returns Parsed array.
- function CSVToArray(strData, strDelimiter) {
- strDelimiter = (strDelimiter || ",");
- var objPattern = new RegExp(
- ("(\\" + strDelimiter + "|\\r?\\n|\\r|^)"
- + "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|"
- + "([^\"\\" + strDelimiter + "\\r\\n]*))"
- ),
- "gi"
- );
- var arrData = [[]];
- var arrMatches = null;
- while (arrMatches = objPattern.exec(strData)) {
- var strMatchedDelimiter = arrMatches[1];
- if (strMatchedDelimiter.length && (strMatchedDelimiter !== strDelimiter)) {
- arrData.push([]);
- }
- if (arrMatches[2]) {
- var strMatchedValue = arrMatches[2].replace(
- new RegExp("\"\"",
- "g"),
- "\""
- );
- } else {
- var strMatchedValue = arrMatches[3];
- }
- arrData[arrData.length - 1].push(strMatchedValue);
- }
- return arrData;
- }
- //Start-up function
- function initialize() {
- var mapOptions = {
- zoom: 7,
- center: new google.maps.LatLng(39.5, -3.2),
- disableDefaultUI: true,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- };
- var map = new google.maps.Map(document.getElementById('map-canvas'),
- mapOptions);
- /*if(citymap[city].population > 2500){
- var markerOptions = {
- position: citymap[city].center,
- map: map
- };
- cityPoint = new google.maps.Marker(markerOptions);
- }*/
- function Marker(city) {
- var populationOptions = {
- strokeColor: '#FF0000',
- strokeOpacity: 0.8,
- strokeWeight: 2,
- fillColor: '#FF0000',
- fillOpacity: 0.35,
- map: map,
- center: citymap[city].center,
- radius: citymap[city].population
- };
- cityCircle = new google.maps.Circle(populationOptions);
- }
- var i;
- for (var city in citymap) {
- var t = setTimeout(function(){Marker(city);},i*2000);
- i++;
- }
- }
- // initializing connection:
- if (window.XMLHttpRequest) {
- txtFile = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- txtFile = new ActiveXObject("Microsoft.XMLHTTP");
- // no ie8 entra aqui!
- }
- var allText;
- txtFile.open("GET", "http://foo/f4/stats/nServsCodigoPostal.csv", false);
- txtFile.onreadystatechange = function() {
- if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
- if (txtFile.status === 200) { // Makes sure it's found the file.
- allText = txtFile.responseText;
- }
- }
- };
- txtFile.send(null);
- var parsed = CSVToArray(allText, ";");
- /* coloca a magnitude na variavel locations */
- Replace();
- for (i = 0; i < locations.length; i++) {
- distrito = locations[i][1];
- latitude = locations[i][2];
- longitude = locations[i][3];
- magnitude = locations[i][4];
- citymap[distrito] = {
- center: new google.maps.LatLng(latitude, longitude),
- population: magnitude
- };
- }
- google.maps.event.addDomListener(window, 'load', initialize);
- </script>
- </head>
- <body>
- <div id="map-canvas" style="height:1050px; width:1200px;"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement