[OpenLayers-Users] Best way to read/parse kml

Vidal, Antoni antoni.vidal at icc.cat
Fri Jul 17 03:21:40 EDT 2009


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.

Thanks a lot.

Antoni Vidal
Unitat d'Aplicacions SIG-WEB
Ext. 3228

-----Missatge original-----
De: bartvde at osgis.nl [mailto:bartvde at osgis.nl] 
Enviat: viernes, 17 de julio de 2009 9:12
Per a: Vidal, Antoni
A/c: users at openlayers.org
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
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: les+gorgues+del+foix.kml
Type: application/octet-stream
Size: 8708 bytes
Desc: les+gorgues+del+foix.kml
Url : http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090717/ef10f8b8/lesgorguesdelfoix.obj


More information about the Users mailing list