Foros del Web » Programando para Internet » Javascript »

Problema con Bucle Javascript y funcion Escucha evento de Google Earth

Estas en el tema de Problema con Bucle Javascript y funcion Escucha evento de Google Earth en el foro de Javascript en Foros del Web. Hola a todos , soy nuevo en el foro y me gustaría saber si alguien me puede ayudar o entregar alguna recomendación para esto. Esta ...
  #1 (permalink)  
Antiguo 18/10/2011, 12:17
 
Fecha de Ingreso: octubre-2011
Ubicación: Santiago, Chile
Mensajes: 1
Antigüedad: 12 años, 6 meses
Puntos: 0
Exclamación Problema con Bucle Javascript y funcion Escucha evento de Google Earth

Hola a todos , soy nuevo en el foro y me gustaría saber si alguien me puede ayudar o entregar alguna recomendación para esto.

Esta funcion (ver codigo al final del post) recibe como parametro un Json con datos de georeferencia...(latitud, logitud etc...), con los cuales inserto marcas en el mapa de Google earth(API) con el bucle for que esta dentro.

Mi problema es el siguiente.
al establecer el nombre de la variable a instanciarce como "Placemark".

Código Javascript:
Ver original
  1. var marca = ge.createPlacemark('');
luego en la funcion
Código Javascript:
Ver original
  1. google.earth.addEventListener(marca, 'click', function(event){})
la cual escucha el evento click a la marca y genera contenido al globo...me genera el mismo contenido para todas las marcas(de la primera)...

Asumo que es asi por el hecho de que el parametro "marca" es el mismo para todas...
mi pregunta es la siguiente ¿Como Puedo diferenciarla en el bucle?...para que sea algo como marca1 , marca2 etc...

Codigo completo a continuacion:
Código Javascript:
Ver original
  1. function addPlacemark(datos_json){
  2.          // Volar a Comuna
  3. volarComuna("Providencia, Santiago, Chile");
  4. BorrarContenido();
  5. var size = datos_json.length;
  6. for (i = 0; i < size; i++){
  7.  
  8.         var latitud = parseFloat(datos_json[i].lat);
  9.         var longitud = parseFloat(datos_json[i].lon);
  10.         var altitud = parseFloat(datos_json[i].alt);
  11.         var nombre = datos_json[i].nombre;
  12.         var kmz = datos_json[i].dir_kmz;
  13.         var kml = datos_json[i].dir_kml;
  14.         var info = datos_json[i].info;
  15.        
  16.        
  17.         var marca = ge.createPlacemark('');
  18.          marca.setName(nombre);
  19.          var point = ge.createPoint('');
  20.          point.setLatitude(latitud);
  21.          point.setLongitude(longitud);
  22.          point.setAltitude(altitud);
  23.          point.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
  24.          marca.setGeometry(point);
  25.         //////////////////////////////////////////////
  26.        
  27.          var styleMap = ge.createStyleMap('');
  28.          // Create normal style for style map.
  29.          var normalStyle = ge.createStyle('');
  30.          var normalIcon = ge.createIcon('');
  31.          normalIcon.setHref('http://upgrade3d.cl/globos/icono_proyecto.png');
  32.          normalStyle.getIconStyle().setIcon(normalIcon);
  33.          normalStyle.getLabelStyle().setScale(0.1);
  34.          normalStyle.getIconStyle().setScale(0.7);
  35.          // Create highlight style for style map.
  36.          var highlightStyle = ge.createStyle('');
  37.          var highlightIcon = ge.createIcon('');
  38.          highlightIcon.setHref('http://upgrade3d.cl/globos/icono_proyecto2.png');
  39.          highlightStyle.getIconStyle().setIcon(highlightIcon);
  40.          highlightStyle.getIconStyle().setScale(0.7);
  41.          styleMap.setNormalStyle(normalStyle);
  42.          styleMap.setHighlightStyle(highlightStyle);
  43.          
  44.          ////////////////////////////////////////////////
  45.          
  46.          marca.setStyleSelector(styleMap);
  47.          ge.getFeatures().appendChild(marca);
  48.          
  49.          
  50.          google.earth.addEventListener(marca, 'click', function(event){
  51.       // prevent the default balloon from popping up
  52.       event.preventDefault();
  53.       var balloon = ge.createHtmlStringBalloon('');
  54.       balloon.setFeature(event.getTarget());
  55.       balloon.setMaxWidth(340);
  56.      
  57.       // Google logo.
  58.       balloon.setContentString(
  59.           '<div  style="font-family: Verdana;width: 330px;"><div  style="float:left; margin-top:15px;"><div id="tit" style="font-size:30px; text-align:center;">'+nombre+'</div><div  style="font-size:14px; text-align:center;">'+info+'</div><div  style="font-size:13px; font-weight:bold; text-align:center;"></div></div></br><a href="javascript:;" onclick="adProject('+latitud+','+longitud+');" style="float:left; text-decoration:none; margin-top: 5px;"><div  style="margin-left: 90px; width:150px; height:50px; text-align:center; background: #09F; color:#FFF; font-weight:bold;">Ir al Proyecto</div></a></div>');
  60.      
  61.       ge.setBalloon(balloon);
  62.         } );
  63.         ///////////añadir kmz Modelo 3d/////////////////
  64.         cargaKM(kmz);
  65.         ////////////////////////////
  66.  
  67.        
  68.         }
  69.    
  70.    
  71.     }

Etiquetas: api, earth, funciones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:09.