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

root/Chameleon/trunk/Chameleon/KeyMapDHTML/KeyMapDHTML.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3 * DHTML KeyMap
4 *
5 * @project     CWC2
6 * @revision    $Id:
7 * @purpose     DHTML KeyMap
8 * @author      DM Solutions Group (sfournier@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 include_once(dirname(__FILE__)."/../NavTool.php");
30 include_once(dirname(__FILE__)."/../geomath.php");
31 /**
32 * KeyMapDHTMLWidget provides a DHTML enabled mapping interface and the javascript
33 * functions for doing javascript-based navigation.
34 */
35 class KeyMapDHTML extends NavTool
36 {
37     var $msAnchorName = "keymapanchor";
38     var $msMapImageName = "keymapimage";
39     var $mszMarqueeColor = "RED";
40     var $mnMarqueeWidth = 1;
41     var $mszMarqueeImageHorizontal = "images/a_pixel.gif";
42     var $mszMarqueeImageVertical = "images/a_pixel.gif";
43     var $mszURL = "";
44     var $mbAllowResize = true;
45     var $mfMinScale = 1;
46     var $mfMaxScale = -1;
47
48     var $mnWidth = 100;
49     var $mnHeight = 100;
50     var $mszImage = "";
51     var $mdMinx = 0;
52     var $mdMiny = 0;
53     var $mdMaxx = 0;
54     var $mdMaxy = 0;
55     var $mszSRS = '';
56
57     var $mszAnchorName = "keyMapAnchor";
58     var $mszKeyMapImageName = "KeyMapImage";
59     var $mszKeyMapName = "";
60     var $mdfZoomMin = 4;
61     var $mszMode = "ZOOM";
62
63     function KeyMapDHTML()
64     {
65         // invoke constructor of parent
66         parent::NavTool();
67
68         $this->SetNavCommand("KEY_MAP_DHTML");
69
70         $this->SetUniqueId(md5(uniqid(rand())));
71
72         $this->moButton->mszAnchorName = $this->mszAnchorName;
73
74         $this->maAttributes["WIDTH"] = new IntegerAttribute( "WIDTH", false, 0 );
75         $this->maAttributes["HEIGHT"] = new IntegerAttribute( "HEIGHT", false, 0 );
76         $this->maAttributes["IMAGE"] = new StringAttribute( "IMAGE", false );
77         $this->maAttributes["COLOR"] = new RGBColorAttribute( "COLOR", false );
78         $this->maAttributes["OUTLINECOLOR"] = new RGBColorAttribute( "OUTLINECOLOR", false );
79         $this->maAttributes["MINX"] = new FloatAttribute( "MINX", false );
80         $this->maAttributes["MINY"] = new FloatAttribute( "MINY", false );
81         $this->maAttributes["MAXX"] = new FloatAttribute( "MAXX", false );
82         $this->maAttributes["MAXY"] = new FloatAttribute( "MAXY", false );
83         $this->maAttributes["SRS"] = new StringAttribute( "SRS", false );
84         $this->mszMarqueeImageHorizontal = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
85         $this->mszMarqueeImageVertical = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
86         $this->mnMaturityLevel = MATURITY_BETA;
87     }
88
89     function InitDefaults()
90     {
91         parent::InitDefaults();
92
93         if (!isset($_SESSION['KEYMAPDHTML_INIT']) || $_SESSION['KEYMAPDHTML_INIT'] != "1")
94         {
95
96             $oApp = GetChameleonApplication();
97
98             // set width
99             if (isset($this->maParams['WIDTH']))
100             {
101                 $this->moMapObject->oMap->reference->set( "width", $this->maParams['WIDTH'] );
102             }
103
104             // set height
105             if (isset($this->maParams['HEIGHT']))
106             {
107                 $this->moMapObject->oMap->reference->set( "height", $this->maParams['HEIGHT'] );
108             }
109
110             // set image
111             if (isset($this->maParams['IMAGE']))
112             {
113                 $szImage = $oApp->getRemoteFile( $this->maParams['IMAGE'] );
114                 $szImage = $oApp->findFile( $szImage );
115                 $this->moMapObject->oMap->reference->set( "image", $szImage );
116             }
117             else
118             {
119                 $szMapPath = realpath( $_SESSION['gszMapPath'] )."/";
120
121                 $szImage = $this->moMapObject->oMap->reference->image;
122
123                 $szImage = realpath($oApp->resolvePath2( $szImage, $szMapPath ));
124                 $this->moMapObject->oMap->reference->set( "image", $szImage );
125
126             }
127
128             // set extent
129             if (isset($this->maParams['MINX']) && isset($this->maParams['MINY']) &&
130             isset($this->maParams['MAXX']) && isset($this->maParams['MAXY']))
131             {
132                 $this->moMapObject->oMap->reference->extent->setextent( $this->maParams['MINX'],
133                 $this->maParams['MINY'],
134                 $this->maParams['MAXX'],
135                 $this->maParams['MAXY'] );
136             }
137         }
138
139         // intialize member variables
140         $this->mnWidth = $this->moMapObject->oMap->reference->width;
141         $this->mnHeight = $this->moMapObject->oMap->reference->height;
142         $this->mszImage = $this->moMapObject->oMap->reference->image;
143         $this->mdMinx = $this->moMapObject->oMap->reference->extent->minx;
144         $this->mdMiny = $this->moMapObject->oMap->reference->extent->miny;
145         $this->mdMaxx = $this->moMapObject->oMap->reference->extent->maxx;
146         $this->mdMaxy = $this->moMapObject->oMap->reference->extent->maxy;
147
148         if ($this->isVarSet( "MAP_ORIGINAL_PROJ" ))
149             $this->mszSRS = $this->getVar( "MAP_ORIGINAL_PROJ" );
150         elseif ($this->moMapObject->oMap->getmetadata( "original_projection" ) != "")
151             $this->mszSRS = $this->moMapObject->oMap->getmetadata( "original_projection" );
152         else
153             $this->mszSRS = $this->moMapObject->oMap->getprojection();
154        
155         //echo "keymapdhtml srs is ".$this->mszSRS."<BR>\n";
156         // Accept different format for SRS.
157         // only a number, we will add init=epsg:
158         // EPSG:XXXX will result in init=epsg:XXXX
159         // Or else a valid projection string.
160         if(isset($this->maParams['SRS']) && $this->maParams['SRS'] != "")
161         {
162             $szSRS = "";
163             $szSRS .= intval($this->maParams['SRS']);
164             if($szSRS == $this->maParams['SRS'])
165             {
166                 $this->mszSRS = "init=epsg:".$this->maParams['SRS'];
167             }
168             else if(strtoupper(substr($this->maParams['SRS'], 0, 5)) ==
169                     "EPSG:")
170             {
171                 $this->maParams['SRS'] = "init=epsg:".
172                     substr($this->maParams['SRS'], 5);
173             }
174             else
175             {
176                 $this->mszSRS = $this->maParams['SRS'];
177             }
178         }
179
180         $_SESSION['KEYMAPDHTML_INIT'] = "1";
181     }
182
183     /**
184     * handle changes coming from the URL.  In this case, we only want
185     * to verify that the map size is valid
186     */
187     function ParseURL()
188     {
189         parent::ParseURL();
190
191         $oMap = $this->moMapObject->oMap;
192
193         $szCmd = "";
194         if ($this->isVarSet("NAV_CMD"))
195         $szCmd = trim($this->getVar("NAV_CMD"));
196
197         if ($this->isVarSet('KEYMAP_DHTML_MODE'))
198         $this->mszMode = $this->getVar('KEYMAP_DHTML_MODE');
199
200         if ($szCmd != "" && $this->isVarSet("NAV_INPUT_COORDINATES") &&
201         $this->isVarSet("NAV_INPUT_TYPE") &&
202         $szCmd == "KEYMAP_DHTML")
203         {
204             $szMapProj = $oMap->getProjection();
205             //adjust extents/projection first ...
206             $szInputCoords = $this->getVar("NAV_INPUT_COORDINATES");
207             $szInputType = $this->getVar("NAV_INPUT_TYPE");
208             $aPixMin = false;
209             $aPixMax = false;
210             if ($szInputType == "RECTANGLE")
211             {
212                 $aPixPos = explode(";", $szInputCoords);
213                 $aPixMin = explode(",", $aPixPos[0]);
214                 $aPixMax = explode(",", $aPixPos[1]);
215                 // adjust ratio of height & width to match main map
216                 if ($this->mszMode == "ZOOM")
217                 {
218                     $this->adjustBBox( $aPixMin[0], $aPixMin[1], $aPixMax[0], $aPixMax[1],
219                                    $oMap->width, $oMap->height );
220                     //check if the rectangle is bigger than the minmum size allowed.  */
221                     if (abs($aPixMax[0] - $aPixMin[0]) < $this->mdfZoomMin &&
222                         abs($aPixMax[1] - $aPixMin[1]) < $this->mdfZoomMin)
223                     {
224                         $aPixMax = false;
225                         $szInputType = 'POINT';
226                     }
227                 }
228             }
229             else
230             {
231                 $aPixMin = explode(",", $szInputCoords);
232             }
233             //calc geo positions and reproject points
234             if ($aPixMin != false)
235             {
236                 $nGeoMinx = Pix2Geo($aPixMin[0], 0, $this->mnWidth, $this->mdMinx, $this->mdMaxx);
237                 $nGeoMiny = Pix2Geo($aPixMin[1], 0, $this->mnHeight, $this->mdMiny, $this->mdMaxy, 1);
238                 reprojectPoint( $nGeoMinx, $nGeoMiny, $this->mszSRS, $this->moMapObject->oMap->getProjection() );
239             }
240             if ($aPixMax != false)
241             {
242                 $nGeoMaxx = Pix2Geo($aPixMax[0], 0, $this->mnWidth, $this->mdMinx, $this->mdMaxx);
243                 $nGeoMaxy = Pix2Geo($aPixMax[1], 0, $this->mnHeight, $this->mdMiny, $this->mdMaxy, 1);
244                 reprojectPoint( $nGeoMaxx, $nGeoMaxy, $this->mszSRS, $this->moMapObject->oMap->getProjection() );
245             }
246            
247             if ($this->mszMode == "ZOOM")
248             {
249                 if ($szInputType == "RECTANGLE")
250                 {
251                     if ($nGeoMinx > $nGeoMaxx)
252                     {
253                         $tmp = $nGeoMinx;
254                         $nGeoMinx = $nGeoMaxx;
255                         $nGeoMaxx = $tmp;
256                     }
257                     if ($nGeoMiny > $nGeoMaxy)
258                     {
259                         $tmp = $nGeoMiny;
260                         $nGeoMiny = $nGeoMaxy;
261                         $nGeoMaxy = $tmp;
262                     }
263
264                     // set the map extent
265                     $oMap->setExtent($nGeoMinx, $nGeoMiny, $nGeoMaxx, $nGeoMaxy);
266                 }
267                 elseif ($szInputType == "POINT")
268                 {
269                     // convert to map pixels
270                     $aPix[0] = Geo2Pix($nGeoMinx, 0, $oMap->width, $oMap->extent->minx, $oMap->extent->maxx);
271                     $aPix[1] = Geo2Pix($nGeoMiny, 0, $oMap->height, $oMap->extent->miny, $oMap->extent->maxy, true);
272
273                     // perform zoom
274                     $this->moMapNavigator->zoomPoint(1, $aPix[0], $aPix[1]);
275                 }
276                 else
277                 {
278                     $_SESSION['gErrorManager']->setError(ERR_WARNING,
279                     trim($this->moMLT->get("1", "ERROR: Invalid input type specified in "))." (".$szInputType.") KeyMapDHTML.widget.php.");
280                     return;
281                 }
282
283                 //cause extents to be recalculated based on size ....
284                 if ($oMap->getprojection() != "")
285                 {
286                     $oMap->setProjection($oMap->getProjection(), true);
287                 }
288                 /* -------------------------------------------------------------------- */
289                 /*      Call the reporjectauto function in case the map projection      */
290                 /*      is set to AUTO:XXX. If it is not, the function will do          */
291                 /*      nothing.                                                        */
292                 /* -------------------------------------------------------------------- */
293                 $this->ReprojectAuto();
294             }
295             elseif ($this->mszMode == "RECENTER")
296             {
297                 if ($szInputType == "POINT")
298                 {
299                     // convert to map pixels
300                     $aPix[0] = Geo2Pix($nGeoMinx, 0, $oMap->width, $oMap->extent->minx, $oMap->extent->maxx);
301                     $aPix[1] = Geo2Pix($nGeoMiny, 0, $oMap->height, $oMap->extent->miny, $oMap->extent->maxy, true);
302
303                     // perform zoom of factor 1 to recenter
304                     $this->moMapNavigator->zoomPoint(1, $aPix[0], $aPix[1]);
305
306                 }
307                 elseif ($szInputType == "RECTANGLE")
308                 {
309                     // calculate offset
310                     $nDeltaXGeo = $nGeoMaxx - $nGeoMinx;
311                     $nDeltaYGeo = $nGeoMaxy - $nGeoMiny;
312
313                     // offset current extent
314                     $oMap->setExtent( $oMap->extent->minx + $nDeltaXGeo,
315                     $oMap->extent->miny + $nDeltaYGeo,
316                     $oMap->extent->maxx + $nDeltaXGeo,
317                     $oMap->extent->maxy + $nDeltaYGeo );
318                 }
319                 else
320                 {
321                     $_SESSION['gErrorManager']->setError(ERR_WARNING,
322                     trim($this->moMLT->get("1", "ERROR: Invalid input type specified in"))." Recenter.php.");
323                     return true;
324                 }
325                 /* -------------------------------------------------------------------- */
326                 /*      Call the reporjectauto function in case the map projection      */
327                 /*      is set to AUTO:XXX. If it is not, the function will do          */
328                 /*      nothing.                                                        */
329                 /* -------------------------------------------------------------------- */
330
331                 $this->ReprojectAuto();
332             }
333         }
334
335         // return success
336         return true;
337     }
338
339     /**
340     * draw the map DHTML widget interface
341     */
342     function DrawPublish()
343     {
344         if (!$this->mbVisible)
345         return "<!-- KeyMapDHTML hidden -->";
346
347         $url = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
348
349         $nWidth = $this->mnWidth;
350         $nHeight = $this->mnHeight;
351
352         $szReturn = <<<EOT
353 <table cellpadding="0" cellspacing="0" border="0">
354 <tr>
355     <td bgcolor="000000"><img src="{$url}" width="1" height="1" id="keymapFrameTL" name="keymapFrameTL"></td>
356     <td bgcolor="000000"><img src="{$url}" width="1" height="1"></td>
357     <td bgcolor="000000"><img src="{$url}" width="1" height="1" id="keymapFrameTR" name="keymapFrameTR"></td>
358   </tr>
359   <tr>
360     <td bgcolor="000000"><img src="{$url}" width="1" height="1"></td>
361     <td><a name="keymapanchor" ><IMG SRC="{$url}" WIDTH="{$nWidth}" HEIGHT="{$nHeight}" NAME="KEYMAPDHTML_1" id="KEYMAPDHTML_1" border="0"></a></td>
362     <td bgcolor="000000"><img src="{$url}" width="1" height="1"></td>
363   </tr>
364   <tr>
365     <td bgcolor="000000"><img src="{$url}" width="1" height="1" id="keymapFrameBL" name="keymapFrameBL"></td>
366     <td bgcolor="000000"><img src="{$url}" width="1" height="1"></td>
367     <td bgcolor="000000"><img src="{$url}" width="1" height="1" id="keymapFrameBR" name="keymapFrameBR"></td>
368   </tr>
369 </table>
370 EOT;
371         return $szReturn;
372     }
373    
374    
375     /**
376     * return an array of javascript functions needed by KeyMapDHTML widget
377     * @return array of name = function values
378     */
379     function GetJavascriptFunctions()
380     {
381         /* -------------------------------------------------------------------- */
382         /*      test if we use the JS API.                                      */
383         /* -------------------------------------------------------------------- */
384         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
385         $bCWCJSAPI = 1;
386         else
387         $bCWCJSAPI = 0;
388    
389         $aReturn = parent::GetJavascriptFunctions();
390    
391         /* -------------------------------------------------------------------- */
392         /*      KeyMapWsetZoomBoxSettings                                          */
393         /* -------------------------------------------------------------------- */
394         $szJsFunctionName = "KeyMapWsetZoomBoxSettings";
395         $szFunction = "function $szJsFunctionName()\n";
396         $szFunction .= <<<EOT
397     {
398         if (CWCIsNav4 || CWCIsNav6)
399         {
400             document.captureEvents(Event.MOUSEMOVE);
401             document.captureEvents(Event.MOUSEDOWN);
402             document.captureEvents(Event.MOUSEUP);
403             document.captureEvents(Event.RESIZE);
404         }
405         else if (CWCIsIE)
406         {
407             gMapWhspc -= gMapWhspcIEadjust;
408             gMapWvspc += gMapWvspcIEadjust;
409         }
410         window.onresize = KeyMapWhandleresize;
411     }
412 EOT;
413         $aReturn[$szJsFunctionName] = $szFunction;
414    
415    
416         /* -------------------------------------------------------------------- */
417         /*      KeyMapWhandleresize                                                */
418         /* -------------------------------------------------------------------- */
419         $szJsFunctionName = "KeyMapWhandleresize";
420         $szFunction = "function $szJsFunctionName()\n";
421         $szFunction .= <<<EOT
422     {
423         if (CWCIsNav4)
424         {     // Netscape
425             location.reload();
426         }
427     }
428 EOT;
429         $aReturn[$szJsFunctionName] = $szFunction;
430    
431    
432         /* -------------------------------------------------------------------- */
433         /*      KeyMapWchkMouseUp                                                  */
434         /* -------------------------------------------------------------------- */
435         $szJsFunctionName = "KeyMapWchkMouseUp";
436         $szFunction = "function $szJsFunctionName(e)\n";
437         $szFunction .= <<<EOT
438     {
439         if (gKeyMapWdragging)
440         {
441             gKeyMapWmouseX = Math.min(Math.max(gKeyMapWmouseX, 0), gKeyMapWiWidth);
442             gKeyMapWmouseY = Math.min(Math.max(gKeyMapWmouseY, 0), gKeyMapWiHeight);
443             KeyMapWmapTool(e);
444         }
445     }
446 EOT;
447         $aReturn[$szJsFunctionName] = $szFunction;
448    
449    
450         /* -------------------------------------------------------------------- */
451         /*      KeyMapWPointNavigation                                             */
452         /* -------------------------------------------------------------------- */
453         $szJsFunctionName = "KeyMapWPointNavigation";
454         $szFunction = "function $szJsFunctionName()\n";
455         $szFunction .= <<<EOT
456     {
457         szCoord = ""+ gKeyMapWmouseX + "," + gKeyMapWmouseY;
458         if ({$bCWCJSAPI})
459         {
460             goCWCJSAPI.NAV_INPUT_COORDINATES = szCoord;
461             goCWCJSAPI.NAV_INPUT_TYPE = "POINT";
462    
463             //the forms variables settings should not be necessary. But It
464             //keeps consistancy since some js functions test the values
465             //of the form parameters.
466             {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value =  szCoord;
467             {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "POINT";
468    
469             goCWCJSAPI.UpdateNavTools();
470         }
471         else
472         {
473             {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value =  szCoord;
474             {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "POINT";
475             document.onmousemove = null;
476             document.onmouseup = null;
477             document.onmousedown = null;
478             {$this->mszHTMLForm}.submit();
479         }
480     }
481 EOT;
482    
483         $aReturn[$szJsFunctionName] = $szFunction;
484    
485    
486         /* -------------------------------------------------------------------- */
487         /*      KeyMapWmapTool                                                     */
488         /* -------------------------------------------------------------------- */
489         $szJsFunctionName = "KeyMapWmapTool";
490         $szFunction = "function $szJsFunctionName(e)\n";
491         $szFunction .= <<<EOT
492     {
493         if ( CWCIsNav6)
494         {
495             if (e.target == "[object HTMLHtmlElement]")
496             {
497                 return;
498             }
499         }
500         KeyMapWgetImageXY(e);
501    
502         /* -------------------------------------------------------------------- */
503         /*      if in js api update the js class with the mouse click position. */
504         /* -------------------------------------------------------------------- */
505         if ({$bCWCJSAPI})
506         {
507             if (KeyMapWinsideKeyMap())
508             {
509                 goCWCJSAPI.MouseClicked(gKeyMapWmouseX,gKeyMapWmouseY);
510             }
511         }
512    
513         if (KeyMapWinsideKeyMap())
514         {
515    
516             if ({$this->mszHTMLForm}.NAV_ALLOW_RECTANGLE.value == 0)
517             {
518                 //alert({$this->mszHTMLForm}.NAV_ALLOW_RECTANGLE.value);
519           //        KeyMapWPointNavigation();
520           //        return true;
521             }
522         }
523         if (!gKeyMapWdragging && KeyMapWinsideKeyMap()) {
524             KeyMapWstartZoomBox(e);
525             return false;
526         }
527         else if (gKeyMapWdragging)
528         {
529             KeyMapWgetMouse(e);
530             KeyMapWstopZoomBox(e);
531         }
532         return true;
533     }
534    
535 EOT;
536         $aReturn[$szJsFunctionName] = $szFunction;
537    
538    
539         /* -------------------------------------------------------------------- */
540         /*      KeyMapgetImageXY                                                   */
541         /* -------------------------------------------------------------------- */
542         $szJsFunctionName = "KeyMapWgetImageXY";
543         $szFunction = "function $szJsFunctionName(e)\n";
544         $szFunction .= <<<EOT
545     {
546         if (CWCIsNav4 || CWCIsNav6)
547         {                // Netscape
548             gKeyMapWmouseX = e.pageX;
549             gKeyMapWmouseY = e.pageY;
550         }
551         else if (CWCIsIE)
552         {            // IE
553             gKeyMapWmouseX = event.clientX + document.body.scrollLeft;
554             gKeyMapWmouseY = event.clientY + document.body.scrollTop;
555         }
556         else
557         {                              // Don't know
558             gKeyMapWmouseX = gKeyMapWmouseY = 0;
559         }
560    
561         // subtract offsets from page left and top
562         gKeyMapWmouseX = gKeyMapWmouseX - gKeyMapWhspc;
563         gKeyMapWmouseY = gKeyMapWmouseY - gKeyMapWvspc;
564     }
565    
566 EOT;
567         $aReturn[$szJsFunctionName] = $szFunction;
568    
569    
570         /* -------------------------------------------------------------------- */
571         /*      KeyMapgetMouse                                                     */
572         /* -------------------------------------------------------------------- */
573         $szJsFunctionName = "KeyMapWgetMouse";
574         $szFunction = "function $szJsFunctionName(e)\n";
575         $szFunction .= <<<EOT
576     {
577         //window.status = "";
578         KeyMapWgetImageXY(e);
579    
580         //make sure that the forms varaibales are initialized.
581         //It seems like that in IE, the mouse move may be called before.
582         if ({$this->mszHTMLForm} == null ||
583         {$this->mszHTMLForm}.KEYMAP_CURSOR_POS_X == null)
584         {
585             return true;
586         }
587    
588         if (KeyMapWinsideKeyMap())
589         {
590             {$this->mszHTMLForm}.KEYMAP_CURSOR_POS_X.value = gKeyMapWmouseX;
591             {$this->mszHTMLForm}.KEYMAP_CURSOR_POS_Y.value = gKeyMapWmouseY;
592             if ({$bCWCJSAPI})
593             {
594                 goCWCJSAPI.oMap.cursorpos[0] = gKeyMapWmouseX;
595                 goCWCJSAPI.oMap.cursorpos[1] = gKeyMapWmouseY;
596             }
597         }
598         else
599         {
600             {$this->mszHTMLForm}.KEYMAP_CURSOR_POS_X.value = -1;
601             {$this->mszHTMLForm}.KEYMAP_CURSOR_POS_Y.value = -1;
602    
603             if ({$bCWCJSAPI})
604             {
605                 goCWCJSAPI.oMap.cursorpos[0] = -1;
606                 goCWCJSAPI.oMap.cursorpos[1] = -1;
607             }
608             if (document.onmousedown == KeyMapWmapTool)
609                 document.onmousedown = null;
610             if (document.onmouseup == KeyMapWchkMouseUp)
611                 document.onmouseup = null;
612             return true;
613         }
614    
615         document.onmousedown = KeyMapWmapTool;
616         document.onmouseup = KeyMapWchkMouseUp;
617    
618         if (gKeyMapWdragging)
619         {
620             gKeyMapWx2 = gKeyMapWmouseX = Math.min(Math.max(gKeyMapWmouseX, 0), gKeyMapWiWidth);
621             gKeyMapWy2 = gKeyMapWmouseY = Math.min(Math.max(gKeyMapWmouseY, 0), gKeyMapWiHeight);
622    
623             KeyMapWsetClip();
624    
625             return false;
626         }
627         else
628         {
629             return true;
630         }
631    
632         return true;
633     }
634 EOT;
635         $aReturn[$szJsFunctionName] = $szFunction;
636    
637         /* -------------------------------------------------------------------- */
638         /*      KeyMapWinsideKeyMap                                                   */
639         /* -------------------------------------------------------------------- */
640         $szJsFunctionName = "KeyMapWinsideKeyMap";
641         $szFunction = "function $szJsFunctionName()\n";
642         $szFunction .= <<<EOT
643     {
644         return ((gKeyMapWmouseX >= 0) && (gKeyMapWmouseX < gKeyMapWiWidth) &&
645                 (gKeyMapWmouseY >= 0) && (gKeyMapWmouseY < gKeyMapWiHeight));
646     }
647 EOT;
648         $aReturn[$szJsFunctionName] = $szFunction;
649    
650    
651         /* -------------------------------------------------------------------- */
652         /*      KeyMapWstartZoomBox                                                */
653         /* -------------------------------------------------------------------- */
654         $szJsFunctionName = "KeyMapWstartZoomBox";
655         $szFunction = "function $szJsFunctionName(e)\n";
656         $szFunction .= <<<EOT
657     {
658         KeyMapWgetImageXY(e);
659         // keep it within the KeyMapImage
660         if (!gKeyMapWdragging)
661         {
662             // capture values to pass to map server
663             gKeyMapWfirstx = gKeyMapWx1 = gKeyMapWmouseX;
664             gKeyMapWfirsty = gKeyMapWy1 = gKeyMapWmouseY;
665             gKeyMapWx2 =  gKeyMapWx1 + 1;
666             gKeyMapWy2 =  gKeyMapWy1 + 1;
667    
668             CWCDHTML_ClipLayer(gKeyMapWtoplayer, gKeyMapWx1, gKeyMapWy1, gKeyMapWx2, gKeyMapWy2);
669             CWCDHTML_ClipLayer(gKeyMapWleftlayer, gKeyMapWx1, gKeyMapWy1, gKeyMapWx2, gKeyMapWy2);
670             CWCDHTML_ClipLayer(gKeyMapWrightlayer, gKeyMapWx1, gKeyMapWy1, gKeyMapWx2, gKeyMapWy2);
671             CWCDHTML_ClipLayer(gKeyMapWbottomlayer, gKeyMapWx1, gKeyMapWy1, gKeyMapWx2, gKeyMapWy2);
672             CWCDHTML_ShowLayer(gKeyMapWtoplayer);
673             CWCDHTML_ShowLayer(gKeyMapWleftlayer);
674             CWCDHTML_ShowLayer(gKeyMapWrightlayer);
675             CWCDHTML_ShowLayer(gKeyMapWbottomlayer);
676    
677             gKeyMapWdragging = true;
678         }
679         else
680         {
681             KeyMapWstopZoomBox(e);
682         }
683         return false;
684     }
685 EOT;
686         $aReturn[$szJsFunctionName] = $szFunction;
687    
688    
689         /* -------------------------------------------------------------------- */
690         /*      KeyMapWstopZoomBox                                                 */
691         /* -------------------------------------------------------------------- */
692         $szJsFunctionName = "KeyMapWstopZoomBox";
693         $szFunction = "function $szJsFunctionName(e)\n";
694         $szFunction .= <<<EOT
695     {
696         gKeyMapWdragging = false;
697         gKeyMapWsecondx = gKeyMapWx2;
698         gKeyMapWsecondy = gKeyMapWy2;
699
700         //TODO : values for the smallest rectangle availablee
701         if (gKeyMapWfirstx == gKeyMapWsecondx && gKeyMapWfirsty == gKeyMapWsecondy)
702         {
703             var szCoord = ""+ gKeyMapWfirstx + "," + gKeyMapWfirsty;
704             if ({$bCWCJSAPI})
705             {
706                 goCWCJSAPI.NAV_INPUT_COORDINATES = szCoord;
707                 goCWCJSAPI.NAV_INPUT_TYPE = "POINT";
708                 //the forms variables settings should not be necessary. But It
709                 //keeps consistancy since some js functions test the values
710                 //of the form parameters.
711                 {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value = szCoord;
712                 {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "POINT";
713                 goCWCJSAPI.UpdateNavTools();
714             }
715             else
716             {
717                 {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value = szCoord;
718                 {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "POINT";
719                 {$this->mszHTMLForm}.NAV_CMD.value = "KEYMAP_DHTML";
720                 document.onmousemove = null;
721                 document.onmouseup = null;
722                 document.onmousedown = null;
723                 {$this->mszHTMLForm}.submit();
724             }
725             return true;
726         }
727         else
728         {
729             // Zoom to box
730             if ({$this->mszHTMLForm}.KEYMAP_DHTML_MODE.value == "ZOOM")
731             {
732                 var tx1 = Math.min(gKeyMapWfirstx, gKeyMapWsecondx);
733                 var tx2 = Math.max(gKeyMapWfirstx, gKeyMapWsecondx);
734                 var ty1 = Math.min(gKeyMapWfirsty, gKeyMapWsecondy);
735                 var ty2 = Math.max(gKeyMapWfirsty, gKeyMapWsecondy);
736             }
737             else
738             {
739                 var tx1 = gKeyMapWfirstx;
740                 var tx2 = gKeyMapWsecondx;
741                 var ty1 = gKeyMapWfirsty;
742                 var ty2 = gKeyMapWsecondy;
743             }
744    
745             var szCoord = ""+ tx1 + "," + ty1 + ";" + tx2 + "," + ty2;
746    
747             if ({$bCWCJSAPI})
748             {
749                 goCWCJSAPI.NAV_CMD = "KEYMAP_DHTML";
750                 goCWCJSAPI.NAV_INPUT_COORDINATES = szCoord;
751                 goCWCJSAPI.NAV_INPUT_TYPE = "RECTANGLE";
752    
753                 //the forms variables settings should not be necessary. But It
754                 //keeps consistancy since some js functions test the values
755                 //of the form parameters.
756                 {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value = szCoord;
757                 {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "RECTANGLE";
758
759                 CWCDHTML_HideLayer("zKeyMapBoxTop");
760                 CWCDHTML_HideLayer("zKeyMapBoxLeft");
761                 CWCDHTML_HideLayer("zKeyMapBoxRight");
762                 CWCDHTML_HideLayer("zKeyMapBoxBottom");
763                 goCWCJSAPI.UpdateNavTools();
764             }
765             else
766             {
767                 {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value = szCoord;
768                 {$this->mszHTMLForm}.NAV_INPUT_TYPE.value = "RECTANGLE";
769                 {$this->mszHTMLForm}.NAV_CMD.value = "KEYMAP_DHTML";
770                 document.onmousemove = null;
771                 document.onmouseup = null;
772                 document.onmousedown = null;
773                 {$this->mszHTMLForm}.submit();
774             }
775             return true;
776         }
777         return false;
778     }
779 EOT;
780         $aReturn[$szJsFunctionName] = $szFunction;
781    
782    
783         /* -------------------------------------------------------------------- */
784         /*      KeyMapWsetClip                                                     */
785         /* -------------------------------------------------------------------- */
786         $oMap = $this->moMapObject->oMap;
787    
788         $nMinx = $oMap->extent->minx;
789         $nMiny = $oMap->extent->miny;
790         $nMaxx = $oMap->extent->maxx;
791         $nMaxy = $oMap->extent->maxy;
792         //echo "bbox 1: $nMinx,$nMiny:$nMaxx,$nMaxy<BR>\n";
793         reprojectPoint( $nMinx, $nMiny, $this->moMapObject->oMap->getProjection(), $this->mszSRS );
794         reprojectPoint( $nMaxx, $nMaxy, $this->moMapObject->oMap->getProjection(), $this->mszSRS );
795         //echo "bbox 2: $nMinx,$nMiny:$nMaxx,$nMaxy<BR>\n";
796        
797        
798         $nRefMinx = $oMap->reference->extent->minx;
799         $nRefMiny = $oMap->reference->extent->miny;
800         $nRefMaxx = $oMap->reference->extent->maxx;
801         $nRefMaxy = $oMap->reference->extent->maxy;
802         //echo "ref: $nRefMinx,$nRefMiny:$nRefMaxx,$nRefMaxy<BR>\n";
803
804         // calculate the bounding pixels of the box to draw
805         $nLeft = Geo2Pix($nMinx, 0, $oMap->reference->width, $nRefMinx, $nRefMaxx);
806         $nTop = Geo2Pix($nMaxy, 0, $oMap->reference->height, $nRefMiny, $nRefMaxy, true);
807         $nRight = Geo2Pix($nMaxx, 0, $oMap->reference->width, $nRefMinx, $nRefMaxx);
808         $nBottom = Geo2Pix($nMiny, 0, $oMap->reference->height, $nRefMiny, $nRefMaxy, true);
809         //echo "$nLeft,$nBottom:$nRight,$nTop<BR>\n";
810             $nSRSRefMinx = $nRefMinx;
811             $nSRSRefMaxx = $nRefMaxx;
812             $nSRSRefMiny = $nRefMiny;
813             $nSRSRefMaxy = $nRefMaxy;
814
815             reprojectPoint( $nSRSRefMinx, $nSRSRefMiny,
816                   $this->mszSRS, $this->moMapObject->oMap->getProjection() );
817             reprojectPoint( $nSRSRefMaxx, $nSRSRefMaxy,
818                   $this->mszSRS, $this->moMapObject->oMap->getProjection() );
819        
820         $szJsFunctionName = "KeyMapWsetClip";
821         $szFunction = "function $szJsFunctionName()\n";
822         $szFunction .= <<<EOT
823     {
824         gKeyMapWzright  = Math.max(gKeyMapWx1, gKeyMapWx2);
825         gKeyMapWzleft   = Math.min(gKeyMapWx1, gKeyMapWx2);
826         gKeyMapWzbottom = Math.max(gKeyMapWy1, gKeyMapWy2);
827         gKeyMapWztop    = Math.min(gKeyMapWy1, gKeyMapWy2);
828    
829         if ((gKeyMapWx1 != gKeyMapWx2) && (gKeyMapWy1 != gKeyMapWy2))
830         {
831             var ovBoxSize = {$this->mnMarqueeWidth};
832    
833         if ({$this->mszHTMLForm}.KEYMAP_DHTML_MODE.value == "ZOOM")
834             {
835                 CWCDHTML_ClipLayer(gKeyMapWtoplayer, gKeyMapWzleft, gKeyMapWztop, gKeyMapWzright, gKeyMapWztop + ovBoxSize);
836                 CWCDHTML_ClipLayer(gKeyMapWleftlayer, gKeyMapWzleft, gKeyMapWztop, gKeyMapWzleft + ovBoxSize, gKeyMapWzbottom);
837                 CWCDHTML_ClipLayer(gKeyMapWrightlayer, gKeyMapWzright - ovBoxSize, gKeyMapWztop, gKeyMapWzright, gKeyMapWzbottom);
838                 CWCDHTML_ClipLayer(gKeyMapWbottomlayer, gKeyMapWzleft, gKeyMapWzbottom - ovBoxSize, gKeyMapWzright, gKeyMapWzbottom);
839             }
840             else
841             {// recenter
842                 var nXDiff = gKeyMapWx2 - gKeyMapWx1;
843                 var nYDiff = gKeyMapWy2 - gKeyMapWy1;
844                 var nLeft = {$nLeft};
845                 var nTop = {$nTop};
846                 var nRight = {$nRight};
847                 var nBottom = {$nBottom};
848  
849                 CWCDHTML_ClipLayer(gKeyMap2Wtoplayer, nLeft+nXDiff,nTop+nYDiff,nRight+nXDiff,nTop+nYDiff+1);
850                 CWCDHTML_ClipLayer(gKeyMap2Wleftlayer, nLeft+nXDiff,nTop+nYDiff,nLeft+nXDiff+1,nBottom+nYDiff);
851                 CWCDHTML_ClipLayer(gKeyMap2Wrightlayer, nRight+nXDiff-1,nTop+nYDiff,nRight+nXDiff,nBottom+nYDiff);
852                 CWCDHTML_ClipLayer(gKeyMap2Wbottomlayer, nLeft+nXDiff,nBottom+nYDiff-1,nRight+nXDiff,nBottom+nYDiff);
853             }
854    
855         }
856     }
857 EOT;
858         $aReturn[$szJsFunctionName] = $szFunction;
859    
860         $szJsFunctionName = "KeyMapWCaptureMouse";
861         $szFunction = "function $szJsFunctionName()\n";
862         $szFunction .= <<<EOT
863     {
864         document.onmousemove = CWC2OnMouseMoveFunction;
865     }
866 EOT;
867         $aReturn[$szJsFunctionName] = $szFunction;
868    
869         $szJsFunctionName = "KeyMapWReleaseMouse";
870         $szFunction = "function $szJsFunctionName()\n";
871         $szFunction .= <<<EOT
872     {
873         document.onmousemove = null;
874     }
875 EOT;
876         $aReturn[$szJsFunctionName] = $szFunction;
877    
878    
879         /* -------------------------------------------------------------------- */
880         /*      KeyMapWCreateDHTMLLayers                                            */
881         /* -------------------------------------------------------------------- */
882         $oApp = GetChameleonApplication();
883    
884         $url = $oApp->fileSystemToURL( $this->mszImage, true );
885         $szJsFunctionName = "KeyMapWCreateDHTMLLayers";
886         $szFunction = "function $szJsFunctionName()\n";
887         $szAPixel = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
888         $szFunction .= <<<EOT
889     {
890         var content = "";
891         //panning layer
892    
893         CWCDHTML_CreateLayer("KeyMapLayerBG", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
894                              true, content);
895         CWCDHTML_SetLayerBackgroundColor("KeyMapLayerBG", 'WHITE');
896         CWCDHTML_SetLayerZOrder( "KeyMapLayerBG", 10 );
897    
898         content = "<img name=\"KeyMapLayerDivImg\" src=\"{$szAPixel}\" width=\""+{$this->mnWidth}+"\" height=\""+{$this->mnHeight}+"\" border=\"0\" onload=\"\" onmouseover=\"KeyMapWCaptureMouse();\" onmouseout=\"KeyMapWReleaseMouse();\">";
899         CWCDHTML_CreateLayer("KeyMapLayerDiv", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
900                               true, content);
901         CWCDHTML_SetLayerZOrder( "KeyMapLayerDiv", 11 );
902    
903         content = '<img name="zKeyMapImgTop" src="{$this->mszMarqueeImageVertical}" border="1">';
904         CWCDHTML_CreateLayer("zKeyMapBoxTop", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
905                              false, content);
906         CWCDHTML_SetLayerZOrder( "zKeyMapBoxTop", 12 );
907    
908         content = '<img name="zKeyMapImgLeft" src="{$this->mszMarqueeImageHorizontal}" border="1">';
909         CWCDHTML_CreateLayer("zKeyMapBoxLeft", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
910                              false, content);
911         CWCDHTML_SetLayerZOrder( "zKeyMapBoxLeft", 12 );
912    
913         content = '<img name="zKeyMapImgBottom" src="{$this->mszMarqueeImageVertical}" border="1">';
914         CWCDHTML_CreateLayer("zKeyMapBoxBottom", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
915                              false, content);
916         CWCDHTML_SetLayerZOrder( "zKeyMapBoxBottom", 12 );
917    
918         content = '<img name="zKeyMapImgRight" src="{$this->mszMarqueeImageHorizontal}" border="1">';
919         CWCDHTML_CreateLayer("zKeyMapBoxRight", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
920                              false, content);
921         CWCDHTML_SetLayerZOrder( "zKeyMapBoxRight", 12 );
922    
923         content = '<img name="zKeyMap2ImgTop" src="{$this->mszMarqueeImageVertical}" border="1">';
924         CWCDHTML_CreateLayer("zKeyMap2BoxTop", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
925                              true, content);
926         CWCDHTML_SetLayerZOrder( "zKeyMap2BoxTop", 12 );
927    
928         content = '<img name="zKeyMap2ImgLeft" src="{$this->mszMarqueeImageHorizontal}" border="1">';
929         CWCDHTML_CreateLayer("zKeyMap2BoxLeft", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
930                              true, content);
931         CWCDHTML_SetLayerZOrder( "zKeyMap2BoxLeft", 12 );
932    
933         content = '<img name="zKeyMap2ImgBottom" src="{$this->mszMarqueeImageVertical}" border="1">';
934         CWCDHTML_CreateLayer("zKeyMap2BoxBottom", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
935                              true, content);
936         CWCDHTML_SetLayerZOrder( "zKeyMap2BoxBottom", 12 );
937    
938         content = '<img name="zKeyMap2ImgRight" src="{$this->mszMarqueeImageHorizontal}" border="1">';
939         CWCDHTML_CreateLayer("zKeyMap2BoxRight", gKeyMapWhspc, gKeyMapWvspc, gKeyMapWiWidth, gKeyMapWiHeight,
940                              true, content);
941         CWCDHTML_SetLayerZOrder( "zKeyMap2BoxRight", 12 );
942    
943    
944         boundingColor = '{$this->mszMarqueeColor}';
945         CWCDHTML_SetLayerBackgroundColor("zKeyMapBoxTop", boundingColor);
946         CWCDHTML_SetLayerBackgroundColor("zKeyMapBoxLeft", boundingColor);
947         CWCDHTML_SetLayerBackgroundColor("zKeyMapBoxRight", boundingColor);
948         CWCDHTML_SetLayerBackgroundColor("zKeyMapBoxBottom", boundingColor);
949    
950         CWCDHTML_SetLayerBackgroundColor("zKeyMap2BoxTop", boundingColor);
951         CWCDHTML_SetLayerBackgroundColor("zKeyMap2BoxLeft", boundingColor);
952         CWCDHTML_SetLayerBackgroundColor("zKeyMap2BoxRight", boundingColor);
953         CWCDHTML_SetLayerBackgroundColor("zKeyMap2BoxBottom", boundingColor);
954    
955         var nLeft = {$nLeft};
956         var nTop = {$nTop};
957         var nRight = {$nRight};
958         var nBottom = {$nBottom};
959    
960         // Create the red rectangle that will show wich part of the map is shown.
961         CWCDHTML_ClipLayer(gKeyMap2Wtoplayer, nLeft,nTop,nRight,nTop+1);
962         CWCDHTML_ClipLayer(gKeyMap2Wleftlayer, nLeft,nTop,nLeft+1,nBottom);
963         CWCDHTML_ClipLayer(gKeyMap2Wrightlayer, nRight-1,nTop,nRight,nBottom);
964         CWCDHTML_ClipLayer(gKeyMap2Wbottomlayer, nLeft,nBottom-1,nRight,nBottom);
965     }
966    
967 EOT;
968         $aReturn[$szJsFunctionName] = $szFunction;
969    
970         /* -------------------------------------------------------------------- */
971         /*       Initilalization function called from on load.                  */
972         /* -------------------------------------------------------------------- */
973         $nWidth = $this->mnWidth;
974         $nHeight = $this->mnHeight;
975         $szJsFunctionName = "KeyMapWidgetInitVariables";
976         $szFunction = "function $szJsFunctionName()\n";
977         $szFunction .= <<<EOT
978     {
979         CWCIsNav4 = (document.layers) ? 1:0;
980    
981         CWCIsIE = (document.all) ? 1:0;
982         CWCIsNav6 = (document.getElementById && !document.all) ? 1:0;
983    
984         // Constants
985         gKeyMapWvspcIEadjust = 0;// orginal code was 7;
986         gKeyMapWhspcIEadjust = 0;// orginal code was -2;
987         gKeyMapWiWidth = {$nWidth};
988         gKeyMapWiHeight = {$nHeight};
989         gKeyMapWhspc = 0;
990         gKeyMapWvspc = 0;
991    
992         if (document.layers) //Netscape 4.x
993         {
994             gKeyMapWhspc = document.images['keymapFrameTL'].x;
995             gKeyMapWvspc = document.images['keymapFrameTL'].y;
996         }
997         else
998         {
999             gKeyMapWhspc = CWCDHTML_FindObjectPosX( document.getElementById('keymapFrameTL'));
1000             gKeyMapWvspc = CWCDHTML_FindObjectPosY( document. getElementById('keymapFrameTL'));
1001         }
1002    
1003         gKeyMapWhspc+=1;
1004         gKeyMapWvspc+=1;
1005    
1006         KeyMapWsetZoomBoxSettings();
1007         KeyMapWCreateDHTMLLayers();
1008     }
1009 EOT;
1010         $aReturn[$szJsFunctionName] = $szFunction;
1011    
1012    
1013         /* -------------------------------------------------------------------- */
1014         /*      if we use the JS API, add functions that will be called on      */
1015         /*      events happning on the map.                                     */
1016         /* -------------------------------------------------------------------- */
1017         if ($bCWCJSAPI)
1018         {
1019             $nSRSRefMinx = $nRefMinx;
1020             $nSRSRefMaxx = $nRefMaxx;
1021             $nSRSRefMiny = $nRefMiny;
1022             $nSRSRefMaxy = $nRefMaxy;
1023
1024             reprojectPoint( $nSRSRefMinx, $nSRSRefMiny,
1025                   $this->mszSRS, $this->moMapObject->oMap->getProjection() );
1026             reprojectPoint( $nSRSRefMaxx, $nSRSRefMaxy,
1027                   $this->mszSRS, $this->moMapObject->oMap->getProjection() );
1028
1029             $szJsFunctionName = "KeyMapWGeo2Pix";
1030             $szFunction = <<<EOT
1031     function {$szJsFunctionName}(nGeoPos, dfPixMin, dfPixMax, dfGeoMin,
1032                      dfGeoMax, nInverseGeo)
1033     {
1034         // calculate the geocoded & pixel width
1035         dfWidthGeo = Math.abs(dfGeoMax - dfGeoMin);
1036         dfWidthPix = Math.abs(dfPixMax - dfPixMin);
1037
1038         // get ratio
1039         if ( dfWidthGeo <= 0 )
1040         {
1041             return 0;
1042         }
1043         dfGeoToPix = dfWidthPix / dfWidthGeo;
1044
1045         // get difference
1046         if (!nInverseGeo)
1047             dfDeltaGeo = nGeoPos - dfGeoMin;
1048         else
1049             dfDeltaGeo = dfGeoMax - nGeoPos;
1050
1051         // calculate
1052         dfDeltaPix = dfDeltaGeo * dfGeoToPix;
1053         dfPosPix = dfPixMin + dfDeltaPix;
1054
1055         // return value
1056         return Math.round (dfPosPix);
1057
1058         // end pixel_to_geo function
1059 }
1060 EOT;
1061             $aReturn[$szJsFunctionName] = $szFunction;
1062
1063             $szJsFunctionName = "KeyMapWKeyMapExtentsChanged";
1064             $szFunction = <<<EOT
1065     /**
1066      * {$szJsFunctionName}
1067      * called to initialize the JS API widget
1068      */
1069     function {$szJsFunctionName}()
1070     {
1071         var sImgName = "KeyMapLayerDivImg";
1072         var url = "{$url}";
1073         if (navigator.appName == "Netscape" && navigator.appVersion[0] <= 4)
1074         {
1075             document.layers["KeyMapLayerDiv"].document.images[0].src=url; //for netscape4
1076         }
1077         else
1078         {
1079             document.images["KeyMapLayerDivImg"].src = url;  //for IE and Netscape6 works
1080         }
1081
1082         var nLeft = KeyMapWGeo2Pix(goCWCJSAPI.oMap.minx, 0, gKeyMapWiWidth, {$nSRSRefMinx}, {$nSRSRefMaxx}, false);
1083         var nTop = KeyMapWGeo2Pix(goCWCJSAPI.oMap.maxy, 0, gKeyMapWiHeight, {$nSRSRefMiny}, {$nSRSRefMaxy}, true);
1084         var nRight = KeyMapWGeo2Pix(goCWCJSAPI.oMap.maxx, 0, gKeyMapWiWidth, {$nSRSRefMinx}, {$nSRSRefMaxx}, false);
1085         var nBottom = KeyMapWGeo2Pix(goCWCJSAPI.oMap.miny, 0, gKeyMapWiHeight, {$nSRSRefMiny}, {$nSRSRefMaxy}, true);
1086
1087         // Create the red rectangle that will show wich part of the map is shown.
1088         CWCDHTML_ClipLayer(gKeyMap2Wtoplayer, nLeft,nTop,nRight,nTop+1);
1089         CWCDHTML_ClipLayer(gKeyMap2Wleftlayer, nLeft,nTop,nLeft+1,nBottom);
1090         CWCDHTML_ClipLayer(gKeyMap2Wrightlayer, nRight-1,nTop,nRight,nBottom);
1091         CWCDHTML_ClipLayer(gKeyMap2Wbottomlayer, nLeft,nBottom-1,nRight,nBottom);
1092        
1093     }
1094 EOT;
1095    
1096             $aReturn[$szJsFunctionName] = $szFunction;
1097    
1098
1099             $bAllowResize = 0;
1100             if ($this->mbAllowResize)
1101             $bAllowResize = 1;
1102             $szJsFunctionName = "KeyMapWRegisterForEvent";
1103             $szFunction = <<<EOT
1104     /**
1105      * {$szJsFunctionName}
1106      * called to create a dynamic layer
1107      */
1108     function {$szJsFunctionName}()
1109     {
1110         goCWCJSAPI.RegisterEvent(MAP_EXTENT_CHANGED, "KeyMapWKeyMapExtentsChanged");
1111         goCWCJSAPI.RegisterEvent(LAYER_STATUS_CHANGED, "KeyMapWKeyMapExtentsChanged");
1112         goCWCJSAPI.RegisterEvent(LAYER_ORDER_CHANGED, "KeyMapWKeyMapExtentsChanged");
1113         goCWCJSAPI.RegisterEvent(LAYER_STYLE_CHANGED, "KeyMapWKeyMapExtentsChanged");
1114         goCWCJSAPI.RegisterEvent(MAP_NEW_LAYER_ADDED, "KeyMapWKeyMapExtentsChanged");
1115         goCWCJSAPI.RegisterEvent(MAP_NEW_ELEMENT_ADDED, "KeyMapWKeyMapExtentsChanged");
1116    
1117         //set the js map object to allow resizing or not.
1118         //goCWCJSAPI.oKeyMap.bAllowResize = {$bAllowResize};
1119     }
1120 EOT;
1121    
1122             $aReturn[$szJsFunctionName] = $szFunction;
1123    
1124    
1125         }
1126    
1127         $szJsFunctionName = "KeyMapLayerDivImgOnLoad";
1128    
1129         $szFunction = <<<EOT
1130     /**
1131      * {$szJsFunctionName}
1132      * called to initialize the map image after the page has loaded
1133      */
1134     function {$szJsFunctionName}()
1135     {
1136         var sImgName = "KeyMapLayerDivImg";
1137         var url = "{$url}";
1138         var d = new Date();
1139         var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
1140    
1141         if (navigator.appName == "Netscape" && navigator.appVersion[0] <= 4)
1142         {
1143             document.layers["KeyMapLayerDiv"].document.images[0].src=url; //for netscape4
1144         }
1145         else
1146         {
1147             document.images["KeyMapLayerDivImg"].src = url;  //for IE and Netscape6 works
1148         }
1149     }
1150 EOT;
1151    
1152         $aReturn[$szJsFunctionName] = $szFunction;
1153    
1154         $szJsFunctionName = "KeyMapWHideActivityLayer";
1155    
1156         $szFunction = <<<EOT
1157     /**
1158      * {$szJsFunctionName}
1159      * called to initialize the map image after the page has loaded
1160      */
1161     function {$szJsFunctionName}()
1162     {
1163         var szImage = null;
1164         if (navigator.appName == "Netscape" && navigator.appVersion[0] <= 4)
1165         {
1166            szImage = document.layers["KeyMapLayerDiv"].document.images[0].src;
1167         }
1168         else
1169         {
1170             szImage = document.images["KeyMapLayerDivImg"].src;  //for IE and Netscape6 works
1171         }
1172         if (szImage != null && szImage.indexOf( 'a_pixel' ) == -1)
1173         {
1174             CWCDHTML_HideLayer('ActivityLayer');
1175             CWCDHTML_ShowLayer('KeyMapLayerDiv');
1176         }
1177    
1178     }
1179 EOT;
1180    
1181         $aReturn[$szJsFunctionName] = $szFunction;
1182    
1183         return $aReturn;
1184     }
1185    
1186    
1187    
1188     /**
1189     * GetJavascriptOnMouseMoveFunctions
1190     *
1191     * Returns functions to be called on mouse mouve event.
1192     */
1193     function GetJavascriptOnMouseMoveFunctions()
1194     {
1195         $aReturn = array();
1196         $szJsFunctionName = "KeyMapWgetMouse";
1197         $szFunction = "$szJsFunctionName(e);\n";
1198         $aReturn[$szJsFunctionName] = $szFunction;
1199    
1200         return $aReturn;
1201     }
1202    
1203     /**
1204     * GetJavascriptOnMouseUpFunctions.
1205     *
1206     */
1207     function GetJavascriptOnMouseUpFunctions2()
1208     {
1209         $aReturn = array();
1210         $szJsFunctionName = "KeyMapWchkMouseUp";
1211         $szFunction = "$szJsFunctionName(e);\n";
1212         $aReturn[$szJsFunctionName] = $szFunction;
1213    
1214         return $aReturn;
1215     }
1216    
1217     /**
1218     * GetJavascriptOnMouseDownFunctions
1219     *
1220     */
1221     function GetJavascriptOnMouseDownFunctions2()
1222     {
1223         $aReturn = array();
1224         $szJsFunctionName = "KeyMapWmapTool";
1225         $szFunction = "$szJsFunctionName(e);\n";
1226         $aReturn[$szJsFunctionName] = $szFunction;
1227    
1228         return $aReturn;
1229     }
1230    
1231    
1232     /**
1233     * GetJavascriptOnLoadFunctions
1234     *
1235     * On load functions.
1236     */
1237     function GetJavascriptOnLoadFunctions()
1238     {
1239         $aReturn = array();
1240    
1241         $aReturn['KeyMapLayerDivImgOnLoad'] = "KeyMapLayerDivImgOnLoad();\n";
1242    
1243         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
1244         {
1245             $szJsFunctionName = "KeyMapWRegisterForEvent";
1246             $szFunction = "$szJsFunctionName();\n";
1247             $aReturn[$szJsFunctionName] = $szFunction;
1248         }
1249    
1250         return $aReturn;
1251     }
1252    
1253    
1254    
1255     /**
1256     * GetJavascriptInitFunctions
1257     *
1258     * Functions to be called at the end of the load.
1259     */
1260     function GetJavascriptInitFunctions()
1261     {
1262         $aReturn = array();
1263    
1264         $szJsFunctionName = "KeyMapWidgetInitVariables";
1265         //$szFunction = "setTimeout('$szJsFunctionName()',5000);";
1266         $szFunction = "$szJsFunctionName();\n";
1267         $aReturn[$szJsFunctionName] = $szFunction;
1268    
1269         return $aReturn;
1270     }
1271    
1272     /**
1273     * GetJavascriptIncludeFunctions
1274     */
1275     function GetJavascriptIncludeFunctions()
1276     {
1277         $aReturn = parent::GetJavascriptIncludeFunctions();
1278    
1279         $szJsIncludeName = "cwc_dhtml.js";
1280         $szInclude = '<script language="JavaScript" src="'.$_SESSION["gszCoreWebPath"]."/widgets/js/cwc_dhtml.js".'" type="text/javascript"></script>';
1281         $aReturn[$szJsIncludeName] = $szInclude;
1282    
1283         return $aReturn;
1284     }
1285    
1286     /**
1287     * GetJavascriptVariables
1288     *
1289     * Return JS global variables and global code.
1290     */
1291     function GetJavascriptVariables()
1292     {
1293         $aReturn = array();
1294    
1295         $szVariable = "gKeyMapWvspcIEadjust";
1296         $szValue = " var $szVariable = 7;\n";
1297         $aReturn[$szVariable] = $szValue;
1298    
1299         $szVariable = "gKeyMapWhspcIEadjust";
1300         $szValue = " var $szVariable = -2;\n";
1301         $aReturn[$szVariable] = $szValue;
1302    
1303         $szVariable = "gKeyMapWiWidth";
1304         $szValue = " var $szVariable = 0;\n";
1305         $aReturn[$szVariable] = $szValue;
1306    
1307         $szVariable = "gKeyMapWiHeight";
1308         $szValue = " var $szVariable = 0;\n";
1309         $aReturn[$szVariable] = $szValue;
1310    
1311         $szVariable = "gKeyMapWhspc";
1312         $szValue = " var $szVariable = 0;\n";
1313         $aReturn[$szVariable] = $szValue;
1314    
1315         $szVariable = "gKeyMapWvspc";
1316         $szValue = " var $szVariable = 0;\n";
1317         $aReturn[$szVariable] = $szValue;
1318    
1319         $szVariable = "gKeyMapWmouseX";
1320         $szValue = " var $szVariable = 0;\n";
1321         $aReturn[$szVariable] = $szValue;
1322    
1323         $szVariable = "gKeyMapWmouseY";
1324         $szValue = " var $szVariable = 0;\n";
1325         $aReturn[$szVariable] = $szValue;
1326    
1327         $szVariable = "gKeyMapWx1";
1328         $szValue = " var $szVariable = 0;\n";
1329         $aReturn[$szVariable] = $szValue;
1330    
1331         $szVariable = "gKeyMapWy1";
1332         $szValue = " var $szVariable = 0;\n";
1333         $aReturn[$szVariable] = $szValue;
1334    
1335         $szVariable = "gKeyMapWx2";
1336         $szValue = " var $szVariable = 0;\n";
1337         $aReturn[$szVariable] = $szValue;
1338    
1339         $szVariable = "gKeyMapWy2";
1340         $szValue = " var $szVariable = 0;\n";
1341         $aReturn[$szVariable] = $szValue;
1342    
1343         $szVariable = "gKeyMapWfirstx";
1344         $szValue = " var $szVariable = 0;\n";
1345         $aReturn[$szVariable] = $szValue;
1346    
1347         $szVariable = "gKeyMapWfirsty";
1348         $szValue = " var $szVariable = 0;\n";
1349         $aReturn[$szVariable] = $szValue;
1350    
1351         $szVariable = "gKeyMapWsecondx";
1352         $szValue = " var $szVariable = 0;\n";
1353         $aReturn[$szVariable] = $szValue;
1354    
1355         $szVariable = "gKeyMapWsecondy";
1356         $szValue = " var $szVariable = 0;\n";
1357         $aReturn[$szVariable] = $szValue;
1358    
1359         $szVariable = "gKeyMapWzleft";
1360         $szValue = " var $szVariable = 0;\n";
1361         $aReturn[$szVariable] = $szValue;
1362    
1363         $szVariable = "gKeyMapWzright";
1364         $szValue = " var $szVariable = 0;\n";
1365         $aReturn[$szVariable] = $szValue;
1366    
1367         $szVariable = "gKeyMapWztop";
1368         $szValue = " var $szVariable = 0;\n";
1369         $aReturn[$szVariable] = $szValue;
1370    
1371         $szVariable = "gKeyMapWzbottom";
1372         $szValue = " var $szVariable = 0;\n";
1373         $aReturn[$szVariable] = $szValue;
1374    
1375         $szVariable = "gKeyMapWmapX";
1376         $szValue = " var $szVariable = 0;\n";
1377         $aReturn[$szVariable] = $szValue;
1378    
1379         $szVariable = "gKeyMapWmapY";
1380         $szValue = " var $szVariable = 0;\n";
1381         $aReturn[$szVariable] = $szValue;
1382    
1383         $szVariable = "gKeyMapWdragging";
1384         $szValue = " var $szVariable = false;\n";
1385         $aReturn[$szVariable] = $szValue;
1386    
1387         $szVariable = "gKeyMapWtoplayer";
1388         $szValue = " var $szVariable = \"zKeyMapBoxTop\";\n";
1389         $aReturn[$szVariable] = $szValue;
1390    
1391         $szVariable = "gKeyMapWleftlayer";
1392         $szValue = " var $szVariable = \"zKeyMapBoxLeft\";\n";
1393         $aReturn[$szVariable] = $szValue;
1394    
1395         $szVariable = "gKeyMapWbottomlayer";
1396         $szValue = " var $szVariable = \"zKeyMapBoxBottom\";\n";
1397         $aReturn[$szVariable] = $szValue;
1398    
1399         $szVariable = "gKeyMapWrightlayer";
1400         $szValue = " var $szVariable = \"zKeyMapBoxRight\";\n";
1401         $aReturn[$szVariable] = $szValue;
1402    
1403    
1404         $szVariable = "gKeyMap2Wtoplayer";
1405         $szValue = " var $szVariable = \"zKeyMap2BoxTop\";\n";
1406         $aReturn[$szVariable] = $szValue;
1407    
1408         $szVariable = "gKeyMap2Wleftlayer";
1409         $szValue = " var $szVariable = \"zKeyMap2BoxLeft\";\n";
1410         $aReturn[$szVariable] = $szValue;
1411    
1412         $szVariable = "gKeyMap2Wbottomlayer";
1413         $szValue = " var $szVariable = \"zKeyMap2BoxBottom\";\n";
1414         $aReturn[$szVariable] = $szValue;
1415    
1416         $szVariable = "gKeyMap2Wrightlayer";
1417         $szValue = " var $szVariable = \"zKeyMap2BoxRight\";\n";
1418         $aReturn[$szVariable] = $szValue;
1419    
1420         return $aReturn;
1421     }
1422    
1423     /**
1424     * GetHTMLHiddenVariables
1425     *
1426     * Return HTML hidden variables.
1427     */
1428     function GetHTMLHiddenVariables()
1429     {
1430         $szVariable = "NAV_INPUT_TYPE";
1431         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
1432         $aReturn[$szVariable] = $szValue;
1433    
1434         $szVariable = "NAV_INPUT_COORDINATES";
1435         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
1436         $aReturn[$szVariable] = $szValue;
1437    
1438         $szVariable = "KEYMAP_CURSOR_POS_X";
1439         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
1440         $aReturn[$szVariable] = $szValue;
1441    
1442         $szVariable = "KEYMAP_CURSOR_POS_Y";
1443         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
1444         $aReturn[$szVariable] = $szValue;
1445    
1446         $szCmd = '';
1447         if ($this->isVarSet('NAV_CMD'))
1448         $szCmd = $this->getVar('NAV_CMD');
1449         $szVariable = "NAV_CMD";
1450         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
1451         $aReturn[$szVariable] = $szValue;
1452    
1453         $szVariable = "KEYMAP_NAV_ALLOW_RECTANGLE";
1454         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
1455         $aReturn[$szVariable] = $szValue;
1456    
1457         $szVariable = "KEYMAP_DHTML_MODE";
1458         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"ZOOM\">\n";
1459         $aReturn[$szVariable] = $szValue;
1460    
1461         return $aReturn;
1462     }
1463    
1464     /**
1465     * adjustBBox()
1466     *
1467     * Postcondition:  This function adjusts a user supplied pixel bbox to the correct ratio
1468     *                 of the mainmap
1469     *
1470     */
1471     function adjustBBox( &$nMinx, &$nMiny, &$nMaxx, &$nMaxy, $nMapWidth, $nMapHeight  )
1472     {
1473         // calculate center pixel values
1474         $nMidX = (($nMaxx - $nMinx)/2) + $nMinx;
1475         $nMidY = (($nMaxy - $nMiny)/2) + $nMiny;
1476    
1477         // adjust according to which dimension is furthest out
1478         if ( ($nMaxx-$nMinx)/$nMapWidth > ($nMaxy-$nMiny)/$nMapHeight )
1479         {
1480             // calculate the pixel width of zoom box
1481             $nPixDist = $nMaxx - $nMinx;
1482    
1483             // determine main map width and height ratio
1484             $dMainMapRatio = $nMapHeight/$nMapWidth;
1485    
1486             // convert the pixel values to be in the same ratio as the main map
1487             $nConvertedPixWidth =  $nPixDist;
1488             $nConvertedPixHeight = $dMainMapRatio * $nPixDist;
1489         }
1490         else
1491         {
1492             // calculate the pixel height of zoom box
1493             $nPixDist = $nMaxy - $nMiny;
1494    
1495             // determine main map width and height ratio
1496             $dMainMapRatio = $nMapWidth/$nMapHeight;
1497    
1498             // convert the pixel values to be in the same ratio as the main map
1499             $nConvertedPixWidth =  $dMainMapRatio * $nPixDist;
1500             $nConvertedPixHeight = $nPixDist;
1501         }
1502    
1503         // update the coordinates
1504         $nMinx = $nMidX - ($nConvertedPixWidth/2);
1505         $nMaxx = $nMidX + ($nConvertedPixWidth/2);
1506         $nMiny = $nMidY - ($nConvertedPixHeight/2);
1507         $nMaxy = $nMidY + ($nConvertedPixHeight/2);
1508    
1509     }
1510 }
1511 ?>
Note: See TracBrowser for help on using the browser.