Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers 3

The map is blanked because applyBackBuffer(),

my workaround is to modify OpenLayers Layer/Grid.js

https://github.com/lydonchandra/openlayers/commit/11bfb0efd754f79896c845b2d4dc1e24bf5b68f7

Pull request https://github.com/openlayers/openlayers/pull/586

moveTo:function(bounds, zoomChanged, dragging) {
      ...
        if (this.singleTile) {

            if ( forceReTile ||
                 (!dragging && !tilesBounds.containsBounds(bounds))) {

                if(zoomChanged && this.transitionEffect !== 'resize') {
                    this.removeBackBuffer();
                }
                if( this.transitionEffect === 'resize' ) {

                        // if new-bounds is within old-bounds (zoom-out)
                        if( (tilesBounds && tilesBounds.containsBounds(bounds))

                            // if old-bounds intersects new-bounds (pan)
                            || (tilesBounds && tilesBounds.intersectsBounds(bounds))

                            // if old-bounds is within new-bounds (zoom-in)
                            || (bounds && tilesBounds
                                && bounds.containsBounds(tilesBounds)) )
                        {
                                this.applyBackBuffer(serverResolution);
                        }
                }

                this.initSingleTile(bounds);
share|improve this answer
add comment

or maybe you can just do the wms.redraw() function to do this?

share|improve this answer
    
i've to zoom to new extent first...see edited problem description. –  portoalet Jul 4 '12 at 1:16
add comment

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

share|improve this answer
    
thanks 4 ur advice, i updated problem description with fetchWmsBound(), which i think i need, but don't know to implement it (yet). –  portoalet Jul 4 '12 at 1:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.