1 |
3032
|
perry
|
/*
|
2 |
|
|
Author: Cameron Shorter cameronATshorter.net
|
3 |
|
|
License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
|
4 |
|
|
|
5 |
|
|
$Id$
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
// Ensure this object's dependancies are loaded.
|
9 |
|
|
mapbuilder.loadScript(baseDir+"/model/Proj.js");
|
10 |
|
|
mapbuilder.loadScript(baseDir+"/widget/MapContainerBase.js");
|
11 |
|
|
mapbuilder.loadScript(baseDir+"/util/wz_jsgraphics/wz_jsgraphics.js");
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Render GML into HTML.
|
15 |
|
|
* Calls GmlCoordinates2Coord.xsl to convert GML to a simpler form.
|
16 |
|
|
* Calls GmlRendererWZ.xsl to convert GML to wz_jsgraphics graphic function
|
17 |
|
|
* calls.
|
18 |
|
|
* this.targetModel references the context model with
|
19 |
|
|
* width/height attributes.
|
20 |
|
|
* @constructor
|
21 |
|
|
* @base MapContainerBase
|
22 |
|
|
* @param widgetNode The widget's XML object node from the configuration document.
|
23 |
|
|
* @param model The model object that this widget belongs to.
|
24 |
|
|
*/
|
25 |
|
|
function GmlRendererWZ(widgetNode, model) {
|
26 |
|
|
WidgetBase.apply(this,new Array(widgetNode, model));
|
27 |
|
|
|
28 |
|
|
// Set this.stylesheet
|
29 |
|
|
// Defaults to "widget/<widgetName>.xsl" if not defined in config file.
|
30 |
|
|
var styleNode = widgetNode.selectSingleNode("mb:stylesheet");
|
31 |
|
|
if (styleNode ) {
|
32 |
|
|
this.stylesheet = new XslProcessor(styleNode.firstChild.nodeValue,model.namespace);
|
33 |
|
|
} else {
|
34 |
|
|
this.stylesheet = new XslProcessor(baseDir+"/widget/"+widgetNode.nodeName+".xsl",model.namespace);
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
this.paint = function(objRef) {
|
38 |
|
|
if (objRef.model.doc && objRef.node && objRef.containerModel && objRef.containerModel.doc) {
|
39 |
|
|
objRef.stylesheet.setParameter("modelUrl", objRef.model.url);
|
40 |
|
|
|
41 |
|
|
//if (objRef.debug) alert("source:"+Sarissa.serialize(objRef.model.doc));
|
42 |
|
|
objRef.resultDoc = objRef.model.doc; // resultDoc sometimes modified by prePaint()
|
43 |
|
|
objRef.prePaint(objRef);
|
44 |
|
|
|
45 |
|
|
//confirm inputs
|
46 |
|
|
if (objRef.debug) alert("prepaint:"+Sarissa.serialize(objRef.resultDoc));
|
47 |
|
|
if (objRef.debug) alert("stylesheet:"+Sarissa.serialize(objRef.stylesheet.xslDom));
|
48 |
|
|
|
49 |
|
|
//set to output to a temporary node
|
50 |
|
|
//hack to get by doc parsing problem in IE
|
51 |
|
|
//the firstChild of tempNode will be the root element output by the stylesheet
|
52 |
|
|
var outputNode = document.getElementById( objRef.outputNodeId );
|
53 |
|
|
var tempNode = document.createElement("DIV");
|
54 |
|
|
|
55 |
|
|
tempNode.style.position="absolute";
|
56 |
|
|
tempNode.style.top=0;
|
57 |
|
|
tempNode.style.left=0;
|
58 |
|
|
tempNode.style.zindex=300;
|
59 |
|
|
tempNode.setAttribute("id", objRef.outputNodeId);
|
60 |
|
|
//look for this widgets output and replace if found,
|
61 |
|
|
//otherwise append it
|
62 |
|
|
if (outputNode) {
|
63 |
|
|
objRef.node.replaceChild(tempNode,outputNode);
|
64 |
|
|
} else {
|
65 |
|
|
objRef.node.appendChild(tempNode);
|
66 |
|
|
}
|
67 |
|
|
jsNode = objRef.stylesheet.transformNodeToObject(objRef.resultDoc);
|
68 |
|
|
js=jsNode.selectSingleNode("js").firstChild.nodeValue;
|
69 |
|
|
if (objRef.debug) alert("javascript eval:"+js);
|
70 |
|
|
objRef.model.setParam("modelStatus","rendering");
|
71 |
|
|
eval(js);
|
72 |
|
|
|
73 |
|
|
objRef.postPaint(objRef);
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
this.model.addListener("refresh",this.paint, this);
|
77 |
|
|
|
78 |
|
|
MapContainerBase.apply(this,new Array(widgetNode, model));
|
79 |
|
|
|
80 |
|
|
// Set stylesheet parameters for all the child nodes from the config file
|
81 |
|
|
for (var j=0;j<widgetNode.childNodes.length;j++) {
|
82 |
|
|
if (widgetNode.childNodes[j].firstChild
|
83 |
|
|
&& widgetNode.childNodes[j].firstChild.nodeValue)
|
84 |
|
|
{
|
85 |
|
|
this.stylesheet.setParameter(
|
86 |
|
|
widgetNode.childNodes[j].nodeName,
|
87 |
|
|
widgetNode.childNodes[j].firstChild.nodeValue);
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
// Set widget text values as parameters
|
92 |
|
|
if (config.widgetText) {
|
93 |
|
|
var textNodeXpath = "/mb:WidgetText/mb:widgets/mb:" + widgetNode.nodeName;
|
94 |
|
|
var textParams = config.widgetText.selectNodes(textNodeXpath+"/*");
|
95 |
|
|
for (var j=0;j<textParams.length;j++) {
|
96 |
|
|
this.stylesheet.setParameter(textParams[j].nodeName,textParams[j].firstChild.nodeValue);
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
//all stylesheets will have these properties available
|
101 |
|
|
this.stylesheet.setParameter("modelId", this.model.id );
|
102 |
|
|
this.stylesheet.setParameter("modelTitle", this.model.title );
|
103 |
|
|
this.stylesheet.setParameter("widgetId", this.id );
|
104 |
|
|
this.stylesheet.setParameter("skinDir", config.skinDir );
|
105 |
|
|
this.stylesheet.setParameter("lang", config.lang );
|
106 |
|
|
|
107 |
|
|
/** Xsl to convert GML Coordinates to Coords. */
|
108 |
|
|
this.coordXsl=new XslProcessor(baseDir+"/widget/GmlCooordinates2Coord.xsl");
|
109 |
|
|
|
110 |
|
|
/**
|
111 |
|
|
* Set up XSL params and convert Gml Coordinate nodes to Gml Coords so
|
112 |
|
|
* that they are easier to process by XSL.
|
113 |
|
|
* @param objRef Pointer to this object.
|
114 |
|
|
*/
|
115 |
|
|
this.prePaint = function(objRef) {
|
116 |
|
|
objRef.model.setParam("modelStatus","preparing coordinates");
|
117 |
|
|
objRef.stylesheet.setParameter("width", objRef.containerModel.getWindowWidth() );
|
118 |
|
|
objRef.stylesheet.setParameter("height", objRef.containerModel.getWindowHeight() );
|
119 |
|
|
bBox=objRef.containerModel.getBoundingBox();
|
120 |
|
|
objRef.stylesheet.setParameter("bBoxMinX", bBox[0] );
|
121 |
|
|
objRef.stylesheet.setParameter("bBoxMinY", bBox[1] );
|
122 |
|
|
objRef.stylesheet.setParameter("bBoxMaxX", bBox[2] );
|
123 |
|
|
objRef.stylesheet.setParameter("bBoxMaxY", bBox[3] );
|
124 |
|
|
objRef.stylesheet.setParameter("color", "#FF0000" );
|
125 |
|
|
|
126 |
|
|
objRef.resultDoc = objRef.coordXsl.transformNodeToObject(objRef.resultDoc);
|
127 |
|
|
|
128 |
|
|
// Force refresh of the wz_jsgraphics handle when the widget's node
|
129 |
|
|
// has been refreshed.
|
130 |
|
|
if (!document.getElementById(objRef.outputNodeId)){
|
131 |
|
|
//objRef.jg=null;
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
/**
|
136 |
|
|
* Called when the context's hidden attribute changes.
|
137 |
|
|
* @param objRef This object.
|
138 |
|
|
* @param layerName The name of the layer that was toggled.
|
139 |
|
|
*/
|
140 |
|
|
this.hiddenListener=function(objRef, layerName){
|
141 |
|
|
var vis="visible";
|
142 |
|
|
if(objRef.model.getHidden(layerName)) {
|
143 |
|
|
vis="hidden";
|
144 |
|
|
}
|
145 |
|
|
var outputNode = document.getElementById(objRef.outputNodeId)
|
146 |
|
|
for (var i=0; i< outputNode.childNodes.length; ++i) {
|
147 |
|
|
outputNode.childNodes[i].style.visibility=vis;
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
this.model.addListener("hidden",this.hiddenListener,this);
|
151 |
|
|
|
152 |
|
|
}
|