[OpenLayers-Users] Displaying gml data

Christopher Schmidt crschmidt at metacarta.com
Mon Nov 17 18:54:13 EST 2008


On Mon, Nov 17, 2008 at 11:40:45PM +0000, Dave Potts wrote:
> Christopher Schmidt wrote:
> Hi
> 
> I have look at the kml sun dail example, nice bit of  example code.
> 
> My input format is xml file, I had assumed that by saying something like
> 
> var layer3= new 
> OpenLayers.Layer.GML("foo","http://localhost:8080/foobar/fooServlet",
>                            {format: OpenLayers.Format.XML,
>                               projection:map.displayProjection,
>                               formatOptions:{
>                                  extraStyles: true,
>                                  extraAttributes:true}
>                      });
> It would invoke the servlet fooServlet and build an xml tree in the 
> client browser

Layear.GML only works with geographic feature parsers. Format.XML is not
a geographic feature parser. Format.GML is, Format.KML is.

> This should kick of my fooServlet, but it does'nt seem to be invoked, 
> even if I do manage to get it invoked, 

Does the URL you are opening start with "http://localhost:8080/" ? If
not, you're running into same origin policy violations. Is your layer
added to the map? Did you call setCenter or zoomToMaxExtnet?

> how would I actual access the xml tree?

You wouldn't. You can access attributes of the data, if it is (for
example) GML and the GML contains properties, via
layer.features[0].attributes['key']. 

> 
> The sundials program assume an object called feature exists.
> 
> From looking at the gml paser  example object,I  the feature object is 
> created by the gml paser, fine no problems there, but how I can access 
> the contents of my xml file?
> 
> My current file format is
> <bar>
> <gml:featureMember>
>    <foo name="xxx" type="yyyy">
>        <gml:point srsName="EPSG:4326">
>            <gml:coordinates>34.333,44.44</gmlcoordinates>
>        </gml:Point>
>    </foo>
> </gmlfeatureMemeber>
> </bar>
> 
> For example in this any suggestions on how I would access the values of 
> name and type elements of the xml type foo?

You wouldn't. Instead, serialize these as proper GML properties. See
examples/gml/point.gml for an example.   

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list