Chris, Your suggestions have been a total success.
Thank's a lot. Antoni Vidal Unitat d'Aplicacions SIG-WEB Institut Cartogràfic de Catalunya Parc de Montjuïc, E-08038 Barcelona Tel. (+34) 93 567 15 00 (ext. 3228) www.icc.cat -----Missatge original----- De: Christopher Schmidt [mailto:[email protected]] Enviat: viernes, 17 de julio de 2009 15:45 Per a: Vidal, Antoni A/c: [email protected]; [email protected] Tema: Re: [OpenLayers-Users] Best way to read/parse kml On Fri, Jul 17, 2009 at 09:21:40AM +0200, Vidal, Antoni wrote: > Hi, > > Added a sample kml. > > To understand the error I post my code: > > features = g.read(req.responseText); > > var points = new Array(); > for(var i=0; i<features.length; ++i) { > ls = features[i].geometry; > > var ifls = ls.toString(); > > if(ifls.startsWith('LINESTRING')){ > for(m=0;m<ls.components.length;m++){ > OpenLayers.Projection.transform(ls.components[m], src, dest); > points.push(new OpenLayers.Geometry.Point(ls.components[m].x, > ls.components[m].y)); > } > }else if(ifls.startsWith('POINT')){ > OpenLayers.Projection.transform(ls, src, dest); > > /********** Pop up **********/ > popup = new OpenLayers.Popup.FramedCloud("chicken", > new OpenLayers.LonLat(ls.x,ls.y), > null, > "<div style='font-size:.8em'>"+html+"</div>", > null, true, null); > map.addPopup(popup); > // ********* End Popup******/ > > } > > And the error got using firebug: ifls is null > > It fails the line features[i].geometry because g.read returns a > OL.Features.Vector, and I supose that don't parse MultiGeometry, but I need > to get every point of the geometries to transform to another srs. It does parse MultiGeometry. The problem is that ultiGeometries don't have a toString(), becuase there is no valid WKT representation of them. However, your code is far more complex than it should be. 1. Geometries can be transformed, you don't have to transform individual points. ls.transform(fromProj, toProj); Will transform the geometry in place. 2. Don't check the WKT to figure out type. Instead, check the CLASS_NAME: if (ls.CLASS_NAME=="OpenLayers.Geometry.LineString") { // etc. } -- Chris > Thanks a lot. > > Antoni Vidal > Unitat d'Aplicacions SIG-WEB > Ext. 3228 > > -----Missatge original----- > De: [email protected] [mailto:[email protected]] > Enviat: viernes, 17 de julio de 2009 9:12 > Per a: Vidal, Antoni > A/c: [email protected] > Tema: Re: [OpenLayers-Users] Best way to read/parse kml > > Hi, > > can you post a sample KML file which fails? > > What is the exact error that you are getting? > > Best regards, > Bart > > > Hello, > > > > > > > > I'm trying to read kml file from user client side. I use: > > > > g = new OpenLayers.Format.KML(); > > > > features = g.read(req.responseText); > > > > ... > > > > > > > > To get the collection of features, and all is ok if the kml NOT contains a > > <MultiGeometry> tag. If so, I get an error. > > > > > > > > How can I solve this? > > > > > > > > Thank's in advance > > > > > > > > Antoni Vidal > > > > Unitat d'Aplicacions SIG-WEB > > Institut Cartogràfic de Catalunya > > <http://mercuri.icc.cat/website/mob_nf/mob1/mob2/inici2.htm?CONSULTA=Institut%20Cartogr%25E0fic%20de%20Catalunya&XYADDRESS=429486:4580392> > > Parc de Montjuïc, E-08038 Barcelona > > Tel. (+34) 93 567 15 00 (ext. 3228) > > www.icc.cat <http://www.icc.cat/> > > > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > [email protected] > > http://openlayers.org/mailman/listinfo/users > > > > _______________________________________________ > Users mailing list > [email protected] > http://openlayers.org/mailman/listinfo/users _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
