1 |
<?php |
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
function getRemoteFile( $szFilename, $szExtension = "" ) |
---|
13 |
{ |
---|
14 |
if (strlen($szFilename) < 7) |
---|
15 |
{ |
---|
16 |
$szLocalFile = $szFilename; |
---|
17 |
} |
---|
18 |
else if (strcasecmp( "http://", substr($szFilename, 0, 7 )) != 0) |
---|
19 |
{ |
---|
20 |
$szLocalFile = $szFilename; |
---|
21 |
} |
---|
22 |
else |
---|
23 |
{ |
---|
24 |
|
---|
25 |
$aszFile = @file( $szFilename ); |
---|
26 |
if ($aszFile === false) |
---|
27 |
{ |
---|
28 |
$_SESSION["gErrorManager"]->seError(ERR_ERROR, "Error retrieving remote file ($szFilename), please ensure the URL is correct" ); |
---|
29 |
$szLocalFile = false; |
---|
30 |
} |
---|
31 |
else |
---|
32 |
{ |
---|
33 |
$szLocalFile = tempnam($_SESSION['gszTmpPath'], "remote").".".$szExtension; |
---|
34 |
$fh = @fopen($szLocalFile, "w"); |
---|
35 |
if ($fh === false) |
---|
36 |
{ |
---|
37 |
$szLocalFile = false; |
---|
38 |
$_SESSION["gErrorManager"]->setError(ERR_ERROR, "Error creating local copy ($szLocalFile) of remote file ($szFilename), please ensure permissions are correctly set." ); |
---|
39 |
} |
---|
40 |
else |
---|
41 |
{ |
---|
42 |
$nbLine = count($aszFile); |
---|
43 |
|
---|
44 |
for($i=0; $i<$nbLine; $i++) |
---|
45 |
{ |
---|
46 |
fwrite($fh, $aszFile[$i]); |
---|
47 |
} |
---|
48 |
fclose($fh); |
---|
49 |
} |
---|
50 |
} |
---|
51 |
} |
---|
52 |
return $szLocalFile; |
---|
53 |
} |
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 |
function loadContext( $szContextName, $bAllowResize = true ) |
---|
68 |
{ |
---|
69 |
|
---|
70 |
$szLocalContext = $this->getRemoteFile( $szContextName, ".cml" ); |
---|
71 |
|
---|
72 |
$oMap = ms_newMapObj( "" ); |
---|
73 |
$bResult = $oMap->loadMapContext( $szLocalContext ); |
---|
74 |
if ($oMap->numlayers == 0) |
---|
75 |
{ |
---|
76 |
$szText = $oMLT->get( "4", "ERROR: Invalid Context file" ); |
---|
77 |
$this->moErrorManager->setError(ERR_WARNING, $szText); |
---|
78 |
|
---|
79 |
} |
---|
80 |
else |
---|
81 |
{ |
---|
82 |
|
---|
83 |
for ($i = 0; $i < $this->moMapSession->oMap->numlayers; $i++) |
---|
84 |
{ |
---|
85 |
$oLayer = $this->moMapSession->oMap->getLayer( $i ); |
---|
86 |
$oLayer->set( "status", MS_DELETE ); |
---|
87 |
} |
---|
88 |
|
---|
89 |
|
---|
90 |
$nLayers = $oMap->numlayers; |
---|
91 |
|
---|
92 |
for ($i=0; $i<$nLayers; $i++) |
---|
93 |
{ |
---|
94 |
ms_newLayerObj($this->moMapSession->oMap, $oMap->getlayer($i)); |
---|
95 |
$oLayer = $this->moMapSession->oMap->getLayer( $i ); |
---|
96 |
} |
---|
97 |
|
---|
98 |
$this->moMapSession->oMap->set( "name", $oMap->name ); |
---|
99 |
$this->moMapSession->oMap->setmetadata( "wms_title", $oMap->getmetadata( "wms_title" ) ); |
---|
100 |
if ($bAllowResize) |
---|
101 |
{ |
---|
102 |
$this->moMapSession->oMap->set( "width", $oMap->width ); |
---|
103 |
$this->moMapSession->oMap->set( "height", $oMap->height ); |
---|
104 |
} |
---|
105 |
$this->moMapSession->oMap->setProjection( $oMap->getprojection(), MS_TRUE ); |
---|
106 |
$this->moMapSession->oMap->extent->setExtent( $oMap->extent->minx, $oMap->extent->miny, $oMap->extent->maxx, $oMap->extent->maxy ); |
---|
107 |
$this->moMapSession->oMap->setMetadata( "original_extents", ""); |
---|
108 |
$this->moMapSession->oMap->setMetadata( "original_projection", "" ); |
---|
109 |
$this->moMapSession->oMap->web->set( "minscale", $oMap->web->minscale ); |
---|
110 |
$this->moMapSession->oMap->web->set( "maxscale", $oMap->web->maxscale ); |
---|
111 |
|
---|
112 |
|
---|
113 |
$oError = ms_GetErrorObj(); |
---|
114 |
while($oError && $oError->code > 0) |
---|
115 |
{ |
---|
116 |
if (isset($this->moErrorManager)) |
---|
117 |
{ |
---|
118 |
$szMsg = getMapServerErrorMessage( $oError ); |
---|
119 |
$this->moErrorManager->setError(ERR_WARNING, $szMsg); |
---|
120 |
} |
---|
121 |
echo "<!-- ".$szMsg." -->"; |
---|
122 |
|
---|
123 |
$oError = $oError->next(); |
---|
124 |
} |
---|
125 |
$this->mszCurrentState = $this->moMapSession->saveState(); |
---|
126 |
$_SESSION["gszCurrentState"] = $this->mszCurrentState; |
---|
127 |
$this->moMapSession->restoreState($this->mszCurrentState, |
---|
128 |
$this->mszMapFile, |
---|
129 |
dirname($this->mszMapFile)); |
---|
130 |
|
---|
131 |
} |
---|
132 |
} |
---|
133 |
?> |
---|