[OpenLayers-Users] Cannot get GML layer to load

Scott Melby smelby at fastlanesw.com
Mon Jan 14 10:31:10 PST 2013


Hello -

I am using GeoServer and am able to get back valid GML in my browser  as 
follows:

<wfs:FeatureCollection numberOfFeatures="50" 
timeStamp="2013-01-14T12:29:26.748-05:00" 
xsi:schemaLocation="http://511nj.org/ 
http://localhost:8082/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=nj511%3Alinks_shifted 
http://www.opengis.net/wfs 
http://localhost:8082/geoserver/schemas/wfs/1.1.0/wfs.xsd">
<gml:featureMembers>
<nj511:links_shifted gml:id="links_shifted.blah">
<nj511:gid>blah</nj511:gid>
<nj511:the_geom>
<gml:MultiLineString srsDimension="2" 
srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
<gml:lineStringMember>
<gml:LineString>
<gml:posList>-74.17828 40.8572 -74.17868 40.85729 -74.17893 40.85738 
-74.17927 40.85756 -74.1794 40.85765 -74.1795 40.85776 -74.17963 
40.85793 -74.1799 40.85852 -74.18028 40.85966</gml:posList>
</gml:LineString>
</gml:lineStringMember>
</gml:MultiLineString>
</nj511:the_geom>
</nj511:links_shifted>
...
</gml:featureMembers>


However, I cannot seem to get the right combination of featureNS, 
featurePrefix etc. in my Format.GML (I have tried format.GML and 
format.GML.v3) object to get the features to be load properly into my 
Vector layer.  Below is my current code:

         var wfsOptions = {
             url: 'http://somehost/geoserver/ows?',
             params: {
                 request: "GetFeature",
                 service: "wfs",
                 typeName: "nj511:links_shifted",
                 maxFeatures: "50",
                 featureNS: "http://testdom.org",
                 srsName: "EPSG:4326"
             },
             format: new OpenLayers.Format.GML.v3({
                 featureNS: "http://testdom.org",
                 featureType: "nj511:links_shifted",
                 geometryName: 'nj511:the_geom'
             })
         };

         var featureLayer = new OpenLayers.Layer.Vector('WFS', {
             visibility: true,
             strategies: [new OpenLayers.Strategy.Fixed()],
             protocol: new OpenLayers.Protocol.HTTP(wfsOptions)
         });

         this.featureLayer = featureLayer;
         this.featureLayer.events.register('loadend',this.featureLayer, 
function(e) {
             // When this occurs, we have completed fetching links
             if ( e.object && e.object.features  )
             {
                 if ( e.object.features.length >1 )
...


When my loadend handler is called, e.object.features.length is always 
0.  Note: I am using HTTP instead of WFS directly because I am trying to 
load this data off of a remote server.  WFS was always giving me a 
request type OPTIONS.

  I am sure that the GML that is returned is as shown above because I am 
grabbing the URL that OpenLayers is hitting from my debugger and posting 
it into my browser.  So... it appears to simply be a matter of getting 
openlayers to correctly parse the returned GML.

Any help is greatly appreciated.

Thanks
Scott

---
Scott Melby
Fast Lane Software LLC
http://www.fastlanesw.com
717.799.1775


More information about the Users mailing list