Class WMSMapCanvas

This class extends the MapCanvas class defined above. It focuses on allowing the displayed image to come from a WMS MapServer, and allows for multiple Aspect objects to be associated with it so you can easily switch between them. Note that in WMS, the bottom left corner is the minx/miny and the top right corner is the maxx/maxy. In this section, only methods that are new or directly override the MapCanvas methods are listed. For all other methods, refer to MapCanvas.
Note that WMSMapCanvas attaches a built-in DblClickListener to itself (really it's parent class). If you wish to provide your own double-click functionality, you may need to set the DblClickMode to 'NONE', to ensure that you don't get conflicts. (However, you can also have multiple listeners, so if the default DblClick functionality is not in conflict with custom functionality, you can simply attach new listeners and they will both be called).


Constructor Summary

WMSMapCanvas ( container , canvasWidth , canvasHeight , inputGrid )
Creates a new WMSMapCanvas object and sets it up.

Method Summary

addAspect ( newAspect )
Attaches a new aspect to the object
changeAspect ( aspectName )
Changes the current aspect to view another one
changeDblClickMode ( newMode )
Changes the action that happens when a double-click is done on the Canvas
changeZoomFactor ( newFactor )
Changes the zoom factor used for double-click events
zoom ( zoomtype , param )
Applies a zoom to the current map.
pan ( xdir , ydir )
Pans the map.
loadWMSImage ( )
Causes the map image to be loaded from the Map Server
setXYFromRSPolgyon ( polygon )
Sets the XY box based on an RS Polygon.
getMoreMousePosInfo ( fullpoint )
Fills in map R/S information to the Mouse Position listener information
getMoreBoxInfo ( boxinfo )
Fills in R/S information to the box returned by Row/Col listeners
adjustGrid ( bnds )
Adjusts the current grid based on the bounds passed in.

Constructor Detail

WMSMapCanvas

Creates a new WMSMapCanvas object and sets it up.


Parameters
container - The HTML DOM container to hold the canvas.
canvasWidth - The width of the canvas
canvasHeight - The height of the canvas
inputGrid - The default grid to use (optional)


Returns
A new WMSMapCanvas object

Examples
new wms = new WMSMapCanvas(somediv, 500, 500, null);
// Creates a new WMSMapCanvas object that is 500x500 pixels,
// and will display it in somediv.

Notes
container should be the actual DOM object, not just a string of the id. The canvas width and height will be used for all aspects, so any that do not match the ratio of these parameters will be cropped (not distorted). Input grid usually does not need to be used, as the WMSAspect objects attached to this class will be used to get the grid.

Method Detail

addAspect

Attaches a new aspect to the object


Parameters
newAspect - The aspect object to add.

Returns
None.

Examples
var asp = new WMSAspect(...); // Create the aspect
wms.addAspect(asp); // Attach it to the MapCanvas

Notes
newAspect must be initialized before calling this method. If the aspect added is the first to be added to the Canvas, it will automatically be selected and the WMSMapCanvas object will begin loading the map image for it. You can add any number of aspects, each with their own projection. However, avoid naming two aspects with the same name, as it could cause problems when selecting them.


changeAspect

Changes the current aspect to view another one


Parameters
aspectName - the name of the aspect to change to

Returns
A boolean, true if the operation is successful

Examples
wms.changeAspect("north");
// Will change to the aspect named "north"

Notes
If the aspect name is not found, false will be returned. Otherwise, the WMSMapCanvas will load the aspect specified. Note that if you specify the name of the current aspect, it will cause the view to be reset for that aspect.


changeDblClickMode

Changes the action that happens when a double-click is done on the Canvas


Parameters
newMode - A string for the new action to do

Returns
None.

Examples
wms.changeDblClickMode('ZOOMIN');
// Will change the Double Click mode to zoom in when double-
// clicked

Notes
The valid valuess for newMode are as follows:
  • ZOOMIN - Will cause the map to be zoomed in at the point
  • clicked
  • ZOOMOUT - Will cause the map to be zoomed out centered at the
  • point clicked
  • CENTER - Will cause the map to recenter at the point clicked
  • NONE - Nothing happens. (Default)
  • For the ZOOMIN and ZOOMOUT modes, the zoom factor is based on the value set by changeZoomFactor. By default, the zoom factor is 2. Note that for all modes, if the center point would cause the new map to be partly "out of bounds" the resulting map will actually be shifted to stay in bounds, so in those cases the point you click may not be the center of the new image.


    changeZoomFactor

    Changes the zoom factor used for double-click events


    Parameters
    newFactor - The new zoom factor to use

    Returns
    None.

    Examples
    wms.changeZoomFactor(3);
    // Will change the zoom factor to 3x

    Notes
    The zoom factor must be greater than one. Zoom outs simply use an inverted version of the current zoom factor. If this method is not called, the default value used is 2.


    zoom

    Applies a zoom to the current map.


    Parameters
    zoomtype - The type of zoom to implement
    param - Parameter object for certain zooms

    Returns
    None.

    Examples
    wms.zoom('in_center');
    // Will zoom in at the center of the image, using the current
    // Zoom factor

    Notes
    There are currently 3 valid values for zoomtype:
  • in_box - Zooms in based on a box. If param is null, it
  • will use the current XY box for the Canvas. If you supply your own, the param object should have fields x0,y0,x1,y1 corresponding to the upper left and lower right corners of the box. If the aspect-ratio of the box to zoom on does not match the aspect-ratio of the Canvas, the zoom will correspond to the bigger dimension. (IE, if the Canvas is square, and the box is a horizontal rectangle, the long sides of the rectangle will stay as they are, and the short sides will be expanded to make the zoom a square)
  • in_center - Zooms into the center of the image using the
  • current zoom factor. param is not used and will be ignored.
  • out_center - Zooms out centered on the current center of the
  • image, using the current zoom factor. param is not used and will be ignored.


    pan

    Pans the map.


    Parameters
    xdir - Horizontal shift mode
    ydir - Vertical shift mode

    Returns
    None.

    Examples
    wms.pan(1,-1);  // Shift the map down and to the right

    Notes
    For the xdir, -1 will pan the map left, +1 will pan the map right, and 0 will cause no horizontal pan. For ydir, -1 will pan the map down, +1 will pan the map up, and 0 will cause no vertical pan. The pan amount is equal to 75% of the current bounds in that dimension.


    loadWMSImage

    Causes the map image to be loaded from the Map Server


    Parameters
    None.

    Returns
    None.

    Examples
    wms.loadWMSImage();  // reloads the map image

    Notes
    You will rarely need to call this manually, as the zooms and pans and aspect changes will automatically do this. It is a public method mostly due to JavaScript scoping issues. However, you can manually call it to reset the image if necessary. It will use current values; it will not "reset" the map to it's default state. To do that, use changeAspect and pass in the current aspect name.


    setXYFromRSPolgyon

    Sets the XY box based on an RS Polygon.


    Parameters
    polygon - An array in (r0,s0,r1,s1,...,r0,s0) format

    Returns
    False if there is no aspect set, otherwise it returns the result of an eventual call to setXYFromLatLonPolygon.

    Examples
    wms.setXYFromRSPolygon(new Array(-10,10,-10,-5,5,-5,5,10,-10,10));
    // sets the XY box based on the coordinates set

    Notes
    The results of this call depend on the projection of the current view, as the r/s coordinates are based on the current aspect.


    getMoreMousePosInfo

    Fills in map R/S information to the Mouse Position listener information


    Parameters
    fullpoint - The information object being used for the listener

    Returns
    None.

    Examples
    this.getMoreMousePosInfo(infopoint);
    // Called within the class to pass more point info

    Notes
    You should never need to call this manually. It is public because of the JavaScript scoping limitations with inheritance. The WMSMapCanvas object uses this to add r and s information to the mouse point, so you can see not only x/y and lat/lon, but the map coordinates (especially if you are using a tile grid, for example). The fields "r" and "s" will be added to fullpoint.


    getMoreBoxInfo

    Fills in R/S information to the box returned by Row/Col listeners


    Parameters
    boxinfo - The information object being used for the listener

    Returns
    None.

    Examples
    this.getMoreBoxInfo(infobox);
    // Called within the class to pass more box info

    Notes
    You should never need to call this manually. It is public because of the JavaScript scoping limitations with inheritance. The WMSMapCanvas object uses this to add r and s information to the info box, you can see the map coordinates (especially if you are using a tile grid, for example). The "ul", "ll", "lr", and "ur" fields in the box info object already will be extended to have two additional fields each: "r" and "s". (IE, boxinfo.ul.r, or boxinfo.lr.s). Thus, there will be r and s values for each corner of the row/col box.


    adjustGrid

    Adjusts the current grid based on the bounds passed in.


    Parameters
    bnds - An object describing the new bounds

    Returns
    None.

    Examples
    this.adjustGrid(newBnds); // will adjust the grid

    Notes
    You should never need to call this manually. It is used internally, and is public only because of scoping issues in JavaScript. The bnds object should have minx,miny,maxx, and maxy fields. The new grid will be based on the current aspect.