1 |
<?php |
---|
2 |
/** |
---|
3 |
* CWC application |
---|
4 |
* |
---|
5 |
* @project CWC |
---|
6 |
* @revision $Id: preview.php,v 1.3 2004/11/16 15:23:40 pspencer Exp $ |
---|
7 |
* @purpose This page contains supporting php functions. |
---|
8 |
* @author William A. Bronsema, C.E.T. (bronsema@dmsolutions.ca) |
---|
9 |
* @copyright |
---|
10 |
* <b>Copyright (c) 2001, 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 |
/***************************************************************************** |
---|
31 |
* $Log: preview.php,v $ |
---|
32 |
* Revision 1.3 2004/11/16 15:23:40 pspencer |
---|
33 |
* bug MT 377: renamed PrintWidget to PrintProduction |
---|
34 |
* |
---|
35 |
* Revision 1.2 2004/04/25 04:20:39 pspencer |
---|
36 |
* fixed file references |
---|
37 |
* |
---|
38 |
* Revision 1.1 2004/04/23 16:51:01 pspencer |
---|
39 |
* moved preview.php to PrintProduction/preview.php |
---|
40 |
* |
---|
41 |
* Revision 1.32 2003/10/27 20:46:19 sfournier |
---|
42 |
* Overwrite main branch with 1.1 stuff |
---|
43 |
* |
---|
44 |
* Revision 1.23.2.3 2003/10/21 01:32:00 pspencer |
---|
45 |
* changed scalebar background to white bc ms40 imageobj pasteimage with transparency doesn't work. |
---|
46 |
* |
---|
47 |
* Revision 1.23.2.2 2003/10/15 21:04:57 pspencer |
---|
48 |
* fixes to work with Chameleon 1.1 |
---|
49 |
* |
---|
50 |
* Revision 1.23.2.1 2003/08/05 15:08:33 zak |
---|
51 |
* removed tests requiring wms layers and metadata in map |
---|
52 |
* (bug 2161) |
---|
53 |
* |
---|
54 |
* Revision 1.23 2003/04/30 15:18:55 bronsema |
---|
55 |
* fixed "invalid syntax" javascript error by removing unecessary and |
---|
56 |
* un-intialized variables |
---|
57 |
* |
---|
58 |
* Revision 1.22 2003/04/30 14:58:07 bronsema |
---|
59 |
* removed SWF output option |
---|
60 |
* |
---|
61 |
* Revision 1.21 2003/04/30 14:35:11 bronsema |
---|
62 |
* fixed map size problem |
---|
63 |
* |
---|
64 |
* Revision 1.20 2003/04/30 14:20:04 bronsema |
---|
65 |
* Updated pdf support |
---|
66 |
* |
---|
67 |
* Revision 1.19 2003/04/29 20:48:39 sacha |
---|
68 |
* Fixed the scalebar preview in jpeg. |
---|
69 |
* |
---|
70 |
* Revision 1.18 2003/04/28 19:18:39 sacha |
---|
71 |
* Use right header for JPEG |
---|
72 |
* |
---|
73 |
* Revision 1.17 2003/04/25 19:47:46 daniel |
---|
74 |
* Add the ability to set the output type for scalebar |
---|
75 |
* |
---|
76 |
* Revision 1.16 2003/04/17 19:10:51 sacha |
---|
77 |
* Change the preview to reflect the exact map size from the main page. |
---|
78 |
* |
---|
79 |
* Revision 1.15 2003/04/16 18:51:09 sacha |
---|
80 |
* Fixed few bugs related to the rendering preview of a map |
---|
81 |
* |
---|
82 |
* Revision 1.14 2003/04/08 20:09:58 sacha |
---|
83 |
* Fixed few bug related to print |
---|
84 |
* |
---|
85 |
* Revision 1.13 2003/04/08 19:08:27 sacha |
---|
86 |
* Added error report to production dialog and also fixed a bug about PDF format. Only offer the choice if available |
---|
87 |
* |
---|
88 |
* Revision 1.12 2003/03/05 20:59:47 sacha |
---|
89 |
* Fixed a directory bug when copying image |
---|
90 |
* |
---|
91 |
* Revision 1.11 2003/02/24 19:32:34 sacha |
---|
92 |
* Don't display layer temp_points in legend. Also fixed a few potential bugs in add point |
---|
93 |
* |
---|
94 |
* Revision 1.10 2003/01/30 13:49:58 sacha |
---|
95 |
* Changed the session management |
---|
96 |
* |
---|
97 |
* Revision 1.9 2003/01/08 16:43:12 bronsema |
---|
98 |
* Updated code to remove the dot that was appearing on labels with no |
---|
99 |
* symbol |
---|
100 |
* |
---|
101 |
* Revision 1.8 2003/01/07 20:25:08 bronsema |
---|
102 |
* Updated function header comments to the doxygen style |
---|
103 |
* |
---|
104 |
* Revision 1.7 2003/01/07 20:04:20 bronsema |
---|
105 |
* Included serveral misc settings |
---|
106 |
* |
---|
107 |
* Revision 1.6 2003/01/07 18:33:45 bronsema |
---|
108 |
* Added legend |
---|
109 |
* |
---|
110 |
* Revision 1.5 2003/01/03 18:51:01 bronsema |
---|
111 |
* Moved the download file capabiltiy to the production page. |
---|
112 |
* |
---|
113 |
* Revision 1.4 2002/12/18 19:07:31 bronsema |
---|
114 |
* Fixed problem with empty shape-file and temp layer. |
---|
115 |
* |
---|
116 |
* Revision 1.3 2002/12/17 18:14:13 bronsema |
---|
117 |
* fixed misc bugs in production |
---|
118 |
* |
---|
119 |
* Revision 1.2 2002/12/15 04:59:45 bronsema |
---|
120 |
* Changed resolution from 300 to 150 & added cross-hair to keymap |
---|
121 |
* |
---|
122 |
* Revision 1.1 2002/10/28 15:07:31 bronsema |
---|
123 |
* Initial addition |
---|
124 |
* |
---|
125 |
* Revision 1.1 2002/08/12 20:26:18 bronsema |
---|
126 |
* Added delayed drawing functionality to map production. |
---|
127 |
* |
---|
128 |
*****************************************************************************/ |
---|
129 |
// set output flag if not defined |
---|
130 |
if ( !isset( $bFileOnly ) ) $bFileOnly = false; |
---|
131 |
|
---|
132 |
// define flag if necessary |
---|
133 |
if ( !defined( "LOAD_MAPSESSION" ) ) |
---|
134 |
{ |
---|
135 |
define("LOAD_MAPSESSION", 1); |
---|
136 |
} |
---|
137 |
|
---|
138 |
// include session info |
---|
139 |
include_once("../session.inc.php"); |
---|
140 |
|
---|
141 |
// give lots of time to draw the map |
---|
142 |
set_time_limit( 300 ); |
---|
143 |
|
---|
144 |
/* ============================================================================ |
---|
145 |
* Build an array with the HTTP GET or POST parameters. |
---|
146 |
* ========================================================================= */ |
---|
147 |
//$http_form_vars = sizeof( $_POST ) > 0 ? $_POST : |
---|
148 |
// ( sizeof($_GET) > 0 ? $_GET : array("") ); |
---|
149 |
|
---|
150 |
// determine the output format |
---|
151 |
switch ( $http_form_vars["selImageFormat"] ) |
---|
152 |
{ |
---|
153 |
case "GIF": |
---|
154 |
$szHeaderType = "Content-type: image/gif"; |
---|
155 |
$sz_format = "gif"; |
---|
156 |
$gsz_dl_ext = ".gif"; |
---|
157 |
$gsz_dl_name = "map.gif"; |
---|
158 |
break; |
---|
159 |
case "JPEG": |
---|
160 |
$szHeaderType = "Content-type: image/jpeg"; |
---|
161 |
$sz_format = "jpeg"; |
---|
162 |
$gsz_dl_ext = ".jpg"; |
---|
163 |
$gsz_dl_name = "map.jpg"; |
---|
164 |
break; |
---|
165 |
case "WBMP": |
---|
166 |
$szHeaderType = "Content-type: image/wbmp"; |
---|
167 |
$sz_format = "wbmp"; |
---|
168 |
$gsz_dl_ext = ".bmp"; |
---|
169 |
$gsz_dl_name = "map.bmp"; |
---|
170 |
break; |
---|
171 |
case "PNG24": |
---|
172 |
$szHeaderType = "Content-type: image/png"; |
---|
173 |
$sz_format = "png24"; |
---|
174 |
$gsz_dl_ext = ".png"; |
---|
175 |
$gsz_dl_name = "map.png"; |
---|
176 |
break; |
---|
177 |
case "PNG": |
---|
178 |
$szHeaderType = "Content-type: image/png"; |
---|
179 |
$sz_format = "png"; |
---|
180 |
$gsz_dl_ext = ".png"; |
---|
181 |
$gsz_dl_name = "map.png"; |
---|
182 |
break; |
---|
183 |
case "PDF": |
---|
184 |
$szHeaderType = "Content-type: application/x-pdf"; |
---|
185 |
$sz_format = "png"; // render as png!!!!!! |
---|
186 |
$gsz_dl_ext = ".pdf"; |
---|
187 |
$gsz_dl_name = "map.pdf"; |
---|
188 |
break; |
---|
189 |
//case "SWF": |
---|
190 |
//$szHeaderType = "Content-type: application/x-shockwave-flash"; |
---|
191 |
//$sz_format = "swf"; |
---|
192 |
//$gsz_dl_ext = ".swf"; |
---|
193 |
//$gsz_dl_name = "map.swf"; |
---|
194 |
//break; |
---|
195 |
default: |
---|
196 |
$szHeaderType = "Content-type: image/png"; |
---|
197 |
$sz_format = "png"; |
---|
198 |
$gsz_dl_ext = ".png"; |
---|
199 |
$gsz_dl_name = "map.png"; |
---|
200 |
break; |
---|
201 |
} |
---|
202 |
|
---|
203 |
// set the output type |
---|
204 |
if ($oMapSession->oMap->selectoutputformat( $sz_format ) == MS_FAILURE && |
---|
205 |
isset($_SESSION['gErrorManager'])) |
---|
206 |
$_SESSION['gErrorManager']->setError(ERR_WARNING, |
---|
207 |
"Type \"$sz_format\" should correspond to one of the output formats declared in the map file"); |
---|
208 |
|
---|
209 |
// render the image |
---|
210 |
$oImage = renderImage( $oMapSession, |
---|
211 |
$_SESSION['gszTmpPath'].$http_form_vars['sid'].".txt" ); |
---|
212 |
|
---|
213 |
// output map to screen or file |
---|
214 |
if ( $bFileOnly ) |
---|
215 |
{ |
---|
216 |
// save image |
---|
217 |
$urlMainMapFile = $oImage->saveWebImage(); |
---|
218 |
|
---|
219 |
// generate a unique name for the tmp download file |
---|
220 |
$szTmpDLName = $http_form_vars['sid'].$gsz_dl_ext; |
---|
221 |
$szDownloadURL = $_SESSION["gszTmpWebPath"].$szTmpDLName; |
---|
222 |
$szDownloadFile = $_SESSION["gszTmpImgPath"].$szTmpDLName; |
---|
223 |
|
---|
224 |
// get the temp image path and filename |
---|
225 |
$szTmpImage = realpath($oMapSession->oMap->web->imagepath.basename($urlMainMapFile)); |
---|
226 |
|
---|
227 |
// convert the image to pdf if necessary |
---|
228 |
if ( $http_form_vars["selImageFormat"] == "PDF" ) |
---|
229 |
{ |
---|
230 |
// check to see if pdf support is loaded |
---|
231 |
if (PHP_OS == "WINNT" || PHP_OS == "WIN32") |
---|
232 |
{ |
---|
233 |
if (!extension_loaded("pdf")) dl("php_pdf.dll"); |
---|
234 |
} |
---|
235 |
|
---|
236 |
// create handle for new PDF document |
---|
237 |
$pdf = pdf_new(); |
---|
238 |
|
---|
239 |
// open a file |
---|
240 |
pdf_open_file($pdf,$szDownloadFile); |
---|
241 |
|
---|
242 |
// start a new page |
---|
243 |
pdf_begin_page($pdf, $ng_map_width, $ng_map_height); |
---|
244 |
|
---|
245 |
// position image |
---|
246 |
$image = pdf_open_image_file($pdf, "png", $szTmpImage); |
---|
247 |
pdf_place_image($pdf, $image, 0, 0, 1); |
---|
248 |
|
---|
249 |
// end page |
---|
250 |
pdf_end_page($pdf); |
---|
251 |
|
---|
252 |
// close and save file |
---|
253 |
pdf_close($pdf); |
---|
254 |
|
---|
255 |
} |
---|
256 |
else |
---|
257 |
{ |
---|
258 |
// copy the new image file to the unique name |
---|
259 |
if ( file_exists( $szDownloadFile ) ) unlink( $szDownloadFile ); |
---|
260 |
copy( $szTmpImage, $szDownloadFile); |
---|
261 |
} |
---|
262 |
} |
---|
263 |
else |
---|
264 |
{ |
---|
265 |
// output to screen |
---|
266 |
header( $szHeaderType ); |
---|
267 |
$urlMainMap = $oImage->saveImage(""); |
---|
268 |
} |
---|
269 |
|
---|
270 |
/** |
---|
271 |
* This function processes the given information and draws the image |
---|
272 |
* accordingly. |
---|
273 |
* |
---|
274 |
* @param $oMapSession object - The mapsession object to process. |
---|
275 |
* @param $szSettings string - Path and filename of the settings file. |
---|
276 |
* @return object - The image handle for the generated image. |
---|
277 |
**/ |
---|
278 |
function renderImage( $oMapSession, $szSettings ) |
---|
279 |
{ |
---|
280 |
global $ng_map_width; |
---|
281 |
global $ng_map_height; |
---|
282 |
|
---|
283 |
// include the settings file |
---|
284 |
include( $szSettings ); |
---|
285 |
|
---|
286 |
// set the pixel amount to have above and below the map |
---|
287 |
$n_pix_whitespace_top = 40; |
---|
288 |
$n_pix_whitespace_bot = 40; |
---|
289 |
$n_pix_whitespace_left = 10; |
---|
290 |
$n_pix_whitespace_right = 10; |
---|
291 |
|
---|
292 |
// get the map object |
---|
293 |
$oMap = $oMapSession->getMapObj(); |
---|
294 |
|
---|
295 |
// check for any layers that are on and not deleted |
---|
296 |
$bNoLayers = true; |
---|
297 |
for ($i=0;$i<$oMap->numlayers;$i++) |
---|
298 |
{ |
---|
299 |
// create layer object |
---|
300 |
$oLayer = $oMap->getlayer($i); |
---|
301 |
|
---|
302 |
// check name |
---|
303 |
if ($oLayer->status == MS_ON) |
---|
304 |
{ |
---|
305 |
// a layer was found that is on |
---|
306 |
$bNoLayers = false; |
---|
307 |
break; |
---|
308 |
} |
---|
309 |
} |
---|
310 |
|
---|
311 |
// check flag |
---|
312 |
if ($bNoLayers) return false; |
---|
313 |
|
---|
314 |
// set the scale value |
---|
315 |
$n_scale_value = 1; |
---|
316 |
|
---|
317 |
// record the current backcolour |
---|
318 |
$n_map_red = intval($oMap->imagecolor->red); |
---|
319 |
$n_map_green = intval($oMap->imagecolor->green); |
---|
320 |
$n_map_blue = intval($oMap->imagecolor->blue); |
---|
321 |
|
---|
322 |
// reset the background colour |
---|
323 |
$oMap->imagecolor->setRGB($n_map_red,$n_map_green,$n_map_blue); |
---|
324 |
|
---|
325 |
// set the map width and height |
---|
326 |
$oMap->set( "width", intval($txtWidthPix) ); |
---|
327 |
$oMap->set( "height", intval($txtHeightPix) ); |
---|
328 |
|
---|
329 |
$map_width = $oMap->width+0; // leave the +0 to make a COPY of the value |
---|
330 |
$map_height =$oMap->height+0; // leave the +0 to make a COPY of the value |
---|
331 |
|
---|
332 |
// draw the map |
---|
333 |
$o_img_map = $oMap->draw(); |
---|
334 |
|
---|
335 |
//now draw the legend, scalebar and north arrow |
---|
336 |
//calculate positions for each as they could overlap |
---|
337 |
//and will be stacked |
---|
338 |
|
---|
339 |
//the amount to inset from the edge and between stacked elements in pixels |
---|
340 |
$nInsetWidth = 5; |
---|
341 |
|
---|
342 |
$nLegendWidth = 0; |
---|
343 |
$nLegendHeight = 0; |
---|
344 |
$nScalebarWidth = 0; |
---|
345 |
$nScalebarHeight = 0; |
---|
346 |
$nLegendX = 0; |
---|
347 |
$nLegendY = 0; |
---|
348 |
$nScalebarX = 0; |
---|
349 |
$nScalebarY = 0; |
---|
350 |
|
---|
351 |
//record the max width at each position so we can center things |
---|
352 |
//use the first one to have centering in each of the 6 positions |
---|
353 |
//use the second one to center in each of the 3 columns |
---|
354 |
//if you use the second one, change the code in the prepare image |
---|
355 |
//sections to use substr($itemPos, 1,1]) |
---|
356 |
$aWidths = array( "TL"=>0, "TC"=>0, "TR"=>0, "BL"=>0, "BC"=>0, "BR"=>0); |
---|
357 |
|
---|
358 |
|
---|
359 |
//prepare the scalebar image |
---|
360 |
if ( $chkScalebarElem == 1 ) |
---|
361 |
{ |
---|
362 |
$szOldImageType = $oMap->outputformat->name; |
---|
363 |
$oMap->selectOutputFormat("PNG"); |
---|
364 |
$oScalebarImg = $oMap->drawScaleBar(); |
---|
365 |
$oMap->selectOutputFormat($szOldImageType); |
---|
366 |
|
---|
367 |
$nScalebarHeight = $oScalebarImg->height * $n_scale_value; |
---|
368 |
$nScalebarWidth = $oScalebarImg->width * $n_scale_value; |
---|
369 |
$scalebarPos = $selScalebarPos; |
---|
370 |
$aWidths[substr($scalebarPos, 0, 2)] = max($aWidths[$scalebarPos], |
---|
371 |
$nScalebarWidth); |
---|
372 |
|
---|
373 |
$vOffset = 0 + (10 * $n_scale_value); |
---|
374 |
if ( isset( $legendPos ) && $legendPos == $scalebarPos ) |
---|
375 |
{ |
---|
376 |
$vOffset = $nLegendHeight + $nInsetWidth + (10 * $n_scale_value); |
---|
377 |
} |
---|
378 |
if ( substr( $scalebarPos, 0, 1 ) == "T" ) |
---|
379 |
$nScalebarY = $nInsetWidth + $vOffset; |
---|
380 |
else |
---|
381 |
$nScalebarY = $map_height - $vOffset - $nScalebarHeight; |
---|
382 |
|
---|
383 |
$hOffset = ($aWidths[substr($scalebarPos,0,2)] - $nScalebarWidth) / 2; |
---|
384 |
if ( substr( $scalebarPos, 1, 1 ) == "L" ) //left |
---|
385 |
$nScalebarX = $nInsetWidth + $hOffset; |
---|
386 |
elseif( substr( $scalebarPos, 1, 1 ) == "C" ) //center |
---|
387 |
$nScalebarX = ($map_width / 2) - ($nScalebarWidth / 2); |
---|
388 |
else |
---|
389 |
$nScalebarX = $map_width-$nInsetWidth-$nScalebarWidth-$hOffset; |
---|
390 |
|
---|
391 |
$o_img_map = draw_scalebar( $oMap, $o_img_map, $nScalebarX, $nScalebarY, |
---|
392 |
$n_scale_value); |
---|
393 |
} |
---|
394 |
|
---|
395 |
//prepare the legend image |
---|
396 |
if ( $chkLegendElem == 1 ) |
---|
397 |
{ |
---|
398 |
// include the utility functions necessary to draw the legend |
---|
399 |
include_once( "./production_draw_legend.php" ); |
---|
400 |
|
---|
401 |
// get list of layer to draw |
---|
402 |
$an_legend_list = getLegendList( $oMap ); |
---|
403 |
|
---|
404 |
// draw legend according to resolution |
---|
405 |
$oLegendImage = getLegendImage($oMap, $an_legend_list,8, |
---|
406 |
$szFontDir."/".$selLegendFontFile, $selLegendFont, |
---|
407 |
$n_scale_value); |
---|
408 |
|
---|
409 |
$nLegendHeight = $oLegendImage->height; |
---|
410 |
$nLegendWidth = $oLegendImage->width; |
---|
411 |
$legendPos = $selLegendPos; |
---|
412 |
$aWidths[substr($legendPos, 0, 2)] = max($aWidths[$legendPos], |
---|
413 |
$nLegendWidth); |
---|
414 |
//$aWidths[substr($legendPos, 1, 1)] = max($aWidths[$legendPos], |
---|
415 |
// $nLegendWidth); |
---|
416 |
} |
---|
417 |
|
---|
418 |
//position the legend image and draw it |
---|
419 |
if ( $chkLegendElem == 1 ) |
---|
420 |
{ |
---|
421 |
if ( substr( $legendPos, 0, 1 ) == "T" ) |
---|
422 |
$nLegendY = $nInsetWidth; |
---|
423 |
else |
---|
424 |
$nLegendY = $map_height - $nInsetWidth - $nLegendHeight; |
---|
425 |
|
---|
426 |
//$hOffset = ( $aWidths[substr($legendPos, 0, 2)] - $nLegendWidth ) / 2; |
---|
427 |
$hOffset = 0; |
---|
428 |
if ( substr( $legendPos, 1, 1 ) == "L" ) //left |
---|
429 |
$nLegendX = $nInsetWidth + $hOffset; |
---|
430 |
elseif( substr( $legendPos, 1, 1 ) == "C" ) //center |
---|
431 |
$nLegendX = ($map_width / 2) - ($nLegendWidth / 2); |
---|
432 |
else |
---|
433 |
$nLegendX = $map_width - $nInsetWidth - $nLegendWidth - $hOffset; |
---|
434 |
|
---|
435 |
draw_legend( $oMap, $o_img_map, $oLegendImage, $nLegendX, |
---|
436 |
$nLegendY ); |
---|
437 |
} |
---|
438 |
|
---|
439 |
// set the map width and height |
---|
440 |
$d_map_width = intval($txtWidthPix) + $n_pix_whitespace_left + |
---|
441 |
$n_pix_whitespace_right; |
---|
442 |
$d_map_height = intval($txtHeightPix) + $n_pix_whitespace_top - |
---|
443 |
$n_pix_whitespace_bot; |
---|
444 |
|
---|
445 |
// record width and height with white spaces for the map cell |
---|
446 |
$ng_map_width = $d_map_width + $n_pix_whitespace_left + |
---|
447 |
$n_pix_whitespace_right; |
---|
448 |
$ng_map_height = $d_map_height + $n_pix_whitespace_top + |
---|
449 |
$n_pix_whitespace_bot; |
---|
450 |
|
---|
451 |
// set the new width of the map |
---|
452 |
$oMap->set("width",$ng_map_width); |
---|
453 |
|
---|
454 |
// set the new height of the map |
---|
455 |
$oMap->set("height",$ng_map_height); |
---|
456 |
|
---|
457 |
// set the background colour to white |
---|
458 |
$oMap->imagecolor->setRGB(255,255,255); |
---|
459 |
|
---|
460 |
// draw the canvas |
---|
461 |
$o_img_canvas = $oMap->prepareImage(); |
---|
462 |
|
---|
463 |
// set back width of the map |
---|
464 |
$oMap->set("width",$map_width); |
---|
465 |
|
---|
466 |
// set back height of the map |
---|
467 |
$oMap->set("height",$map_height); |
---|
468 |
|
---|
469 |
// draw the title on the map if necessary |
---|
470 |
if ( $chkTitleElem == 1 ) |
---|
471 |
{ |
---|
472 |
drawLabel( $oMap, $o_img_canvas, $ng_map_width/2, 35 * $n_scale_value, |
---|
473 |
$n_scale_value, $txtTitleDesc, |
---|
474 |
$selTitleFont, $selFontSize, MS_UC ); |
---|
475 |
} |
---|
476 |
|
---|
477 |
// add copyright notice |
---|
478 |
drawLabel($oMap, $o_img_canvas, $ng_map_width - (5 * $n_scale_value), |
---|
479 |
$ng_map_height - (5 * $n_scale_value), |
---|
480 |
$n_scale_value, ""/*? Put your copyright code here, ". |
---|
481 |
"something, something. All rights reserved"*/, |
---|
482 |
$selTitleFont,8, MS_UL ); |
---|
483 |
|
---|
484 |
// draw the neat line around the map if required |
---|
485 |
if ( $chkNeatElem == 1 ) |
---|
486 |
draw_neat_line( $oMap, $o_img_canvas, $n_pix_whitespace_left, $n_pix_whitespace_top); |
---|
487 |
$urlMainMap = $o_img_map->saveWebImage(); |
---|
488 |
|
---|
489 |
// add bounding box coordinates |
---|
490 |
drawBoundingCoords( $oMap, $o_img_canvas, $n_pix_whitespace_left, |
---|
491 |
$n_pix_whitespace_right, $n_pix_whitespace_top, |
---|
492 |
$n_pix_whitespace_bot, $ng_map_width, $ng_map_height, |
---|
493 |
$n_scale_value, $selLegendFont ); |
---|
494 |
|
---|
495 |
// add scale |
---|
496 |
drawScaleLabel($oMap, $o_img_canvas, $n_pix_whitespace_left, |
---|
497 |
$n_pix_whitespace_right, $n_pix_whitespace_top, |
---|
498 |
$n_pix_whitespace_bot, $ng_map_width, $ng_map_height, |
---|
499 |
$n_scale_value, $szFontDir."/".$selLegendFont ); |
---|
500 |
|
---|
501 |
// paste the map onto the canvas |
---|
502 |
$o_img_canvas->pasteImage( $o_img_map, -1, $n_pix_whitespace_left, |
---|
503 |
$n_pix_whitespace_top); |
---|
504 |
|
---|
505 |
// return image handle |
---|
506 |
return $o_img_canvas; |
---|
507 |
|
---|
508 |
// end render_map function |
---|
509 |
} |
---|
510 |
|
---|
511 |
/** |
---|
512 |
* This function will draw the map into the given map image. |
---|
513 |
* |
---|
514 |
* @param oMap object - Map file object. |
---|
515 |
* @param oImage object - Image object to draw the rectangle on. |
---|
516 |
* @return void. |
---|
517 |
**/ |
---|
518 |
function draw_neat_line($oMap,$oImage, $nPosX, $nPosY) |
---|
519 |
{ |
---|
520 |
// create temp layer |
---|
521 |
$o_tmp_layer = ms_newLayerObj($oMap); |
---|
522 |
$o_tmp_layer->set("name", "temp_layer"); |
---|
523 |
$o_tmp_layer->set("type", MS_LAYER_LINE); |
---|
524 |
$o_tmp_layer->set("status", MS_OFF); |
---|
525 |
$o_tmp_layer->set("transform", MS_FALSE); |
---|
526 |
$o_tmp_class = ms_newClassObj($o_tmp_layer); |
---|
527 |
|
---|
528 |
// create style object |
---|
529 |
$o_style = ms_newStyleObj( $o_tmp_class ); |
---|
530 |
|
---|
531 |
// set the class colour |
---|
532 |
$o_style->color->setRGB( 0,0,0 ); |
---|
533 |
|
---|
534 |
// create new rectangle object |
---|
535 |
$o_rect = ms_newRectObj(); |
---|
536 |
|
---|
537 |
// set to full extents |
---|
538 |
$o_rect->setExtent($nPosX-1, $nPosY-1, $oMap->width+$nPosX, $oMap->height+$nPosY); |
---|
539 |
|
---|
540 |
// draw the rectangle onto the map |
---|
541 |
$o_rect->draw($oMap, $o_tmp_layer, $oImage, 0, ""); |
---|
542 |
|
---|
543 |
// delete temp layer |
---|
544 |
$o_tmp_layer->set("status", MS_DELETE); |
---|
545 |
|
---|
546 |
// end draw_neat_line function |
---|
547 |
} |
---|
548 |
|
---|
549 |
/** |
---|
550 |
* This function draws the given text at the location specified. |
---|
551 |
* |
---|
552 |
* @param $oMap object - The current map object. |
---|
553 |
* @param $oImage object - The image object to paste onto. |
---|
554 |
* @param $n_x_pos integer - The x position of the label. |
---|
555 |
* @param $n_y_pos integer - The y position of the label. |
---|
556 |
* @param $n_scale_factor integer - The scale factor to apply to the label. |
---|
557 |
* @param $szText string - The text to output. |
---|
558 |
* @param $szFontName string - The font to use. |
---|
559 |
* @param $nFontSize integer - The font sixe to use. |
---|
560 |
* @param $nPosition integer - The label position. |
---|
561 |
* @return boolean - True if successful, false if not. |
---|
562 |
**/ |
---|
563 |
function drawLabel( $oMap,$oImage, $n_x_pos, $n_y_pos, $n_scale_factor, |
---|
564 |
$szText, $szFontName ,$nFontSize, $nPosition ) |
---|
565 |
{ |
---|
566 |
// create temp layer |
---|
567 |
$o_tmp_layer = ms_newLayerObj($oMap); |
---|
568 |
$o_tmp_layer->set("name", "temp_layer"); |
---|
569 |
$o_tmp_layer->set("type", MS_LAYER_ANNOTATION); |
---|
570 |
$o_tmp_layer->set("status", MS_OFF); |
---|
571 |
$o_tmp_layer->set("transform", MS_FALSE); |
---|
572 |
$o_tmp_layer->set("labelitem", "test_label"); |
---|
573 |
$o_tmp_layer->set("labelcache", MS_OFF); |
---|
574 |
$o_tmp_class = ms_newClassObj($o_tmp_layer); |
---|
575 |
|
---|
576 |
// create style object |
---|
577 |
$o_style = ms_newStyleObj( $o_tmp_class ); |
---|
578 |
|
---|
579 |
// set the class colour |
---|
580 |
$o_style->color->setRGB( -1,-1,-1 ); |
---|
581 |
|
---|
582 |
// set the label properties |
---|
583 |
$o_tmp_class->label->color->setRGB( 0,0,0 ); |
---|
584 |
$o_tmp_class->label->set("size" , $nFontSize ); |
---|
585 |
$o_tmp_class->label->set("font" , $szFontName ); |
---|
586 |
$o_tmp_class->label->set("type" , MS_TRUETYPE ); |
---|
587 |
$o_tmp_class->label->set("position" , $nPosition ); |
---|
588 |
$o_tmp_class->label->set("partials" , MS_FALSE ); |
---|
589 |
|
---|
590 |
// create new point object |
---|
591 |
$o_point = ms_newPointObj(); |
---|
592 |
|
---|
593 |
//position |
---|
594 |
$o_point->setXY($n_x_pos,$n_y_pos); |
---|
595 |
|
---|
596 |
// draw the point onto the map |
---|
597 |
$o_point->draw($oMap, $o_tmp_layer, $oImage, 0, restoreChars( $szText )); |
---|
598 |
|
---|
599 |
// return success |
---|
600 |
return true; |
---|
601 |
|
---|
602 |
// end drawLabel function |
---|
603 |
} |
---|
604 |
|
---|
605 |
/** |
---|
606 |
* Draw the scalebar for the map onto an image at a given position. |
---|
607 |
* |
---|
608 |
* @param oMap object - The objec map. |
---|
609 |
* @param oImage object - The image to draw the legend onto. |
---|
610 |
* @param nX int - The left edge of the scalebar. |
---|
611 |
* @param nY int - The top edge of the scalebar. |
---|
612 |
* @param n_scale_factor integer - Scale factor to apply to title. |
---|
613 |
* @param szImageType - Image output type. |
---|
614 |
* @return mixed - The image object passed in or false if it failed. |
---|
615 |
**/ |
---|
616 |
function draw_scalebar( $oMap, $oImage, $nX, $nY, $n_scale_factor) |
---|
617 |
{ |
---|
618 |
// create scalebar object |
---|
619 |
$oScalebar = $oMap->scalebar; |
---|
620 |
|
---|
621 |
// set the intervals |
---|
622 |
$oScalebar->set("intervals", 5); |
---|
623 |
|
---|
624 |
// set the size of the scalebar according to scale |
---|
625 |
$oLabel = $oScalebar->label; |
---|
626 |
if ($n_scale_factor == 1) |
---|
627 |
{ |
---|
628 |
//no scale |
---|
629 |
$oLabel->set("size", MS_TINY); |
---|
630 |
} |
---|
631 |
else |
---|
632 |
{ |
---|
633 |
// scale |
---|
634 |
$oLabel->set("size", MS_GIANT); |
---|
635 |
$oScalebar->set("width", $oScalebar->width * $n_scale_factor); |
---|
636 |
$oScalebar->set("height", $oScalebar->height * $n_scale_factor); |
---|
637 |
} |
---|
638 |
|
---|
639 |
// set status and transparency |
---|
640 |
$oScalebar->set("status",MS_ON); |
---|
641 |
$oScalebar->set("transparent",MS_TRUE); |
---|
642 |
$oScalebar->setimagecolor(255,255,255); |
---|
643 |
|
---|
644 |
//ask the map to draw the legend onto an image object |
---|
645 |
$szOldImageType = $oMap->outputformat->name; |
---|
646 |
$oMap->selectOutputFormat("PNG"); |
---|
647 |
$oScalebarImage = $oMap->drawScaleBar(); |
---|
648 |
$oMap->selectOutputFormat($szOldImageType); |
---|
649 |
|
---|
650 |
//get the size of the map and legend for validation |
---|
651 |
$nMapWidth = $oImage->width; |
---|
652 |
$nMapHeight = $oImage->height; |
---|
653 |
$nScalebarWidth = $oScalebarImage->width; |
---|
654 |
$nScalebarHeight = $oScalebarImage->height; |
---|
655 |
|
---|
656 |
//top & left validation |
---|
657 |
if ($nX < 0) $nX = 0; |
---|
658 |
if ($nY < 0) $nY = 0; |
---|
659 |
|
---|
660 |
//bottom & right validation |
---|
661 |
if ( ($nX + $nScalebarWidth) > $nMapWidth ) |
---|
662 |
$nX = $nMapWidth - $nScalebarWidth; |
---|
663 |
if ( ($nY + $nScalebarHeight) > $nMapHeight ) |
---|
664 |
$nY = $nMapHeight - $nScalebarHeight; |
---|
665 |
|
---|
666 |
//paste the scalebar onto the image at the desired location |
---|
667 |
//TODO: fix me when pasteImage is fixed (bug 463) |
---|
668 |
$oImage->pasteImage( $oScalebarImage, 0xffffff, $nX, $nY); |
---|
669 |
|
---|
670 |
return $oImage; |
---|
671 |
} |
---|
672 |
|
---|
673 |
/** |
---|
674 |
* Postcondition: This function formats the bounding box coordinates and |
---|
675 |
* pastes them onto the give image object. |
---|
676 |
* |
---|
677 |
* @param $oMap object - The main map object. |
---|
678 |
* @param $oCanvas object - the image object to paste to. |
---|
679 |
* @param $nWsLeft integer - The size of the left whitespace margin in pixels. |
---|
680 |
* @param $nWsRight integer - The size of the right whitespace margin in pixels. |
---|
681 |
* @param $nWsTop integer - The size of the top whitespace margin in pixels. |
---|
682 |
* @param $nWsBottom integer - The size of the bot whitespace margin in pixels. |
---|
683 |
* @param $nMapWidth integer - The width of the overall canvas. |
---|
684 |
* @param $nMapHeight integer - The height of the overall canvas. |
---|
685 |
* @param $dScale double - The scale factor to be applied. |
---|
686 |
* @param $szFontName string - The font to use. |
---|
687 |
* @return void. |
---|
688 |
**/ |
---|
689 |
function drawBoundingCoords( $oMap, $oCanvas, $nWsLeft, $nWsRight, $nWsTop, |
---|
690 |
$nWsBottom, $nMapWidth, $nMapHeight, $dScale, |
---|
691 |
$szFontName ) |
---|
692 |
{ |
---|
693 |
// determine the ratio of the pixel width to extent width |
---|
694 |
$nRatio = abs( $oMap->width / ($oMap->extent->maxx - $oMap->extent->minx) ); |
---|
695 |
|
---|
696 |
// process accordingly |
---|
697 |
if ( $nRatio > 1 ) |
---|
698 |
$nNbDecimal = log( $nRatio )/log( 10 ) + 1; |
---|
699 |
else |
---|
700 |
$nNbDecimal = 0; |
---|
701 |
|
---|
702 |
// format bounding coordinates for labels |
---|
703 |
$dMinX = number_format($oMap->extent->minx, $nNbDecimal, ".", ""); |
---|
704 |
$dMinY = number_format($oMap->extent->miny, $nNbDecimal, ".", ""); |
---|
705 |
$dMaxX = number_format($oMap->extent->maxx, $nNbDecimal, ".", ""); |
---|
706 |
$dMaxY = number_format($oMap->extent->maxy, $nNbDecimal, ".", ""); |
---|
707 |
|
---|
708 |
// draw the labels |
---|
709 |
drawLabel( $oMap, $oCanvas, $nWsLeft, $nMapHeight - $nWsBottom + 6, |
---|
710 |
$dScale, "x: ".$dMinX, $szFontName, 8, MS_LR ); |
---|
711 |
drawLabel( $oMap, $oCanvas, $nWsLeft, $nMapHeight - $nWsBottom + 19, |
---|
712 |
$dScale, "y: ".$dMinY, $szFontName, 8, MS_LR ); |
---|
713 |
drawLabel( $oMap, $oCanvas, $nMapWidth - $nWsRight, $nWsTop - 21, |
---|
714 |
$dScale, "x: ".$dMaxX, $szFontName, 8, MS_UL ); |
---|
715 |
drawLabel( $oMap, $oCanvas, $nMapWidth - $nWsRight, $nWsTop - 7, |
---|
716 |
$dScale, "y: ".$dMaxY, $szFontName, 8, MS_UL ); |
---|
717 |
|
---|
718 |
// end drawCoundingCoords() function |
---|
719 |
} |
---|
720 |
|
---|
721 |
/** |
---|
722 |
* This function restores the characters that give problems when passed through |
---|
723 |
* a URL. |
---|
724 |
* |
---|
725 |
* @param $szString string - The string to fix. |
---|
726 |
* @param $bHTML boolean - Optional flag to indicate if HTML quote is needed. |
---|
727 |
* @return string - The restored string. |
---|
728 |
**/ |
---|
729 |
function restoreChars( $szString, $bHTML = false ) |
---|
730 |
{ |
---|
731 |
// check for #!# and replace with \ |
---|
732 |
$szString = str_replace( "#!#", "\\", $szString ); |
---|
733 |
|
---|
734 |
// check for #!!# and replace with ' |
---|
735 |
$szString = str_replace( "#!!#", "'", $szString ); |
---|
736 |
|
---|
737 |
// check for #!!!# and replace with " |
---|
738 |
if ( $bHTML ) |
---|
739 |
$szString = str_replace( "#!!!#", """, $szString ); |
---|
740 |
else |
---|
741 |
$szString = str_replace( "#!!!#", "\"", $szString ); |
---|
742 |
|
---|
743 |
// return string |
---|
744 |
return $szString; |
---|
745 |
|
---|
746 |
// end restorChars() function |
---|
747 |
} |
---|
748 |
|
---|
749 |
/** |
---|
750 |
* Postcondition: This function formats the scale label and |
---|
751 |
* pastes it onto the give image object. |
---|
752 |
* |
---|
753 |
* @param $oMap object - The main map object. |
---|
754 |
* @param $oCanvas object - the image object to paste to. |
---|
755 |
* @param $nWsLeft integer - The size of the left whitespace margin in pixels. |
---|
756 |
* @param $nWsRight integer - The size of the right whitespace margin in pixels. |
---|
757 |
* @param $nWsTop integer - The size of the top whitespace margin in pixels. |
---|
758 |
* @param $nWsBottom integer - The size of the bot whitespace margin in pixels. |
---|
759 |
* @param $nMapWidth integer - The width of the overall canvas. |
---|
760 |
* @param $nMapHeight integer - The height of the overall canvas. |
---|
761 |
* @param $dScale double - The scale factor to be applied. |
---|
762 |
* @param $szFontName string - The font to use. |
---|
763 |
* @return void. |
---|
764 |
**/ |
---|
765 |
function drawScaleLabel( $oMap, $oCanvas, $nWsLeft, $nWsRight, $nWsTop, |
---|
766 |
$nWsBottom, $nMapWidth, $nMapHeight, $dScale, |
---|
767 |
$szFontName ) |
---|
768 |
{ |
---|
769 |
// format scale |
---|
770 |
$nScale = number_format($oMap->scale, 0, ".", ""); |
---|
771 |
|
---|
772 |
// draw the label |
---|
773 |
drawLabel( $oMap, $oCanvas, $nMapWidth - $nWsRight, |
---|
774 |
$nMapHeight - $nWsBottom + 6, |
---|
775 |
$dScale, "Scale 1:".$nScale, $szFontName, 8, MS_LL ); |
---|
776 |
|
---|
777 |
// end drawScaleLabel() function |
---|
778 |
} |
---|
779 |
?> |
---|