function createMap(centerLat,centerLng){ map = new GMaps({ el: '#map', lat: centerLat, lng: centerLng, click: addNewMarker }); map.addMarker({ lat: centerLat, lng: centerLng}); addedMarkers = 1; lat = centerLat; lng = centerLng; }; function addNewMarker(e){ var newLat = e.latLng.lat(); var newLng = e.latLng.lng(); drawDestination(newLat,newLng); }; function drawDestination(destinationLat, destinationLng){ map.drawRoute({ origin: [lat, lng], destination: [destinationLat, destinationLng], travelMode: 'driving', strokeColor: '#000000', strokeOpacity: 0.6, strokeWeight: 5 }); lat = destinationLat; lng = destinationLng; map.addMarker({ lat: lat, lng: lng}); addedMarkers++; }; $("#compactar").on("click",function(e){ //Compactar if((lat != firstLat)&&(addedMarkers > 2)){ var lastLat = lat; var lastLng = lng; //1. Reiniciar mapa createMap(firstLat,firstLng); //2. Añadir ruta a destino final drawDestination(lastLat,lastLng); } }); function updateWatch(){ var date = new Date(); $("#hour").html(date.getHours() + ":"); $("#minute").html(date.getMinutes()); $("#second").html(date.getSeconds()); }; setInterval(function(){ //Timer del reloj updateWatch(); },1000); geolocate(); });

Práctica 3 - CORE