map Extent issue in dojox/app/view when switching between views

2005
0
11-13-2014 04:57 PM
TheresaRepta
New Contributor

I’m using dojox/app/views in my application.  One of my views contains a map.  The underlying problem that I’m having is that my map is getting an invalid extent set if the user transitions quickly between views.

I’ve already turned off auto-resizing, and have implemented my own custom function that makes sure that the dijit.layout.ContentPane that
contains my map is visible. 

I tried to add in logic to retain the last valid extent of the map, and reset it if it’s going to be set to NAN or Infinity, etc.


dojo.connect(map, 'onLoad', function(theMap) {
dojo.config.lastValidExtent = theMap.extent; // Save valid extent.


dojo.connect(dijit.byId('map'), 'resize', function() { // where “map” is the dijit.layout.ContentPane that contains my map
 
 clearTimeout(resizeTimer);
 resizeTimer = setTimeout( function() {


  var node = dijit.byId("map-view").domNode.parentNode; //Checking to see if the map view is visible.
  if(node.classList.contains("dijitVisible")){
   /*
   Checking for an "Invalid Extent" 
   */
   if(isNaN(map.extent.xmax) || isNaN(map.extent.xmin) || isNaN(map.extent.ymax) || isNaN(map.extent.ymin)
    || map.extent.xmax == map.extent.xmin || map.extent.ymax == map.extent.ymin
    || map.extent.xmax == Number.POSITIVE_INFINITY || map.extent.xmax == Number.NEGATIVE_INFINITY 
    || map.extent.xmin == Number.POSITIVE_INFINITY || map.extent.xmin == Number.NEGATIVE_INFINITY 
    || map.extent.ymax == Number.POSITIVE_INFINITY || map.extent.ymax == Number.NEGATIVE_INFINITY 
    || map.extent.ymin == Number.POSITIVE_INFINITY || map.extent.ymin == Number.NEGATIVE_INFINITY){
    console.log('INVALID EXTENT!');


      
    map.setExtent(dojo.config.lastValidExtent); // Extent is "invalid" so set the extent to the last valid extent
    map.reposition();
    map.resize();
   }
   else{
    dojo.config.lastValidExtent = map.extent; // Update with new valid extent
    map.reposition();
    map.resize();
     
   }
   }


 }, 500);
});
});

What it looks like is happening now is that the Extent is not getting updated with value I have saved in the lastValidExtent variable.  I added a function for the map’s “extent-change” event and it’s getting fired after I call map.setExtent, but when I check the extent of the map inside of this function, it does not have the updated values.

Is there any way to pre-emptively check and see what the map extent is going to become and then “Cancel” it if it’s going to fall into one of the options above? 

Is there any way to “disable” a map when leaving the map view (so it doesn’t change the extent, or resize), then re-enable it afterwards?

Does anyone have experience working with the map inside of dojo views who has had a similar issue and can offer some guidance on how the resolved it?

I’ve spent quite a few days on this issue already and have pretty much come to a dead end in fixing this.


ANY suggestions at this point would be greatly appreciated.

Thank you very much for your time.

0 Kudos
0 Replies