| 1 |
<?php |
|---|
| 2 |
/********************************************************************** |
|---|
| 3 |
* |
|---|
| 4 |
* $Id: config.dist.php,v 1.10 2006/04/28 11:15:57 pspencer Exp $ |
|---|
| 5 |
* |
|---|
| 6 |
* purpose: configuration file for kaMap, hopefully well documented |
|---|
| 7 |
* |
|---|
| 8 |
* author: Paul Spencer (pspencer@dmsolutions.ca) |
|---|
| 9 |
* |
|---|
| 10 |
* TODO: |
|---|
| 11 |
* |
|---|
| 12 |
* - consider moving per-map configuration to metadata in map files |
|---|
| 13 |
* |
|---|
| 14 |
********************************************************************** |
|---|
| 15 |
* |
|---|
| 16 |
* Copyright (c) 2005, DM Solutions Group Inc. |
|---|
| 17 |
* |
|---|
| 18 |
* Permission is hereby granted, free of charge, to any person obtaining a |
|---|
| 19 |
* copy of this software and associated documentation files (the "Software"), |
|---|
| 20 |
* to deal in the Software without restriction, including without limitation |
|---|
| 21 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|---|
| 22 |
* and/or sell copies of the Software, and to permit persons to whom the |
|---|
| 23 |
* Software is furnished to do so, subject to the following conditions: |
|---|
| 24 |
* |
|---|
| 25 |
* The above copyright notice and this permission notice shall be included |
|---|
| 26 |
* in all copies or substantial portions of the Software. |
|---|
| 27 |
* |
|---|
| 28 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|---|
| 29 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|---|
| 30 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|---|
| 31 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|---|
| 32 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|---|
| 33 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|---|
| 34 |
* DEALINGS IN THE SOFTWARE. |
|---|
| 35 |
* |
|---|
| 36 |
**********************************************************************/ |
|---|
| 37 |
|
|---|
| 38 |
/****************************************************************************** |
|---|
| 39 |
* basic system configuration |
|---|
| 40 |
* |
|---|
| 41 |
* kaMap! uses PHP/MapScript and the PHP GD extension to |
|---|
| 42 |
* render tiles, and uses PHP/MapScript to generate initialization parameters |
|---|
| 43 |
* a legend, and a keymap from the selected map file. |
|---|
| 44 |
* |
|---|
| 45 |
* Make sure to set the correct module names for your PHP extensions. |
|---|
| 46 |
* |
|---|
| 47 |
* WINDOWS USERS: you will likely need to use php_gd2.dll instead of php_gd.dll |
|---|
| 48 |
*/ |
|---|
| 49 |
$szPHPMapScriptModule = 'php_mapscript.'.PHP_SHLIB_SUFFIX; |
|---|
| 50 |
$szPHPGDModule = 'php_gd.'.PHP_SHLIB_SUFFIX; |
|---|
| 51 |
|
|---|
| 52 |
/****************************************************************************** |
|---|
| 53 |
* tile generation parameters |
|---|
| 54 |
* |
|---|
| 55 |
* kaMap! generates tiles to load in the client application by first rendering |
|---|
| 56 |
* larger areas from the map file and then slicing them up into smaller tiles. |
|---|
| 57 |
* This approach reduces the overhead of loading PHP/MapScript and PHP GD and |
|---|
| 58 |
* drawing the map file. These larger areas are referred to as metaTiles in |
|---|
| 59 |
* the code. You can set the size of both the small tiles and the metaTiles |
|---|
| 60 |
* here. A reasonable size for the small tiles seems to be 200 pixels square. |
|---|
| 61 |
* Smaller tiles seem to cause problems in client browsers by causing too many |
|---|
| 62 |
* images to be created and thus slowing performance of live dragging. Larger |
|---|
| 63 |
* tiles take longer to download to the client and are inefficient. |
|---|
| 64 |
* |
|---|
| 65 |
* The number of smaller tiles that form a metaTile can also be configured. |
|---|
| 66 |
* This parameter allows tuning of the tile generator to ensure optimal |
|---|
| 67 |
* performance and for label placement. MapServer will produce labels only |
|---|
| 68 |
* within a rendered area. If the area is too small then features may be |
|---|
| 69 |
* labelled multiple times. If the area is too large, it may exceed MapServer,s |
|---|
| 70 |
* maximum map size (by default 2000x2000) or be too resource-intensive on the |
|---|
| 71 |
* server, ultimately reducing performance. |
|---|
| 72 |
*/ |
|---|
| 73 |
$tileWidth = 256; |
|---|
| 74 |
$tileHeight = 256; |
|---|
| 75 |
$metaWidth = 5; |
|---|
| 76 |
$metaHeight = 5; |
|---|
| 77 |
/* $metaBuffer = Buffer size in pixels to add around metatiles to avoid |
|---|
| 78 |
* rendering issues along the edge of the map image |
|---|
| 79 |
*/ |
|---|
| 80 |
$metaBuffer = 10; |
|---|
| 81 |
|
|---|
| 82 |
/****************************************************************************** |
|---|
| 83 |
* in-image debugging information - tile location, outlines etc. |
|---|
| 84 |
* to use this, you need to remove images from your cache first. This also |
|---|
| 85 |
* affects the meta tiles - if debug is on, they are not deleted. |
|---|
| 86 |
*/ |
|---|
| 87 |
$bDebug = false; |
|---|
| 88 |
|
|---|
| 89 |
/****************************************************************************** |
|---|
| 90 |
* aszMapFiles - an array of map files available to the application. How this |
|---|
| 91 |
* is used is determined by the application. Each map file is entered into |
|---|
| 92 |
* this array as a key->value pair. |
|---|
| 93 |
* |
|---|
| 94 |
* The key is the name to be used by the tile caching system to store cached |
|---|
| 95 |
* tiles within the base cache directory. This key should be a single word |
|---|
| 96 |
* that uniquely identifies the map. |
|---|
| 97 |
* |
|---|
| 98 |
* The value associated with each key is an array of three values. The first |
|---|
| 99 |
* value is a human-readable name to be presented to the user (should the |
|---|
| 100 |
* application choose to do so) and the second value is the path to the map |
|---|
| 101 |
* file. It is assumed that the map file is fully configured for use with |
|---|
| 102 |
* MapServer/MapScript as no error checking or setting of values is done. The |
|---|
| 103 |
* third value is an array of scale values for zooming. |
|---|
| 104 |
*/ |
|---|
| 105 |
|
|---|
| 106 |
$aszMapFiles = array( |
|---|
| 107 |
"world" => array( |
|---|
| 108 |
"title" => "World", |
|---|
| 109 |
"path" => "/path/to/your/mapfile.map", |
|---|
| 110 |
// Scales are used only to generate the cache using "precache.php", |
|---|
| 111 |
"scales" => array( 20000, 10000, 5000, 2500 ), |
|---|
| 112 |
"format" => "PNG24" |
|---|
| 113 |
) |
|---|
| 114 |
|
|---|
| 115 |
/* Add more elements to this array to offer multiple mapfiles */ |
|---|
| 116 |
|
|---|
| 117 |
); |
|---|
| 118 |
|
|---|
| 119 |
/****************************************************************************** |
|---|
| 120 |
* figure out which map file to use and set up the necessary variables for |
|---|
| 121 |
* the rest of the code to use. This does need to be done on every page load |
|---|
| 122 |
* unfortunately. |
|---|
| 123 |
* |
|---|
| 124 |
* szMap should be set to the default map file to use but can change if |
|---|
| 125 |
* this script is called with map=<mapname>. |
|---|
| 126 |
*/ |
|---|
| 127 |
$szMap = 'world'; |
|---|
| 128 |
|
|---|
| 129 |
/****************************************************************************** |
|---|
| 130 |
* kaMap! caching |
|---|
| 131 |
* |
|---|
| 132 |
* this is the directory within which kaMap! will create its tile cache. The |
|---|
| 133 |
* directory does NOT have to be web-accessible, but it must be writable by the |
|---|
| 134 |
* web-server-user and allow creation of both directories AND files. |
|---|
| 135 |
* |
|---|
| 136 |
* the tile caching system will create a separate subdirectory within the base |
|---|
| 137 |
* cache directory for each map file. Within the cache directory for each map |
|---|
| 138 |
* file, directories will be created for each group of layers. Within the group |
|---|
| 139 |
* directories, directories will be created at each of the configured scales |
|---|
| 140 |
* for the application (see mapfile configuration above.) |
|---|
| 141 |
*/ |
|---|
| 142 |
$szBaseCacheDir = "/var/cache/kamap/"; |
|---|
| 143 |
|
|---|
| 144 |
/***** END OF CONFIGURABLE STUFF - unless you know what you are doing *****/ |
|---|
| 145 |
/***** *****/ |
|---|
| 146 |
/***** *****/ |
|---|
| 147 |
/***** *****/ |
|---|
| 148 |
/***** END OF CONFIGURABLE STUFF - unless you know what you are doing *****/ |
|---|
| 149 |
|
|---|
| 150 |
if (isset($_REQUEST['map']) && isset($aszMapFiles[$_REQUEST['map']])) |
|---|
| 151 |
{ |
|---|
| 152 |
$szMap = $_REQUEST['map']; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
$szMapCacheDir = $szBaseCacheDir.$szMap."/"; |
|---|
| 156 |
$szMapName = $aszMapFiles[$szMap]["title"]; |
|---|
| 157 |
$szMapFile = $aszMapFiles[$szMap]["path"]; |
|---|
| 158 |
$anScales = $aszMapFiles[$szMap]["scales"]; |
|---|
| 159 |
|
|---|
| 160 |
if (isset($_REQUEST["i"])) { |
|---|
| 161 |
// Use the parameter 'i' to set the output format |
|---|
| 162 |
setOutputFormat( $_REQUEST["i"] ); |
|---|
| 163 |
} else { |
|---|
| 164 |
// Use the default output format indicated by $aszMapFiles array |
|---|
| 165 |
setOutputFormat($aszMapFiles[$szMap]["format"]); |
|---|
| 166 |
} |
|---|
| 167 |
|
|---|
| 168 |
/****************************************************************************** |
|---|
| 169 |
* output format of the map and resulting tiles |
|---|
| 170 |
* |
|---|
| 171 |
* The output format used with MapServer can greatly affect appearance and |
|---|
| 172 |
* performance. It is recommended to use an 8 bit format such as PNG |
|---|
| 173 |
* |
|---|
| 174 |
* NOTE: the tile caching code in tile.php is not configurable here. It |
|---|
| 175 |
* currently assumes that it is outputting 8bit PNG files. If you change to |
|---|
| 176 |
* PNG24 here then you will need to update tile.php to use the gd function |
|---|
| 177 |
* imagecreatetruecolor. If you change the output format to jpeg then |
|---|
| 178 |
* you would need to change imagepng() to imagejpeg(). A nice enhancement |
|---|
| 179 |
* would be to make that fully configurable from here. |
|---|
| 180 |
*/ |
|---|
| 181 |
function setOutputFormat($szFormat) |
|---|
| 182 |
{ |
|---|
| 183 |
switch(strtoupper($szFormat)) { |
|---|
| 184 |
case "PNG24": |
|---|
| 185 |
$GLOBALS['szMapImageFormat'] = 'PNG24'; //mapscript format name |
|---|
| 186 |
$GLOBALS['szMapImageCreateFunction'] = "imagecreatefrompng"; // appropriate GD function |
|---|
| 187 |
$GLOBALS['szImageExtension'] = '.png'; //file extension |
|---|
| 188 |
$GLOBALS['szImageCreateFunction'] = "imagecreatetruecolor"; //or imagecreatetruecolor if PNG24 ... |
|---|
| 189 |
$GLOBALS['szImageOutputFunction'] = "imagepng"; //or imagegif, imagejpeg ... |
|---|
| 190 |
$GLOBALS['szImageHeader'] = 'image/png'; //the content-type of the image |
|---|
| 191 |
break; |
|---|
| 192 |
case "GIF": |
|---|
| 193 |
$GLOBALS['szMapImageFormat'] = 'GIF'; //mapscript format name |
|---|
| 194 |
$GLOBALS['szMapImageCreateFunction'] = "imagecreatefromgif"; // appropriate GD function |
|---|
| 195 |
$GLOBALS['szImageExtension'] = '.gif'; //file extension |
|---|
| 196 |
$GLOBALS['szImageCreateFunction'] = "imagecreate"; //or imagecreatetruecolor if PNG24 ... |
|---|
| 197 |
$GLOBALS['szImageOutputFunction'] = "imagegif"; //or imagegif, imagejpeg ... |
|---|
| 198 |
$GLOBALS['szImageHeader'] = 'image/gif'; //the content-type of the image |
|---|
| 199 |
break; |
|---|
| 200 |
case "JPEG": |
|---|
| 201 |
$GLOBALS['szMapImageFormat'] = 'JPEG'; //mapscript format name |
|---|
| 202 |
$GLOBALS['szMapImageCreateFunction'] = "imagecreatefromjpeg"; // appropriate GD function |
|---|
| 203 |
$GLOBALS['szImageExtension'] = '.jpg'; //file extension |
|---|
| 204 |
$GLOBALS['szImageCreateFunction'] = "imagecreatetruecolor"; //or imagecreatetruecolor if PNG24 ... |
|---|
| 205 |
$GLOBALS['szImageOutputFunction'] = "imagejpeg"; //or imagegif, imagejpeg ... |
|---|
| 206 |
$GLOBALS['szImageHeader'] = 'image/jpeg'; //the content-type of the image |
|---|
| 207 |
break; |
|---|
| 208 |
case "PNG": |
|---|
| 209 |
$GLOBALS['szMapImageFormat'] = 'PNG'; //mapscript format name |
|---|
| 210 |
$GLOBALS['szMapImageCreateFunction'] = "imagecreatefrompng"; // appropriate GD function |
|---|
| 211 |
$GLOBALS['szImageExtension'] = '.png'; //file extension |
|---|
| 212 |
$GLOBALS['szImageCreateFunction'] = "imagecreate"; //or imagecreatetruecolor if PNG24 ... |
|---|
| 213 |
$GLOBALS['szImageOutputFunction'] = "imagepng"; //or imagegif, imagejpeg ... |
|---|
| 214 |
$GLOBALS['szImageHeader'] = 'image/png'; //the content-type of the image |
|---|
| 215 |
break; |
|---|
| 216 |
case "DITHERED": |
|---|
| 217 |
case "PNG8": |
|---|
| 218 |
$GLOBALS['szMapImageFormat'] = 'dithered'; |
|---|
| 219 |
$GLOBALS['szMapImageCreateFunction'] = "imagecreatefrompng"; |
|---|
| 220 |
$GLOBALS['szImageExtension'] = '.png'; |
|---|
| 221 |
$GLOBALS['szImageCreateFunction'] = "imagecreate"; |
|---|
| 222 |
$GLOBALS['szImageOutputFunction'] = "imagepng"; |
|---|
| 223 |
$GLOBALS['szImageHeader'] = 'image/png'; |
|---|
| 224 |
break; |
|---|
| 225 |
} |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
/** |
|---|
| 229 |
* create all directories in a directory tree - found on the php web site |
|---|
| 230 |
* under the mkdir function ... |
|---|
| 231 |
*/ |
|---|
| 232 |
function makeDirs($strPath, $mode = 0777) |
|---|
| 233 |
{ |
|---|
| 234 |
return is_dir($strPath) or ( makeDirs(dirname($strPath), $mode) and mkdir($strPath, $mode) ); |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
/** |
|---|
| 238 |
* This function replaces all special characters in the given string. |
|---|
| 239 |
* |
|---|
| 240 |
* @param szString string - The string to convert. |
|---|
| 241 |
* |
|---|
| 242 |
* @return string converted |
|---|
| 243 |
*/ |
|---|
| 244 |
function normalizeString($szString) |
|---|
| 245 |
{ |
|---|
| 246 |
// Normalize string by replacing all special characters |
|---|
| 247 |
// e.g. "http://my.host.com/cgi-bin/mywms?" |
|---|
| 248 |
// becomes "http___my_host_com_cgi_bin_mywms_" |
|---|
| 249 |
return preg_replace("/(\W)/", "_", $szString); |
|---|
| 250 |
} |
|---|
| 251 |
?> |
|---|