简体   繁体   English

Openlayers-禁用平移层

[英]Openlayers - Disable pan on a layer

I'm using OpenLayers and I'm trying to create an information overlay layer. 我正在使用OpenLayers,并且试图创建一个信息叠加层。 I'm using my own WMS server, so for this layer, the server always send an image with informations in it. 我正在使用自己的WMS服务器,因此对于该层,服务器始终发送包含信息的图像。 My problem is that when I pan the Map, my "information" layer also pan, once finished panning, the layer is refreshed and the text is displayed in the right position. 我的问题是,当我平移地图时,我的“信息”层也将平移,一旦平移完成,该层将刷新并在正确的位置显示文本。 I would like to disable panning on this particular layer (WMS), is there any way to achieve this ? 我想在此特定层(WMS)上禁用平移,有什么方法可以实现?

I tried with an external div but didn't succeed, the panning was still there. 我尝试了一个外部div,但没有成功,平移仍然存在。

Thanks ! 谢谢 !

Edit: So here is what I've come with. 编辑:这就是我所附带的。 It works perfectly, thanks for the idea 效果很好,谢谢你的想法

<script type="text/javascript"> 
    /////////////////////////////////////////
    // USE AN EMPTY LAYER WITH ATTRIBUTION //
    /////////////////////////////////////////

    var informationLayerRefreshStrategy = new OpenLayers.Strategy.Refresh({
        interval: 10000,
        force:true,
        refresh: function() {
        if (this.layer) {
            this.layer.attribution = "Data loading ...";
                // Load new attributions
            var layer = this.layer;
            $.ajax({
                url: "myURL",
                success: function(data){
                    layer.attribution = data;
                    map.getControlsByClass("OpenLayers.Control.Attribution")[0].updateAttribution();
                },
                global: false
            });
          }
     }
});

    var informationLayer =  new OpenLayers.Layer(
        "Sans fond de plan",
        {attribution:"Data loading ..."});

        informationLayerRefreshStrategy.setLayer(informationLayer);
        informationLayerRefreshStrategy.activate();
</script>

My conclusion: Use a separate layer that only contains the attribution values. 我的结论:使用仅包含归因值的单独图层。 Do your querying to a separate resource that you could configure to use JSON. 查询可配置为使用JSON的单独资源。 In the refreshStrategy, only update the Attribution for the layer with the resulting data, and style the generated attribution div to display on the correct place with regards to your map. 在refreshStrategy中,仅使用结果数据更新图层的Attribution,并设置生成的Attribution div的样式以显示在与地图有关的正确位置上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM