OpenLayers 使用 BBOX 策略找出用户的缩放级别

发布于 2024-10-31 12:13:09 字数 198 浏览 2 评论 0原文

我目前正在制作一个使用 OpenLayers 并使用 BBOX 策略进行绘图的网站。数据库中可能有很多点可以绘制。当 OpenLayers 发送 BBOX 坐标时,我希望 OpenLayers 发送当前的缩放级别。我将使用此缩放级别来决定是否应该发送所有结果或最近的 10 个条目。当OpenLayers发送BBOX信息时,OpenLayers是否可以将当前的缩放级别发送回服务器?

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. When 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情废物 2024-11-07 12:13:09

默认情况下不是这样,但您可以重写triggerRead 函数并自行添加缩放级别。像这样的东西(未经测试):

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()}
    });
}

或者,当然只是使用 BBOX 参数计算缩放级别。

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.

墨落成白 2024-11-07 12:13:09

我已经测试过这个并且它有效:

        //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()}

            });
        }

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()}

            });
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文