Vector 添加矢量数据-带WFS传输的GML格式(可能有错误?)

Vector 添加矢量数据-带WFS传输的GML格式(可能有错误?),vector,openlayers-3,gml,web-feature-service,Vector,Openlayers 3,Gml,Web Feature Service,我试图通过查询一个提供GML数据的公开可用WFS服务器,向我的OpenLayers地图添加功能 // initalize the map var map = new ol.Map({ layers: [ new ol.layer.Tile({ // OpenLayers public map server source: new ol.source.OSM() }), ], target: '

我试图通过查询一个提供GML数据的公开可用WFS服务器,向我的OpenLayers地图添加功能

// initalize the map
var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            // OpenLayers public map server
            source: new ol.source.OSM()
        }),
    ],
    target: 'map',
    view: new ol.View({
        // center on Murica
        center: [-10997148, 4569099],
        zoom: 4
    })
});

var xmlhttp = new XMLHttpRequest();

// execute this once the remote GML xml document has loaded
xmlhttp.onload = function() {

    console.log("GML XML document retrieved.  executing onload handler:");
    var format = new ol.format.GML3();

    var xmlDoc = xmlhttp.responseXML;

    console.log("you will see multiple features in the xml: ");
    console.log(xmlDoc);

    // Read and parse all features in XML document
    var features = format.readFeatures(xmlDoc, {
        featureProjection: 'EPSG:4326',
        dataProjection: 'EPSG:3857'
    });

    console.log("for some reason only a single feature will have been added: ")
    console.log(features);
    console.log("Why is this?");

    var vector = new ol.layer.Vector({
        source: new ol.source.Vector({
            format: format
        })
    });

    // Add features to the layer's source
    vector.getSource().addFeatures(features);

    map.addLayer(vector);
};

// configure a GET request
xmlhttp.open("GET", "http://geoint.nrlssc.navy.mil/dnc/wfs/DNC-WORLD/feature/merged?version=1.1.0&request=GetFeature&typename=DNC_APPROACH_LIBRARY_BOUNDARIES&srsname=3857",
   true);

// trigger the GET request
xmlhttp.send();
下面是一个代码笔,演示了这个bug

在这里,您可以将其打包下载到单个HTML文件中:

使用有效的typename,我可以成功地将包含多个功能的整个功能集合下载到变量xmlDoc中。然而,当我使用format.ReadFeatures(xmlDoc)时,OpenLayers GML格式解析器似乎只从功能集合中提取一个功能,而它应该提取更多功能


如果有人能看一看,看看他们是否能找出我做了什么愚蠢的错误,或者这是OpenLayers3中的一个合法错误,那就太好了。非常感谢任何能帮忙的人

添加了单个功能,因为整个文档是读取的,而不是格式。readFeatures(xmlDoc)解析每个功能。以下是源代码:

    var vector;
    var map = new ol.Map({
        layers: [
            new ol.layer.Tile({
                source: new ol.source.OSM()
            }),
        ],
        target: 'map',
        view: new ol.View({
            center: [-8197020.761224195,8244563.818176944],
            zoom: 4
        })
    });

    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = function() {
        var format = new ol.format.GML3();
        var xmlDoc = xmlhttp.responseXML;
        vector = new ol.layer.Vector({
            source: new ol.source.Vector({
                format: format
            })
        });

        for (var i = 1; i < xmlDoc.children[0].children.length; i++) {
            var features = format.readFeatures(xmlDoc.children[0].children[i], {
                featureProjection: 'EPSG:4326'
            });


            features.getGeometry().transform('EPSG:4326', 'EPSG:3857');
            vector.getSource().addFeature(features);
        }

        map.addLayer(vector);
        map.getView().fit(vector.getSource().getExtent(), map.getSize())
    };

    xmlhttp.open("GET", "http://geoint.nrlssc.navy.mil/dnc/wfs/DNC-WORLD/feature/merged?version=1.1.0&request=GetFeature&typename=DNC_APPROACH_LIBRARY_BOUNDARIES&srsname=3857",
        true);

    // trigger the GET request
    xmlhttp.send();
var向量;
var map=新ol.map({
图层:[
新ol.layer.Tile({
来源:new ol.source.OSM()
}),
],
目标:“地图”,
视图:新ol.view({
中心:[-8197020.7612241958244563.818176944],
缩放:4
})
});
var xmlhttp=new XMLHttpRequest();
xmlhttp.onload=函数(){
var format=new ol.format.GML3();
var xmlDoc=xmlhttp.responseXML;
vector=新ol.layer.vector({
来源:新ol.source.Vector({
格式:格式
})
});
对于(var i=1;i
这是一个代码笔结果。

它的工作原理是赞美所有爱普生之神