[Spanish] Parsear XML con OpenLayers

jorgelopez jorgelopez.physics at gmail.com
Tue Jun 4 01:42:42 PDT 2013


Hi all:

Estoy haciendo una aplicación web con OpenLayers que parsea datos puntuales
provenientes de un servicio web, los he añadido inicialmente a un formato
XML crudo para parsearlo y estoy teniendo problemas con cómo acceder a los
nodos del documento XML. Dado que el carácter geográfico está en el
atributos LON/LAT, tomo los valores y creo las features con la geometría
puntual y los añado a una capa vectorial.

La verdad es que me da un error en Firebug ("non-standard document.all
property. Use the W3C standard document.getElementById ()"), que entiendo es
un asunto del DOM element pero que no sé cómo solventarlo. 

Nos dejo el código por si alguno de vosotros tenéis alguna idea:

/**
* A specific format for parsing API XML responses (no callback possible)
*/
var marineTr = OpenLayers.Class(OpenLayers.Format.XML, {
					read: function(data) {
					
						var root = data.documentElement 
						var children = root.childNodes;
								
						if(typeof data == 'string') {
						data = OpenLayers.Format.XML.prototype.read.apply(this,[data]);
						}
							
					      // access to elements in the root node (row tag)
					      var elems = data.getElementsByTagName("row");
						     		var features = [];
								for(var i=0,l=elems.length; i<l; i++) {
									var node = elems[i];
							// attributes for XML node: LON, LAT, TIMESTAMP and so on
									var x = node.attributes.LON.nodeValue;
									var y = node.attributes.LAT.nodeValue;
        								var lonlat = new OpenLayers.LonLat(x,y);
	         							var geometr = new OpenLayers.Geometry.Point(x,y);
								var feats = new OpenLayers.Feature.Vector(geometr);
															
										features.push(feats);

									}
									
									return features;
									
									
					}
            });

Esta clase devuelve las features y uso protocolo HTTP para que apunte como
url al fichero xml y use el formato específicado por esa clase. 

function init() {
		
                map = new OpenLayers.Map('map');

                var base = new OpenLayers.Layer.OSM();


vesselsL = new OpenLayers.Layer.Vector("Vessels_from_service", {
          
                    protocol: new OpenLayers.Protocol.HTTP({
		                     url: "data/vessels.xml",                                  
    				format: new marineTr()
                    })
                });

Y el error que me da parece un asunto de navegadores pero no sé si algún
parámetro de la clase OL.Format.XML resuelve esto. 

Tenéis alguna idea?

Muchas gracias de antemano

Jorge



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Parsear-XML-con-OpenLayers-tp5057675.html
Sent from the OSGeo Spanish Local Chapter mailing list archive at Nabble.com.


More information about the Spanish mailing list