Openlayers 3 读取GML文件时出现问题(未重新编程)

Openlayers 3 读取GML文件时出现问题(未重新编程),openlayers-3,Openlayers 3,我正试图用这段代码读取openlayers 3.4.0文件中的GML var from = ol.proj.get("EPSG:4326"); var to = ol.proj.get("EPSG:3857"); var gml = new ol.source.StaticVector({ format: new ol.format.GML2({dataProjection: from, featureProjection

我正试图用这段代码读取openlayers 3.4.0文件中的GML

var from = ol.proj.get("EPSG:4326");
var to = ol.proj.get("EPSG:3857");
var gml = new ol.source.StaticVector({
    format: new ol.format.GML2({dataProjection: from, 
                                featureProjection: to}),
    projection: 'EPSG:3857',
    url: 'test_4326.gml'
}); 
var vectorLayer = new ol.layer.Vector({
    source: gml
});
var map;
function init(){
    map = new ol.Map({
        layers: [vectorLayer],
        target: 'map',
        view: new ol.View({
            center: [0, 0],
            zoom: 2
        })
    });
}
这对于KML或GeoJSON(更改ol.format并删除相关参数)很好,但对于GML文件(在ol.format.GML2中也没有参数)则不行。我尝试了一些不同的GML文件,但没有任何效果。在读取阶段,坐标似乎不会被重新投影。 读取GMl文件的正确方法是什么


测试在

当前的方法是使用普通的ol.source.Vector,使用XHR手动获取数据,并直接对格式进行解析,以便您可以指定readFeatures函数的所有选项。之后,您将向源添加功能。例如:

var vector=新ol.layer.vector({
来源:new ol.source.Vector()
});
var format=new ol.format.GML2();
var xmlhttp=new XMLHttpRequest();
open(“GET”,“gml.xml”,true);
xmlhttp.onload=函数(){
var xmlDoc=xmlhttp.responseXML;
var features=format.readFeatures(xmlDoc{
功能投影:“EPSG:3857”,
数据预测:“EPSG:4326”
});
vector.getSource().addFeatures(features);
};
xmlhttp.send();

不再适用于OpenLayers 3.5.0 AssertionError:Assertion failed:objectStack应该是一个数组数组