NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/cwcjsapi/cwcjsapi.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ZoomIn Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: cwcjsapi.widget.php,v 1.6 2005/05/16 11:46:15 bartvde Exp $
7  * @purpose     Zoom In Widget class
8  * @author      DM Solutions Group (assefa@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2002, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29
30 class CWCJSAPI extends CWCWidget
31 {
32
33     var $mbDebug = false;
34
35     function CWCJSAPI()
36     {
37         parent::CWCWidget();
38
39         $this->mnPriority = PRIORITY_MAXIMUM;
40
41         $this->maAttributes["DEBUG"] = new BooleanAttribute( "DEBUG", false );
42
43         $this->szWidgetDescription = <<<EOT
44 The CWCJSAPI Widget provides a javascript API to the CWC core architecture.
45 This provides an application that runs almost entirely on the client side,
46 with very few 'submits' of the page.  It also provides the application
47 developer with a javascript API to access and change the state of the Context.
48 EOT;
49         $this->mnMaturityLevel = MATURITY_ALPHA;
50
51     }
52
53     function InitDefaults()
54     {
55         parent::InitDefaults();
56         if (isset($this->maParams["DEBUG"]))
57         {
58             $this->mbDebug = (strcasecmp($this->maParams["DEBUG"], "true") == 0) ? true : false;
59         }
60
61     }
62
63     /**
64      * GetJavascriptFunctions
65      *
66      */
67     function GetJavascriptFunctions()
68     {
69         $poMap = $this->moMapObject->oMap;
70         if (!is_object( $poMap ) )
71             return array();
72         $dfMinX = $poMap->extent->minx;
73         $dfMinY = $poMap->extent->miny;
74         $dfMaxX = $poMap->extent->maxx;
75         $dfMaxY = $poMap->extent->maxy;
76         $nWidth = $poMap->width;
77         $nHeight = $poMap->height;
78         $dfScale = $poMap->scale;
79         $dfCellSize = $poMap->cellsize;
80         $dfResolution = $poMap->resolution;
81         $nUnits = $poMap->units;
82
83         if (is_object($poMap))
84             $szProj = $poMap->getProjection();
85         else
86             $szProj = "init=EPSG:None";
87         $szProj = substr( $szProj, 5 );
88
89
90         $aReturn = array();
91
92     $szJsFunctionName = "CWCJSAPIGetObject";
93
94     $szFunction = "function CWCJSAPIGetObject()\n";
95     $szFunction .= <<<EOT
96 {
97   return gpoCWCJSAPI;
98 }
99 EOT;
100     $aReturn[$szJsFunctionName] = $szFunction;
101
102
103     $szJsFunctionName = "CWCJSAPICreateLayer";
104     $szFunction = <<<EOT
105 /**
106  * {$szJsFunctionName}
107  * called to create a dynamic layer
108  */
109 function {$szJsFunctionName}(containerName)
110 {
111     var layer ;
112     var str;
113     var left = 0;
114     var right = 0;
115     var width = 10;
116     var height = 10;
117     var visible = 0;
118     var bNetscape4 = 0;
119     var bNetscape6 = 0;
120     var bIE = 0;
121
122
123     if (navigator.appName == "Netscape")
124     {
125         if (navigator.appVersion[0] <= 4)
126         {
127             bNetscape4 = 1;
128         }
129         else
130         {
131             bNetscape6 =1;
132         }
133     }
134     else if (navigator.appName == "Microsoft Internet Explorer")
135     {
136         bIE = 1;
137     }
138
139
140     if (bNetscape4)
141     {
142 /* ==================================================================== */
143 /*      For netscape 4 the Layer is created in the cwcjsapi :           */
144 /*      when CWCGetDocumentObject() function is called the first        */
145 /*      time. Seeems to have a problem when created beforehand.         */
146 /* ==================================================================== */
147         //container = new Layer(100);
148
149         //container.name = containerName;
150         //container.visibility = 'hide';
151         //container.visibility = 'show';
152         // container.resizeTo(100,100);
153         //container.document = '';
154         //container.src = '';
155         //container.clip.width = 100;
156         //container.clip.height = 100;
157     }
158     else if (bIE)
159     {
160         document.body.insertAdjacentHTML( "afterBegin", '<span id="' + containerName + '"></span>' );
161       var span = document.all(containerName );
162       var html = '<iframe name="' + "frame_" + containerName + '" src""></iframe>';
163       span.innerHTML = html;
164       span.style.display = 'none';
165       container = window.frames[ "frame_" + containerName ];
166     }
167     else if (bNetscape6)
168     {
169         var span = document.createElement('SPAN');
170         span.id = containerName;
171         document.body.appendChild( span );
172         var iframe = document.createElement('IFRAME');
173         iframe.name = "frame_"+containerName;
174         span.appendChild( iframe );
175         container = iframe;
176     }
177     return container;
178 }
179 EOT;
180
181     $aReturn[$szJsFunctionName] = $szFunction;
182
183
184     $session_id = session_id();
185
186     //arrays contains the infos on the layers.
187     $szLayerInfo="";
188     for ($i=0; $i<$poMap->numlayers; $i++)
189     {
190       $poLayer = $poMap->getlayer($i);
191       if ($poLayer->connectiontype == MS_WMS)
192         $szLayerInfo .="aLayername[".$i."] = '" .  $poLayer->getMetaData("wms_name") . "';\n";
193       else
194         $szLayerInfo .="aLayername[".$i."] = '" .  $poLayer->name . "';\n";
195
196       $szLayerInfo .="aLayerindex[".$i."] = '" .  $poLayer->index . "';\n";
197       $szLayerInfo .="aLayerstatus[".$i."] = '" .  $poLayer->status . "';\n";
198       $szLayerInfo .="aLayertype[".$i."] = '" .  $poLayer->type . "';\n";
199
200
201       if ($poLayer->connectiontype == MS_WMS &&
202           strlen($poLayer->getMetaData("wms_title")) > 0)
203         $szLayerInfo .="aLayertitle[".$i."] = \"" .  $poLayer->getMetaData("wms_title") . "\";\n";
204       else
205         $szLayerInfo .="aLayertitle[".$i."] = \"" .  $poLayer->name . "\";\n";
206
207       $szLayerInfo .="aLayerconnection[".$i."] = '" .  $poLayer->connection . "';\n";
208       $szLayerInfo .="aLayeronlineresource[".$i."] = '" . $poLayer->getMetaData("wms_onlineresource")  . "';\n";
209       $szLayerInfo .="aLayersrs[".$i."] = '" .  $poLayer->getMetaData("wms_srs") . "';\n";
210       $szLayerInfo .="aLayerversion[".$i."] = '" .  $poLayer->getMetaData("wms_server_version") . "';\n";
211       $szLayerInfo .="aLayerformat[".$i."] = '" .  $poLayer->getMetaData("wms_format") . "';\n";
212       $szLayerInfo .="aLayerformatlist[".$i."] = '" .  $poLayer->getMetaData("wms_formatlist") . "';\n";
213
214       $szLayerInfo .="aLayerconnection[".$i."] = '" .  $poLayer->connection . "';\n";
215       $szLayerInfo .="aLayerconnectiontype[".$i."] = '" .  $poLayer->connectiontype . "';\n";
216       $szLayerInfo .="aLayeronlineresource[".$i."] = '" . $poLayer->getMetaData("wms_onlineresource")  . "';\n";
217       $szLayerInfo .="aLayersrs[".$i."] = '" .  $poLayer->getMetaData("wms_srs") . "';\n";
218       $szLayerInfo .="aLayerversion[".$i."] = '" .  $poLayer->getMetaData("wms_server_version") . "';\n";
219       $szLayerInfo .="aLayerformat[".$i."] = '" .  $poLayer->getMetaData("wms_format") . "';\n";
220       $szLayerInfo .="aLayerformatlist[".$i."] = '" .  $poLayer->getMetaData("wms_formatlist") . "';\n";
221
222       $szLayerInfo .="aLayerstyle[".$i."] = '" .  $poLayer->getMetaData("wms_style") . "';\n";
223       $szLayerInfo .="aLayerstylelist[".$i."] = '" .  $poLayer->getMetaData("wms_stylelist") . "';\n";
224     }
225
226     $aLayerOder = $poMap->getlayersdrawingorder();
227     $szLayerDrawingOrder = implode(",", $aLayerOder);
228     $szCurrentLanguage = strtoupper($_SESSION['gszCurrentLanguage']);
229
230     $szJsFunctionName = "CWCJSAPIWInit";
231     $bDebug = ($this->mbDebug) ? 1 : 0;
232     $szFunction = <<<EOT
233 /**
234  * {$szJsFunctionName}
235  * called to initialize the JS API widget
236  */
237 function {$szJsFunctionName}()
238 {
239     aLayername = new Array({$poMap->numlayers});
240     aLayerindex = new Array({$poMap->numlayers});
241     aLayerstatus = new Array({$poMap->numlayers});
242     aLayertitle = new Array({$poMap->numlayers});
243     aLayertype = new Array({$poMap->numlayers});
244     aLayerconnection = new Array({$poMap->numlayers});
245     aLayerconnectiontype = new Array({$poMap->numlayers});
246     aLayeronlineresource = new Array({$poMap->numlayers});
247     aLayersrs = new Array({$poMap->numlayers});
248     aLayerversion = new Array({$poMap->numlayers});
249     aLayerformat = new Array({$poMap->numlayers});
250     aLayerformatlist = new Array({$poMap->numlayers});
251     aLayerstyle = new Array({$poMap->numlayers});
252     aLayerstylelist = new Array({$poMap->numlayers});
253
254     //create a CWC JS API class
255     goCWCJSAPI = new CWCApplication();
256     goCWCJSAPI.szURL = "{$_SESSION["gszCoreWebPath"]}";
257
258     //init map elements
259     goCWCJSAPI.oMap.minx = {$dfMinX};
260     goCWCJSAPI.oMap.miny = {$dfMinY};
261     goCWCJSAPI.oMap.maxx = {$dfMaxX};
262     goCWCJSAPI.oMap.maxy = {$dfMaxY};
263
264     goCWCJSAPI.oMap.width = {$nWidth};
265     goCWCJSAPI.oMap.height = {$nHeight};
266
267     goCWCJSAPI.oMap.scale = {$dfScale};
268     goCWCJSAPI.oMap.cellsize = {$dfCellSize};
269     goCWCJSAPI.oMap.resolution = {$dfResolution};
270     goCWCJSAPI.oMap.units = {$nUnits};
271
272     goCWCJSAPI.oMap.projection = '{$szProj}';
273
274     goCWCJSAPI.oMap.layerdrawingorder='{$szLayerDrawingOrder}';
275
276 /* -------------------------------------------------------------------- */
277 /*      Add properties in the application object.                       */
278 /* -------------------------------------------------------------------- */
279     goCWCJSAPI.aProperties = new Array(11);
280
281     //add all the layers in the map file.
282
283     {$szLayerInfo};
284     for (i=0; i<{$poMap->numlayers}; i++)
285     {
286         goCWCJSAPI.oMap.AddLayer(aLayername[i]);
287         goCWCJSAPI.oMap.aLayers[i].index = aLayerindex[i];
288         goCWCJSAPI.oMap.aLayers[i].status = aLayerstatus[i];
289         goCWCJSAPI.oMap.aLayers[i].type = aLayertype[i];
290         goCWCJSAPI.oMap.aLayers[i].title = aLayertitle[i];
291         goCWCJSAPI.oMap.aLayers[i].connection = aLayerconnection[i];
292         goCWCJSAPI.oMap.aLayers[i].connectiontype = aLayerconnectiontype[i];
293         goCWCJSAPI.oMap.aLayers[i].onlineresource = aLayeronlineresource[i];
294         goCWCJSAPI.oMap.aLayers[i].srs = aLayersrs[i];
295         goCWCJSAPI.oMap.aLayers[i].version = aLayerversion[i];
296         goCWCJSAPI.oMap.aLayers[i].format = aLayerformat[i];
297         goCWCJSAPI.oMap.aLayers[i].formatlist = aLayerformatlist[i];
298         goCWCJSAPI.oMap.aLayers[i].style = aLayerstyle[i];
299         goCWCJSAPI.oMap.aLayers[i].stylelist = aLayerstylelist[i];
300     }
301     //alert(goCWCJSAPI.oMap.numlayers);
302     //alert(goCWCJSAPI.oMap.aLayers[0].name);
303
304
305     //create htnml layer that will be used to communicate with server
306
307
308 /* ==================================================================== */
309 /*      For Netscape 4, the container (which is a DHTML Layer will      */
310 /*      be created the first time that the GetDocuemntObject            */
311 /*      function is called.                                             */
312 /* ==================================================================== */
313     if (navigator.appName != "Netscape" ||
314         navigator.appVersion[0] > 4)
315     {
316         oContainer = CWCJSAPICreateLayer("CWCJSAPILayer");
317         goCWCJSAPI.szContainerName = "CWCJSAPILayer";
318         goCWCJSAPI.oContainer = oContainer;
319         goCWCJSAPI.ContainerSetVisibility({$bDebug});
320     }
321     if ({$bDebug})
322     {
323         goCWCJSAPI.bDebug = true;
324     }
325
326     //szURL = "" + window.location;
327     //szURL = szURL.substr( 0, szURL.lastIndexOf("?") + 1 );
328     //szURL = szURL.substr( 0, szURL.lastIndexOf("/" ) + 1 );
329     //goCWCJSAPI.szURL = szURL;
330
331     //set the session id
332     goCWCJSAPI.sid = "{$session_id}";
333
334 /* -------------------------------------------------------------------- */
335 /*      for netscape 4 the setlanguage  will be called in               */
336 /*      CWCGetDocumentObject the first time the function is called.     */
337 /* -------------------------------------------------------------------- */
338     if (navigator.appName != "Netscape" ||
339         navigator.appVersion[0] > 4)
340     {
341         goCWCJSAPI.oMLT.SetLanguage("{$szCurrentLanguage}");
342     }
343
344     goCWCJSAPI.szLanguage = "{$szCurrentLanguage}";
345 }
346 EOT;
347
348     $aReturn[$szJsFunctionName] = $szFunction;
349
350
351
352
353     return $aReturn;
354 }
355
356
357
358     /**
359      * GetJavascriptIncludeFunctions.
360      *
361      */
362     function GetJavascriptIncludeFunctions()
363     {
364         $poMap = $this->moMapObject->oMap;
365
366         $aReturn = array();
367
368         $szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/js/cwcjsapi.js";
369         $szInclude = "<script language=\"JavaScript\" src=\"".$_SESSION["gszCoreWebPath"]."/widgets/js/cwcjsapi.js\" type=\"text/javascript\"></script>";
370         $aReturn[$szJsIncludeName] = $szInclude;
371
372          return $aReturn;
373     }
374
375
376     /**
377      * GetJavascriptVariables
378      *
379      */
380     function GetJavascriptVariables()
381     {
382         $aReturn = array();
383
384         $szVariable = "goCWCJSAPI";
385         $szValue = " var $szVariable = '';\n";
386         $aReturn[$szVariable] = $szValue;
387
388         return $aReturn;
389     }
390
391     /**
392      * GetJavascriptInitFunctions
393      *
394      * Functions to be called at the end of the load.
395      */
396     function GetJavascriptInitFunctions()
397     {
398         $aReturn = array();
399
400         $szJsFunctionName = "CWCJSAPIWInit";
401         $szFunction = "$szJsFunctionName();\n";
402         $aReturn[$szJsFunctionName] = $szFunction;
403
404         return $aReturn;
405     }
406
407
408     /**
409      * GetHTMLHiddenVariables
410      *
411      * Return HTML hidden variables.
412      *
413      * @return HTML hidden variables.
414      */
415     function GetHTMLHiddenVariables()
416     {
417          $aReturn = array();
418         //used with load context. Needed to add this in case the
419         //UploadContext widget is not in the template.
420         $szVariable = "CONTEXT";
421         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
422         $aReturn[$szVariable] = $szValue;
423
424         return $aReturn;
425     }
426
427 }
428 //end of class CWCJSAPIWidget
429
430 if ((function_exists( "RegisterWidget" )))
431     RegisterWidget( "CWCJSAPI", "CWCJSAPI" );
432 ?>
Note: See TracBrowser for help on using the browser.