2017-06-16 172 views
0

我試圖使用Openlayers 4顯示WFS圖層。如果我查詢請求格式爲json的服務器並使用ol.format.GeoJSON,圖層將顯示正確的在地圖上。但使用gml3請求(並使用ol.format.WFS)查詢服務器不會顯示圖層。我檢查了vectorSource,它確實加載了功能,但沒有顯示。OpenLayers 4:使用ol.format.WFS時地圖上未顯示WFS圖層

任何人都有什麼線索可能是什麼? Bellow是我的代碼和xml響應的片段。

loadLayer: function() { 
     var wfsFormat = new ol.format.WFS(); 
     var self = this; 
     this._vectorSource = new ol.source.Vector({ 
     format: wfsFormat, 
     url: function(extent) { 
      var url = self.serviceUrl +     '&request=GetFeature&typeName=cite:dl_3&outputFormat=gml3&srsname=EPSG:3857' + 
       '&bbox=' + extent.join(',') + ',EPSG:3857'; 
      return url; 
     }, 
     strategy: ol.loadingstrategy.bbox, 
     projection: 'EPSG:3857', 
     }); 

     this.inherited(arguments); 
    } 

該加載程序位於名爲WFSLayer的類中。貝婁是在主代碼:

var wfsLayer = WFSLayer({ 
      serviceUrl: wfsServiceUrl, 
     }); 
     wfsLayer.loadLayer(); 

     var wfsVector = new ol.layer.Vector({ 
      source: wfsLayer.getVectorSource(), 
      style: new ol.style.Style({ 
       stroke: new ol.style.Stroke({ 
        color: 'rgba(0, 0, 255, 1.0)', 
        width: 2, 
       }), 
      }), 
     }); 

     var raster = new ol.layer.Tile({ 
      source: new ol.source.XYZ({ 
       attributions: 'Tiles © <a href="https://services.arcgisonline.com/ArcGIS/' + 
       'rest/services/World_Topo_Map/MapServer">ArcGIS</a>', 
       url: 'https://server.arcgisonline.com/ArcGIS/rest/services/' + 
       'World_Topo_Map/MapServer/tile/{z}/{y}/{x}', 
      }), 
     }); 

     var map = new ol.Map({ 
      layers: [raster, wfsVector], 
      target: document.getElementById('map'), 
      view: new ol.View({ 
       center: [705208.0811999999, 6839435.416199997], 
       zoom: 8, 
       projection: 'EPSG:3857', 
      }), 
     }); 

這裏是XML響應的一個片段:

<wfs:FeatureCollection xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="10070" timeStamp="2017-06-15T15:06:48Z" xsi:schemaLocation="http://www.opengeospatial.net/cite http://geoserver:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=cite%3Adl_3 http://www.opengis.net/wfs http://geoserver:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd"> 
<gml:featureMembers> 
<cite:dl_3 gml:id="dl_3.1"> 
<cite:the_geom> 
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#3857" srsDimension="3"> 
<gml:lineStringMember> 
<gml:LineString> 
<gml:posList> 
498498.93497989 6786346.91870299 43.80370511 498497.04800763 6786352.73097019 43.68967084 498495.16103228 6786358.54324726 43.83243658 498498.89640871 6786359.76200893 43.70402609 498499.33127574 6786359.90391212 43.65502487 498501.21824812 6786354.09163816 43.72265914 498503.10521781 6786348.27936783 43.7882934 498502.63037784 6786348.12447027 43.82089473 498498.93497989 6786346.91870299 43.80370511 
</gml:posList> 
</gml:LineString> 
</gml:lineStringMember> 
</gml:MultiLineString> 
</cite:the_geom> 
</cite:dl_3> 
<cite:dl_3 gml:id="dl_3.2"> 
<cite:the_geom> 
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#3857" srsDimension="3"> 
<gml:lineStringMember> 
<gml:LineString> 
<gml:posList> 
498509.86707833 6786343.314062 43.70141855 498508.02631507 6786349.10070888 43.75378441 498506.18554938 6786354.88735662 43.69115027 498509.61544357 6786355.98400546 43.67794078 498510.10837676 6786356.14156283 43.62683941 498511.94913995 6786350.35491354 43.70037356 498513.78990048 6786344.56826831 43.7912077 498513.44929737 6786344.45934742 43.78340864 498509.86707833 6786343.314062 43.70141855 
</gml:posList> 
</gml:LineString> 
</gml:lineStringMember> 
</gml:MultiLineString> 
</cite:the_geom> 
</cite:dl_3> 
<cite:dl_3 gml:id="dl_3.3"> 
<cite:the_geom> 
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#3857" srsDimension="3"> 
<gml:lineStringMember> 
<gml:LineString> 
<gml:posList> 
498513.37376869 6786275.58223307 43.95293282 498510.96125125 6786281.14230307 43.92010051 498508.54873049 6786286.70237625 43.89516819 498511.70049349 6786288.07686893 43.8335572 498514.11293161 6786282.51679254 43.84838951 498516.5253664 6786276.95671993 43.89402182 498513.70936863 6786275.72873202 43.95213165 498513.37376869 6786275.58223307 43.95293282 
</gml:posList> 
</gml:LineString> 
</gml:lineStringMember> 
</gml:MultiLineString> 
</cite:the_geom> 
</cite:dl_3> 
<cite:dl_3 gml:id="dl_3.4"> 
<cite:the_geom> 
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#3857" srsDimension="3"> 
<gml:lineStringMember> 
<gml:LineString> 
<gml:posList> 
498547.56469744 6786240.41906434 43.91062195 498546.95224789 6786240.21669251 43.91602369 498547.4916903 6786238.48738942 43.91663392 498548.12052306 6786238.67374152 43.91073226 498547.56469744 6786240.41906434 43.91062195 
</gml:posList> 
</gml:LineString> 
</gml:lineStringMember> 
</gml:MultiLineString> 
</cite:the_geom> 
</cite:dl_3> 
<cite:dl_3 gml:id="dl_3.20"> 
<cite:the_geom> 
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#3857" srsDimension="3"> 
<gml:lineStringMember> 
<gml:LineString> 
<gml:posList> 
498835.21795003 6785163.91809574 46.00415766 498829.6138097 6785161.26036719 46.02577907 
</gml:posList> 
</gml:LineString> 
</gml:lineStringMember> 
</gml:MultiLineString> 
</cite:the_geom> 
</cite:dl_3> 

回答

0

我想通了。如果有人在那裏有同樣的問題。問題是我正在使用帶有3D圖層的GML3。 Openlayers不能正確地從XML中獲取srsDimension屬性,因此座標將不正確。到目前爲止,您可以使用GML2(或之前處理XML)。我已經將它作爲issue添加到git中。