OpenLayers3 GeoJSON 解析错误的参数?

OpenLayers3 GeoJSON parsing wrong argument?

在将要素绘制到 OpenLayers 地图(地图叠加层)后,我想解析要素以便能够发送它。

问题是,当我调用 getArray() 时它起作用,而没有 getArray 时它不起作用。 parse.writeFeatures 不应该作为参数 featureOverlay.getFeatures() 而不是 featureOverlay.getFeatures().getArray() 吗?

        $.FooBarNS.featureOverlay = new ol.FeatureOverlay({
          style: new ol.style.Style({
            fill: new ol.style.Fill({
              color: 'rgba(255, 255, 255, 0.2)'
            }),
            stroke: new ol.style.Stroke({
              color: '#ffcc33',
              width: 2
            }),
            image: new ol.style.Circle({
              radius: 7,
              fill: new ol.style.Fill({
                color: '#ffcc33'
              })
            })
          })
        });



$.FooBarNS.featureOverlay.setMap(map);

    $('#save_polygon').click( function(){

        var parser = new ol.format.GeoJSON();
        //features = $.FooBarNS.features;
        var features =    $.FooBarNS.featureOverlay.getFeatures().getArray();
        console.log(features);

        var featuresGeoJSON = parser.writeFeatures(features, {'dataProjection':'EPSG:4326','featureProjection':'EPSG:3857'});
        console.log(featuresGeoJSON);
        $.ajax({
            type: 'POST',
            url: 'http://gis.FooBar.com/testpolygon/',
            dataType: 'json',
            //contentType: 'application/json;charset=utf-8',
            data: featuresGeoJSON
        }).then(function(response) {
            //console.log(response);
        });


    });

查看 API 文档:http://openlayers.org/en/v3.5.0/apidoc/ol.format.GeoJSON.html#writeFeatures

writeFeatures 采用 ol.Feature 的数组,因此这就是您需要传入的内容。