在vector openlayer图层上设置策略

Setting strategy on vector openlayer layer

在 Openlayers 3.9.0 中,我使用 loader 从 Geoserver 获取矢量图层。这是代码

var sourceVector = new ol.source.Vector({
    format: new ol.format.GeoJSON(),
    loader: function (extent) {
        $.ajax('http://localhost:5550/geoserver/mymap/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=mymap:mylayer&outputFormat=application/json', 
        {type: 'GET'})
        .done(      
         function(response) {
                    var geojsonFormat = new ol.format.GeoJSON({});
                    sourceVector.addFeatures(geojsonFormat.readFeatures(response,{dataProjection :projection,featureProjection : projection}));
                })
        .fail(function () {alert("BAD");});
    },
    strategy: new ol.loadingstrategy.tile(ol.tilegrid.createXYZ({maxZoom: 20}))
});

我尝试将 strategy 更改为 strategy: new ol.loadingstrategy.bbox 但我得到 Uncaught TypeError: this.strategy_ is not a function.

大部分例子都设置了bbox策略,在url上也设置了一个BBOX。如果我在 url 末尾添加 ....&BBOX='+extent.join(','),我仍然会遇到同样的错误。我错过了什么?是策略、url、设置?我该如何解决这个问题?

谢谢

您不应该初始化一个新的 ol.loadingstrategy.bbox,它已经是一个 ol.LoadingStrategy(不像 ol.loadingstrategy.tile,它是一个返回基于 TileGrid 的 ol.LoadingStrategy 的工厂。

// when using the bbox strategy:
strategy: ol.loadingstrategy.bbox

// when using the tile strategy:
strategy: new ol.loadingstrategy.tile(tileGrid)