Community Map Builder 27 Apr 2008

CollectionList.js

Summary

No overview generated for 'CollectionList.js'


Class Summary
CollectionList  

/*
Author:       Cameron Shorter cameronAtshorter.net
License:      LGPL as per: http://www.gnu.org/copyleft/lesser.html

$Id: CollectionList.js 3888 2008-02-27 18:25:45Z ahocevar $
*/

// Ensure this object's dependancies are loaded.
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");

/**
 * A widget to display a list of context docs to pick from.  This is a view of 
 * a Context Collection as specified in the OGC Context specification.
 * The default xsl stylesheet for this widget also uses the switchMap
 * function, which allows to switch to a different map context.
 * @constructor
 * @base WidgetBaseXSL
 * @param widgetNode  The widget's XML object node from the configuration document.
 * @param model       The model object that this widget belongs to.
 */

function CollectionList(widgetNode, model) {
  WidgetBaseXSL.apply(this,new Array(widgetNode, model));

  /**
   * Switch to another map context, keeping the current extent.
   * @param objRef this widget
   * @modelUrl the URL of the context we want to switch to.
   */
  this.switchMap = function(objRef, modelUrl) {
    // save the current extent
    objRef.extent = objRef.targetModel.map.getExtent();
    objRef.srs = objRef.targetModel.getSRS();
    objRef.scale = objRef.targetModel.map.getScale();
   
    objRef.targetModel.addListener( "loadModel", objRef.setExtent, objRef );
    config.loadModel( objRef.targetModel.id, modelUrl );
  }
  
  /**
   * Sets the extent of the map that we just switched to.
   * Called when the map is reloaded with the new context.
   * @param objRef this widget
   */
  this.setExtent = function (objRef) {
    objRef.targetModel.removeListener( "loadModel", objRef.setExtent, objRef );

    var bbox = objRef.extent.toBBOX().split(/,/);  
    if (objRef.targetModel.getSRS().toUpperCase() != objRef.srs.toUpperCase()) {
      var targetProj = new OpenLayers.Projection(objRef.targetModel.getSRS());
      var srcProj = new OpenLayers.Projection(objRef.srs);
    	var ptLL=new OpenLayers.Geometry.Point(bbox[0],bbox[1]);
    	var ptUR=new OpenLayers.Geometry.Point(bbox[2],bbox[3]);
  		ptLL.transform(srcProj, targetProj);
	    ptUR.transform(srcProj, targetProj);
      objRef.extent = new OpenLayers.Bounds(ptLL.x, ptLL.y, ptUR.x, ptUR.y);
    }
    if (objRef.targetModel.map.getExtent().containsBounds(objRef.extent, false, false)) {
      objRef.targetModel.map.zoomToExtent(objRef.extent);
      if (!objRef.targetModel.map.fractionalZoom && objRef.targetModel.map.getScale() > objRef.scale) {
        objRef.targetModel.map.zoomIn();
      }
    }
  }
}

Community Map Builder 27 Apr 2008

Documentation generated by JSDoc on Sun Apr 27 20:30:54 2008