Project

General

Profile

1
/*
2
Author:       Tom Kralidis
3
License:      LGPL as per: http://www.gnu.org/copyleft/lesser.html
4

    
5
$Id: Locations.js 3821 2008-02-01 13:58:30Z ahocevar $
6
*/
7

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

    
11
/**
12
 * Widget to display predefined locations (as per schema at lib/model/schemas/locations.xsd)
13
 * into a HTML select box. Changing a location will set the AOI of the targetModel.
14
 * TBD: projection coordinate conversion still to be implemented.
15
 * @constructor
16
 * @base WidgetBaseXSL
17
 * @param widgetNode This widget's object node from the configuration document.
18
 * @param model The model that this widget is a view of.
19
 */
20

    
21

    
22
function Locations(widgetNode, model) {
23
  WidgetBaseXSL.apply(this,new Array(widgetNode, model));
24

    
25
  /**
26
   * Change the AOI coordinates from select box choice of prefined locations
27
   * @param bbox the bbox value of the location keyword chosen
28
   * @param targetModel the model on which to set the AOI
29
   * @param srsName srs of the bbox
30
   */
31
  this.setAoi = function(bbox, targetModel, srsName) {
32
    var srsTokens = srsName.split(/[:#]/);
33
    srsName = 'EPSG:'+srsTokens[srsTokens.length-1];
34
    if (!srsName) {
35
      srsName = 'EPSG:4326';
36
    }
37
    var proj = new OpenLayers.Projection(srsName);
38
    var bboxArray = new Array();
39
    bboxArray     = bbox.split(",");
40
    var ptUL=new OpenLayers.Geometry.Point(parseFloat(bboxArray[0]),parseFloat(bboxArray[3]));
41
    var ptLR=new OpenLayers.Geometry.Point(parseFloat(bboxArray[2]),parseFloat(bboxArray[1]));
42
    ptUL.transform(proj,this.targetModel.proj);
43
    ptLR.transform(proj,this.targetModel.proj);
44
    var ul = new Array(ptUL.x,ptUL.y);
45
    var lr = new Array(ptLR.x,ptLR.y);   
46
    this.targetModel.setParam("aoi",new Array(ul,lr));
47

    
48
    //convert this.model XY to latlong
49
    //convert latlong to targetmodel XY
50
    this.targetModel.map.zoomToExtent(new OpenLayers.Bounds(ul[0],lr[1],lr[0],ul[1]));
51
  }
52
}
(71-71/145)