Openplayers发布Mapserver的WFS服务

function init() { var wfs = OpenLayers.Protocol.WFS({ url: "http://localhost/cgi-bin/mapserv.exe?map=D:/ms4w/Apache/cgi-bin/wfs.map&", featureType: "lake", srsName: "EPSG:3978", geometryName: "GEOM", featurePrefix: "ms" }); var map = new OpenLayers.Map( { div: "map", //下面很重要,如果不设置,每个图片都按照BBOX:-180,-90,90-270这样的经纬度去找,对于用meters来做的mapfile是找不到图的,白屏 maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90), maxResolution: "auto", units: 'METERS', projection: "EPSG:3978" } ); var wms = new OpenLayers.Layer.WMS( "OpenPlayer WMS", "http://localhost/cgi-bin/mapserv.exe?", {layers: 'lake', map:'D:/ms4w/Apache/cgi-bin/wms.map', IMAGETYPE:'PNG'}, { reproject: false, 'numZoomLevels': 20, gutter: 15, buffer: 0, visibility: true } ); map.addLayer(wms); //缩放级别,以maxExtent的左上角为基点缩放 map.setCenter(new OpenLayers.LonLat(0, 0), 15); var control = new OpenLayers.Control.GetFeature({ protocol: wfs, hover: true, multipleKey: "shiftKey", toggleKey: "ctrlKey" }); control.events.register("featureselected", this, function(e){ select.addFeatures([e.feature]); }); control.events.register("featureunselected", this, function(e){ select.removeFeatures([e.feature]); }); control.events.register("hoverfeature", this, function(e){ hover.addFeatures([e.feature]); }); control.events.register("outfeature", this, function(e){ hover.removeFeatures([e.feature]); }); map.addControl(control); control.activate(); map.addControl(new OpenLayers.Control.LayerSwitcher()); map.addControl(new OpenLayers.Control.MousePosition()); if (!map.getCenter()) { map.zoomToMaxExtent(); } }
posted @ 2011-08-01 16:44  一路遥遥  阅读(1421)  评论(0编辑  收藏  举报