开发者

OpenLayers finding out a user's zoom level with the BBOX strategy

I am currently making a site which uses OpenLayers and plotting with the BBOX strategy. Potentially there can be alot of points to plot in the db. Whe开发者_开发百科n OpenLayers sends the BBOX coordinates I would like OpenLayers to send what the current zoom level is. I would use this zoom level to decide whether I should send all results or the 10 most recent entries. Is it possible for OpenLayers to send what the current zoom level is back to the server when OpenLayers sends the BBOX information?


Not by default, but you could override the triggerRead function and add the zoom level yourself. Something like this (untested):

OpenLayers.Strategy.BBOX.prototype.triggerRead = 
function() {
    if (this.response) {
        this.layer.protocol.abort(this.response);
        this.layer.events.triggerEvent("loadend");
    }
    this.layer.events.triggerEvent("loadstart");
    this.response = this.layer.protocol.read({
        filter: this.createFilter(),
        callback: this.merge,
        scope: this,
        params: {center: this.layer.getZoomForExtent()}
    });
}

Or, of course just calculate the zoom level with the BBOX parameters.


I have tested this and it works:

        //override BBOX strategy in order to pass zoom
        OpenLayers.Strategy.BBOX.prototype.triggerRead = 
        function() {
            if (this.response) {
                this.layer.protocol.abort(this.response);
                this.layer.events.triggerEvent("loadend");
            }
            this.layer.events.triggerEvent("loadstart");
            this.response = this.layer.protocol.read({
                filter: this.createFilter(),
                callback: this.merge,
                scope: this,
                params: {zoom: this.layer.map.getZoom()}

            });
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜