I'm currently setting up a PostGIS/Mapserver/OpenLayers application. It works fine for serving up an image of my data, but I can not for the life of me get a WFS layer to show up in OpenLayers.
I've gone through the similar questions and resolved all the points mentioned there such as cross-domain issues, SRS names, etc. I have come to the point where the data is requested by OpenLayers and the Mapserver answers with a data set, but still nothing shows up in OpenLayers.
Here are my mapfile and my OpenLayers test file. Note that the base mapserver layer ("regions") is displayed correctly. It is the WFS layer ("rivers") that remains invisble. Any help much appreciated. There are no error messages in the javascript console.
the mapfile:
MAP
NAME "test"
STATUS ON
EXTENT 0 0 100000 100000
SIZE 1200 800
IMAGECOLOR 0 40 120
WEB
MINSCALE 10
MAXSCALE 1000000000
METADATA
"wfs_title" "Might & Fealty WFS Service"
"wfs_srs" "EPSG:4326"
"wfs_onlineresouce" "http://va.mightandfealty.com/mapserver"
"wfs_enable_request" "*"
END
END
LAYER
NAME "regions"
STATUS ON
METADATA
"wfs_title" "estates"
"wfs_srs" "EPSG:4326"
"gml_featureid" "id"
"wfs_enable_request" "*"
END
TYPE POLYGON
CONNECTIONTYPE POSTGIS
CONNECTION "host=127.0.0.1 port=5432 dbname=bm2 user=bm2 password=xxx"
DATA "poly from geodata"
FILTER (biome not in ('water','ocean'))
CLASS
STYLE
OUTLINECOLOR 200 20 20
COLOR 20 200 20
WIDTH 1
ANTIALIAS true
END
END
END
LAYER
NAME "rivers"
STATUS ON
METADATA
"wfs_title" "rivers"
"wfs_srs" "EPSG:4326"
"gml_featureid" "id"
"wfs_enable_request" "*"
END
TYPE LINE
CONNECTIONTYPE POSTGIS
CONNECTION "host=127.0.0.1 port=5432 dbname=bm2 user=bm2 password=xxx"
DATA "course from river"
CLASS
STYLE
COLOR 0 80 160
WIDTH 2
ANTIALIAS true
END
END
END
END
and the OpenLayers test HTML:
<html>
<head>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>
<div id="map" style="width:1200px;height:800px"></div>
<script language="javascript" type="text/javascript">
var map, layer;
init();
function init(){
var mapBounds = new OpenLayers.Bounds(0, 0, 100000, 100000);
var geojson_format = new OpenLayers.Format.GeoJSON();
var options = {
maxExtent: mapBounds,
projection: new OpenLayers.Projection('EPSG:4326'),
units: 'm'
};
map = new OpenLayers.Map('map', options);
baselayer = new OpenLayers.Layer.MapServer("Mapserver",
"http://va.mightandfealty.com/mapserver",
{map: 'basemap', layers: ['regions']}, {singleTile:true});
map.addLayer(baselayer);
var style = new OpenLayers.Style({
fillColor: '#ffff00',
strokeColor: '#0040ff',
strokeWidth: 5
});
var style = new OpenLayers.Style({
fillColor: '#ffff00',
strokeColor: '#0040ff',
strokeWidth: 5
});
layer = new OpenLayers.Layer.Vector("Rivers", {
renderers: ["SVG2", "VML", "Canvas"],
styleMap: new OpenLayers.StyleMap(style),
strategies: [new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.WFS({
url: "http://va.mightandfealty.com/mapserver?map=basemap&service=wfs&srsName=EPSG:4326",
featureType: "rivers",
featureNS: "http://va.mightandfealty.com/maplayers/rivers",
srsName: "EPSG:4326",
geometryName: "course",
version: "1.1.0"
}),
});
map.addLayer(layer);
layer.setVisibility(true);
map.zoomToMaxExtent();
};
</script>
</body>
</html>
One thing I can imagine as causing issues is the coordinate system. I should use EPSG:404000 I believe, as my coordinates are in m from an arbitrary 0 point, so the range is 0 to about 100,000 - but as it seems to work just fine for the image and neither Mapserver nor OpenLayers complain, I'm currently testing this way.
Update: Here is the first part of the response from the WFS server:
<wfs:FeatureCollection xmlns:ms="http://mapserver.gis.umn.edu/mapserver" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://mapserver.gis.umn.edu/mapserver http://va.mightandfealty.com/mapserver?SERVICE=WFS&VERSION=1.0.0&REQUEST=DescribeFeatureType&TYPENAME=feature:rivers&OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>9870.500000,11393.700000 89396.100000,82458.000000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:rivers fid="rivers.56288">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>30170.100000,36050.400000 33748.000000,42180.900000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:LineString srsName="EPSG:4326">
<gml:coordinates>30170.100000,42180.900000 30638.666606,42145.195547 31092.384113,42022.852978 31541.532887,42110.569985 31998.200000,41998.700000 31982.139081,41544.379665 32041.352331,41093.103418 32150.754503,40642.976204 32175.600000,40200.500000 32217.079394,40152.159753 32264.056250,40095.565900 32311.261782,40056.552423 32364.300000,40011.900000 32669.068387,39950.658606 32967.946875,39965.794791 33268.616917,39823.880529 33589.700000,39722.200000 33560.642536,39352.254679 33714.125000,38989.478112 33634.090702,38633.521408 33748.000000,38273.400000 33232.041223,38066.279559 32676.456250,37646.200251 32160.021640,37573.382959 31663.300000,37339.200000 31802.023226,37019.298307 31883.325000,36677.163326 31937.030313,36378.729052 32022.800000,36050.400000 </gml:coordinates>
</gml:LineString>
</ms:msGeometry>
</ms:rivers>
</gml:featureMember>
<gml:featureMember>
<ms:rivers fid="rivers.56291">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>33843.100000,48178.700000 36248.400000,52306.300000</gml:coordinates>
</gml:Box>
</gml:boundedBy>