简体   繁体   中英

Openlayers - Disable pan on a layer

I'm using OpenLayers and I'm trying to create an information overlay layer. I'm using my own WMS server, so for this layer, the server always send an image with informations in it. 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 ?

I tried with an external div but didn't succeed, the panning was still there.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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