3

how to reload ServerVector with different zoom levels ? I don't want to use ol.loadingstrategy.createTile strategy because it sends many requests with each zoom -one request with each tile - which takes some time. I want to force it to send one request in each zoom level because WFS parameters are changed in every zoom level

4

I did workaround for this issue:

I used ol.loadingstrategy.bbox to trigger reload each time I zoom but it didn't work because the new extent is subset from the old extent which is loaded already, this is the default loadFeature function which is used by ServerVector each time the bbox is changed:

 ol.source.ServerVector.prototype.loadFeatures = function(extent, resolution, projection) {
      var loadedExtents = this.loadedExtents_;
      var extentsToLoad = this.strategy_(extent, resolution);
      var i, ii;
      for (i = 0, ii = extentsToLoad.length; i < ii; ++i) {
        var extentToLoad = extentsToLoad[i];
            var alreadyLoaded = loadedExtents.forEachInExtent(extentToLoad,
            /**
             * @param {{extent: ol.Extent}} object Object.
            * @return {boolean} Contains.
            */
            function(object) {
                return ol.extent.containsExtent(object.extent, extentToLoad);
            });
        if (!alreadyLoaded) {
            this.loader_.call(this, extentToLoad, resolution, projection);
            loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
        }
    }
};

alreadyLoaded flag prevent the reloading of the ServerVector and in the same time this function should use it to tell the map that all extents are loaded each time we move or zoom. so I overwrite this function to be

myvectorSourceJsonp.loadFeatures = function(extent, resolution, projection) {
      var loadedExtents = this.loadedExtents_;
      var extentsToLoad = this.strategy_(extent, resolution);
      var i, ii;
      for (i = 0, ii = extentsToLoad.length; i < ii; ++i) {
        var extentToLoad = extentsToLoad[i];
            var alreadyLoaded = loadedExtents.forEachInExtent(extentToLoad,
            /**
             * @param {{extent: ol.Extent}} object Object.
            * @return {boolean} Contains.
            */
            function(object) {
                return ol.extent.containsExtent(object.extent, extentToLoad);
            });
        if (!alreadyLoaded) {
            this.loader_.call(this, extentToLoad, resolution, projection);
            loadedExtents.insert(extentToLoad, {extent: extentToLoad.slice()});
        }
        this.resolution = resolution; //added by me
    }
};

every time I save the resolution of the current state, to use it in strategy function which is called by loadFeatures function. I override the bbox strategy code to check if it is called by resolution change or not

BBox strategy:

ol.loadingstrategy.bbox = function(extent, resolution) {
    return [extent];
};

to this strategy:

myvectorSourceJsonp.strategy_ = function(extent, resolution) {
    if(this.resolution && this.resolution != resolution){
        this.loadedExtents_.clear();
    }
    return [extent];
};

every zoom or resolution change will clear the loadedExtents_ array of the ServerVector to trigger reload function

1

With the bbox strategy (ol.loadingstrategy.bbox) a new request is triggered basically each time the map moves. See http://openlayers.org/en/master/examples/vector-wfs.html for a an example based on that strategy and a WFS. See also this StackOverflow question: https://stackoverflow.com/q/26844412/1064422.

  • I tried it and it didn't work, I think it didn't reload the VectorSource if the extent of new zoom level is in the extent of the previous zoom level. I need to change the filter of every zoom level so I need to force the reload even the new extent is subset from the previous extent – Mariam Malak Nov 12 '14 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.