Project

General

Profile

1
/*
2
Author: imke doerge AT geodan.nl
3
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
4
$Id: ShowDistance.js 3242 2007-09-11 11:15:21Z gjvoosten $
5
*/
6

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

    
10
/**
11
 * Widget to display the measured distance when it measurement is enabled.
12
 *
13
 * @constructor
14
 * @base WidgetBaseXSL
15
 * @param widgetNode This widget's object node from the configuration document.
16
 * @param model The model that this widget is a view of.
17
 */
18

    
19
function ShowDistance(widgetNode, model) {
20
  WidgetBaseXSL.apply(this,new Array(widgetNode, model));
21
   
22
	// outputs the totalDistance value to the form element
23
	this.showDistance = function(objRef) {
24
		var distForm = document.getElementById(objRef.formName);   
25
		var totalDistance = objRef.model.values.showDistance;
26
		if (totalDistance == null) {
27
		  // hide result form
28
		  objRef.getNode().style.display = 'none';
29
		} else {
30
		  objRef.getNode().style.display = '';
31
		  // fill new distance value into form
32
  		if (totalDistance > 1000.000) { // >1000m = 1.000km
33
        if (totalDistance > 1000000.000) outputDistance = Math.round(totalDistance/1000)+"  km"; // >1000km
34
        else outputDistance = Math.round(totalDistance/100)/10+"  km";
35
      }
36
      else if (totalDistance > 0) { outputDistance = Math.round(totalDistance)+"  m"; }
37
      else outputDistance = '';
38
      if (distForm) {
39
        distForm.distance.value = outputDistance;
40
      }
41
		}
42
	}
43

    
44
	//add a showDistance Listener to the modal
45
	this.model.addListener("showDistance", this.showDistance, this);
46

    
47
  //set some properties for the form output
48
	this.formName = "ShowDistance_" + mbIds.getId();
49
	this.stylesheet.setParameter("formName", this.formName);  
50
}    
(116-116/145)