我目前正在设置PostGIS / Mapserver / OpenLayers应用程序。它可以很好地提供我的数据的图像,但我不能为我的生活得到一个WFS层显示在OpenLayers。
我已经完成了类似的问题,并解决了那里提到的所有问题,例如跨域问题,SRS名称等。我已经到了OpenLayers请求数据的地步,Mapserver用数据回答设置,但OpenLayers中仍未显示任何内容。
这是我的mapfile和我的OpenLayers测试文件。请注意,基本映射服务器层(“区域”)正确显示。 WFS层(“河流”)仍然是隐形的。任何帮助非常感谢。 javascript控制台中没有错误消息。
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
和OpenLayers测试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>
我可以想象的一个问题是坐标系。我应该使用EPSG:404000我相信,因为我的坐标是从任意0点开始的m,所以范围是0到大约100,000 - 但是因为它似乎对图像工作得很好,Mapserver和OpenLayers都没有抱怨,我'我目前正在以这种方式进行测试。
更新 以下是WFS服务器响应的第一部分:
<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>