Advertisement
Yanazaki

mapa.js

Sep 2nd, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var map;
  2. var idInfoBoxAberto;
  3. var infoBox = [];
  4. var markers = [];
  5.  
  6. function initialize() {
  7.     var latlng = new google.maps.LatLng(-18.8800397, -47.05878999999999);
  8.    
  9.     var options = {
  10.         zoom: 10,
  11.         center: latlng,
  12.         mapTypeId: google.maps.MapTypeId.ROADMAP
  13.     };
  14.  
  15.     map = new google.maps.Map(document.getElementById("mapa"), options);
  16. }
  17.  
  18. initialize();
  19.  
  20. function abrirInfoBox(id, marker) {
  21.     if (typeof(idInfoBoxAberto) == 'number' && typeof(infoBox[idInfoBoxAberto]) == 'object') {
  22.         infoBox[idInfoBoxAberto].close();
  23.     }
  24.  
  25.     infoBox[id].open(map, marker);
  26.     idInfoBoxAberto = id;
  27. }
  28.  
  29. function carregarPontos() {
  30.    
  31.     $.getJSON('js/pontos.json', function(pontos) {
  32.        
  33.         var latlngbounds = new google.maps.LatLngBounds();
  34.        
  35.         $.each(pontos, function(index, ponto) {
  36.            
  37.             var marker = new google.maps.Marker({
  38.                 position: new google.maps.LatLng(ponto.Latitude, ponto.Longitude),
  39.                 title: "Meu ponto personalizado! :-D",
  40.                 icon: 'img/marcador.png'
  41.             });
  42.            
  43.             var myOptions = {
  44.                 content: "<p>" + ponto.Descricao + "</p>",
  45.                 pixelOffset: new google.maps.Size(-150, 0)
  46.             };
  47.  
  48.             infoBox[ponto.Id] = new InfoBox(myOptions);
  49.             infoBox[ponto.Id].marker = marker;
  50.            
  51.             infoBox[ponto.Id].listener = google.maps.event.addListener(marker, 'click', function (e) {
  52.                 abrirInfoBox(ponto.Id, marker);
  53.             });
  54.            
  55.             markers.push(marker);
  56.            
  57.             latlngbounds.extend(marker.position);
  58.            
  59.         });
  60.        
  61.         var markerCluster = new MarkerClusterer(map, markers);
  62.        
  63.         map.fitBounds(latlngbounds);
  64.        
  65.     });
  66.    
  67. }
  68.  
  69. carregarPontos();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement