Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/05/2011, 15:28
Nacho0505
 
Fecha de Ingreso: abril-2011
Mensajes: 5
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Llamar a subfuncion desde fuera de la funcion principal

Estoy haciendo un programa para seguir a mi auto en google maps a traves de un gps.
la funcion iniatialize se carga con <body onload =initialize()>. Es la que carga el mapa. La funcion punto se encarga de leer un archivo txt con las coordenadas y va mostrando en el mapa el punto. Por lo tanto hice un setInterval para iterar la lectura de este archivo (que se va actualizando a todo esto).
Solamente quiero iterar la funcion punto que es la que va mostrando el punto, si itero la funcion initialize se ve muy feo ya que se carga tambien todo el mapa de nuevo. Y despues llamo a la funcion punto con un boton. Espero haberme explicado bien... aqui dejo esta parte del codigo.
PD. me funciona todo bien en el caso de iterar la funcion initialize, pero como mencione solo quiero ir actualizando la ubicacion del auto una vez el mapa cargado.


var intervalID;

function initialize() {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(-33.408319444444400,-70.573786111111100),15);
map.addControl(new GLargeMapControl());
map.addControl(new GOverviewMapControl());

function punto() {


// A function to create the marker and set up the event window

function createMarker(point,name,html) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}

// === Define the function thats going to process the text file ===
process_it = function(doc) {
// === split the document into lines ===
lines = doc.split("\n");
for (var i=0; i<lines.length; i++) {
if (lines[i].length > 1) {
// === split each line into parts separated by "|" and use the contents ===
parts = lines[i].split("|");
var lat = parseFloat(parts[0]);
var lng = parseFloat(parts[1]);
var html = parts[2];
var label = parts[3];
var point = new GLatLng(lat,lng);
// create the marker
var marker = createMarker(point,label,html);
map.addOverlay(marker);
map.panTo(new GLatLng(lat, lng));
}
}

}


GDownloadUrl("example.txt", process_it);
}
}


function iterar(){
intervalID=setInterval("punto()",3000);
}
function detenerpunto(){
clearInterval(intervalID);
}

......
<body onload="initialize()" onunload="GUnload()">

.....

<td width="101"><input type="button" onclick="iterar()" value="Posicion Actual" /></td>
<td width="136"><input type="button" onclick="detenerpunto()" value="Detener Seguimiento" /></td>