1
|
/*
|
2
|
Author: Cameron Shorter cameronAtshorter.net
|
3
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4
|
|
5
|
$Id: CollectionList.js 3888 2008-02-27 18:25:45Z ahocevar $
|
6
|
*/
|
7
|
|
8
|
// Ensure this object's dependancies are loaded.
|
9
|
mapbuilder.loadScript(baseDir+"/widget/WidgetBaseXSL.js");
|
10
|
|
11
|
/**
|
12
|
* A widget to display a list of context docs to pick from. This is a view of
|
13
|
* a Context Collection as specified in the OGC Context specification.
|
14
|
* The default xsl stylesheet for this widget also uses the switchMap
|
15
|
* function, which allows to switch to a different map context.
|
16
|
* @constructor
|
17
|
* @base WidgetBaseXSL
|
18
|
* @param widgetNode The widget's XML object node from the configuration document.
|
19
|
* @param model The model object that this widget belongs to.
|
20
|
*/
|
21
|
|
22
|
function CollectionList(widgetNode, model) {
|
23
|
WidgetBaseXSL.apply(this,new Array(widgetNode, model));
|
24
|
|
25
|
/**
|
26
|
* Switch to another map context, keeping the current extent.
|
27
|
* @param objRef this widget
|
28
|
* @modelUrl the URL of the context we want to switch to.
|
29
|
*/
|
30
|
this.switchMap = function(objRef, modelUrl) {
|
31
|
// save the current extent
|
32
|
objRef.extent = objRef.targetModel.map.getExtent();
|
33
|
objRef.srs = objRef.targetModel.getSRS();
|
34
|
objRef.scale = objRef.targetModel.map.getScale();
|
35
|
|
36
|
objRef.targetModel.addListener( "loadModel", objRef.setExtent, objRef );
|
37
|
config.loadModel( objRef.targetModel.id, modelUrl );
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
* Sets the extent of the map that we just switched to.
|
42
|
* Called when the map is reloaded with the new context.
|
43
|
* @param objRef this widget
|
44
|
*/
|
45
|
this.setExtent = function (objRef) {
|
46
|
objRef.targetModel.removeListener( "loadModel", objRef.setExtent, objRef );
|
47
|
|
48
|
var bbox = objRef.extent.toBBOX().split(/,/);
|
49
|
if (objRef.targetModel.getSRS().toUpperCase() != objRef.srs.toUpperCase()) {
|
50
|
var targetProj = new OpenLayers.Projection(objRef.targetModel.getSRS());
|
51
|
var srcProj = new OpenLayers.Projection(objRef.srs);
|
52
|
var ptLL=new OpenLayers.Geometry.Point(bbox[0],bbox[1]);
|
53
|
var ptUR=new OpenLayers.Geometry.Point(bbox[2],bbox[3]);
|
54
|
ptLL.transform(srcProj, targetProj);
|
55
|
ptUR.transform(srcProj, targetProj);
|
56
|
objRef.extent = new OpenLayers.Bounds(ptLL.x, ptLL.y, ptUR.x, ptUR.y);
|
57
|
}
|
58
|
if (objRef.targetModel.map.getExtent().containsBounds(objRef.extent, false, false)) {
|
59
|
objRef.targetModel.map.zoomToExtent(objRef.extent);
|
60
|
if (!objRef.targetModel.map.fractionalZoom && objRef.targetModel.map.getScale() > objRef.scale) {
|
61
|
objRef.targetModel.map.zoomIn();
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
}
|