openlayer加载geoserver发布的wfs图层方法
//测试添加wfs图层 var t_geoserver_url="http://192.168.30.16:8080/geoserver"; this.map.addLayer(this.map.createLayerByWFSJsonp("onemap:bz_point","wfs标记点图层",t_geoserver_url)); this.map.addLayer(this.map.createLayerByWFSJsonp("onemap:cjqy2010","wfs村级行政区图层",t_geoserver_url)); //添加wfs格式的jsonp的图层ok cwgisMap.prototype.createLayerByWFSJsonp = function (layerName, caption, geoserver_url) { // var t_wfsUrl = ""; //geoserver_url="http://192.168.30.16:8080/geoserver"; if (caption && caption.trim() == "") caption = layerName; this.vectorSource = new ol.source.Vector({ format: new ol.format.GeoJSON({ geometryName: "geom" }), name: layerName, caption: caption, url: function (extent) { t_wfsUrl = geoserver_url + "/wfs?service=wfs&version=1.0.0&request=GetFeature&typeName=" + layerName; t_wfsUrl += '&outputFormat=application/json&srsname=EPSG:3857&'; t_wfsUrl += 'bbox=' + extent.join(',') + ',EPSG:3857'; // return t_wfsUrl; }, strategy: ol.loadingstrategy.bbox }); var BSIconStyle = new ol.style.Style({ /*icon样式*/ image: new ol.style.Icon( /** @type {olx.style.IconOptions} */ ({ opacity: 0.95, src: '../static/imgs/data/bs2.png' })) }); var vLayer = new ol.layer.Vector({ source: this.vectorSource, name:layerName, caption:caption, type:2, style: [new ol.style.Style({ //绘制几何图形样式 fill: new ol.style.Fill({ //填充样式 color: 'rgba(255, 255, 255, 0.2)' }), stroke: new ol.style.Stroke({ //边线样式 color: 'rgba(255, 0, 0, 0.5)', lineDash: [10, 10], width: 2 }), image: new ol.style.Circle({ //点样式 radius: 8, stroke: new ol.style.Stroke({ color: 'rgba(255, 0, 0, 0.7)' }), fill: new ol.style.Fill({ color: 'rgba(255, 0, 0, 0.2)' }) }) })] }); return vLayer; };