[GIS] Can we request new OpenLayers WMS image for an extent without moving the map

openlayers-2

Can we request new OpenLayers WMS image for an extent without moving the map center ?

Reading OpenLayers code, OpenLayers move map center to new extent, and THEN do HTTP request to get the image.

Is it possible to instruct the map to HTTP load certain extent and when 'tileloaded' is fired, THEN load new WMS image?

Edit ———————-

  1. The problem is I need to "tell the map to zoomToExtent" so it gets a new bound.

  2. OpenLayers Map sets its center and zoom first, and then request new map through HTTP.

  3. The map response will be available in 2 seconds, until that time, map view is blank (if new bound is outside current bound).

    if( result.zoom ) {

                           var bounds = result.data.map.mapBounds;
                            var x1 = parseFloat( bounds.x1 );
                            var x2 = parseFloat( bounds.x2 );
                            var y1 = parseFloat( bounds.y1 );
                            var y2 = parseFloat( bounds.y2 );
    
                            map.zoomToExtent([x1, y1, x2, y2]);
                    }
    
  4. What i think i need is fetchWmsBound() below.

         if( result.zoom ) {
                           var bounds = result.data.map.mapBounds;
    
                            var x1 = parseFloat( bounds.x1 );
                            var x2 = parseFloat( bounds.x2 );
                            var y1 = parseFloat( bounds.y1 );
                            var y2 = parseFloat( bounds.y2 );
    
                            function wmsLoaded() {
                                 map.redraw(true);
                            }
    
                            //
                            // @param { <Array.number> } bounds,
                            // @param { Function } callback to exec when wms is fetched
                            // fetchWmsBound might trigger a 'fetched' event also
    
                            map.wmslayer.fetchWmsBound( [x1, y1, x2, y2], wmsLoaded );                                
    
                    }
    

Filed at https://github.com/openlayers/openlayers/issues/573

Best Answer

when u check out OpenLayers.Layer.WMS structure, you can see that it inherits from OpenLayers.Layer.Grid... and when looking at api, you can notice that spiralTileLoad() may help you about what you want...

from OpenLayers doc:

spiralTileLoad: function()

Starts at the top right corner of the grid and proceeds in a spiral towards the center, adding tiles one at a time to the beginning of a queue.

Once all the grid’s tiles have been added to the queue, we go back and iterate through the queue (thus reversing the spiral order from outside-in to inside-out), calling draw() on each tile.

code:

var wms = new OpenLayers.Layer.WMS("NASA Global Mosaic",
          "http://wms.jpl.nasa.gov/wms.cgi",
          {layers: "modis,global_mosaic"});
wms.spiralTileLoad();
wms.redraw();

or

map.layers[i].spiralTileLoad();
map.layers[i].redraw();

i hope it helps you...