FAQ: Tips and tricks

Clean URL's when using config paramaters

Using Apache rewrite mechanisms

If you want to launch the application with different configuration settings like


you can achieve "cleaner" looking URL's by using Apache rewrite rules and .htaccess files (just google for "apache .htaccess"). This requires the configuration setting in the Apache configuration file (usually httpd.conf) under your <directory> entry

  AllowOverride All

Then add in the .htaccess file delivered with p.mapper the lines

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ ?config=$1 [L,QSA]

Then you can start the application as


This will re-write the address to


Using POST method from an HTML form

An alternative approach is to use an HTML form with POST as submit method, like

<title>p.mapper - start application with different config files</title>
<h2> Examples how to start the application from a form with different config files</h2>
<form method="POST" action="map.phtml">
    <!-- using config_default.xml -->
    <input type="radio" name="config" value="default" onclick="submit()">Default</input><p>
    <!-- using config_dev.xml -->
    <input type="radio" name="config" value="dev" onclick="submit()">Development</input><p>

The disadvantage, however, of this approach is that the URL that appears in the browser address Window is always the same. So this method does not work with direct URL's inserted in the browser address bar, it absolutely requires being launched via an HTML form.

Default layers visible on map but not in legend/TOC

If a layer should always be visible on the map but not selectable/visible in legend or TOC (e.g. copyright, north arrow, background image layer) the easiest solution is to define for the layer in the map file


and don't reference the layer in the config XML file. This way it is always drawn by Mapserver logic and never switched off by p.mapper logic.

Optimization image output format:

Why when a vector layer is selected the output png image size is about 30kb and if a raster is selected the output png image size is about 500kb. The same example in jpeg output size is about 120kb in all case but quality is less than png.

JPEG generally is better for raster layer but you could have eg. scanned black/white maps that are also raster layers but are smaller when in PNG and look better than in JPEG. Also thematic raster layers (like DEM/slopes, landuse raster data) using CLASS definitions in Mapserver are normally better displayed in PNG than JPEG.

Remove temporary files from /tmp directory

p.mapper creates various temporary files under the directory specified in the map file at WEB - IMAGEPATH

to remove them automatically add a shell script file rm_tempfiles under /etc/cron.daily or /etc/cron.hourly that contains the following lines:

 find /home/www/tmp -name "*.png" -amin +60 -exec rm -f {} \;
 find /home/www/tmp -name "*.jp*" -amin +60 -exec rm -f {} \;
 find /home/www/tmp -name "*.tif" -amin +60 -exec rm -f {} \;
 find /home/www/tmp -name "*.zip" -amin +300 -exec rm -f {} \;
 find /home/www/tmp -name "*.tar" -amin +300 -exec rm -f {} \;
 find /home/www/tmp -name "*.tmp" -amin +300 -exec rm -f {} \;
 find /home/www/tmp -name "*.pdf" -amin +300 -exec rm -f {} \;
 find /home/www/tmp -name "*.xls" -amin +300 -exec rm -f {} \;
 find /home/www/tmp -name "sess_*" -amin +300 -exec rm -f {} \;

and set the file executable

  ~# chmod 755 rm_tempfiles

Setting up a common library container for multiple p.mapper applications

p.mapper currently requires to have all PHP and Javascript files inside the main application window. For multiple applications using the same PHP and JS code base this requires a multiple maintenance of these files. Most p.mapper applications differ just in the configuration (config_xyz.xml, map file, etc) and the CSS templates, so having them sharing the same libaries makes the maintenance of these applications easier, mainly for applying updates and bug fixes.

One way to work with this is the use of symbolic links. One could e.g. set up in the WWW root a common directory pmapper containing the javascript and incphp directories and symlinking them into the applications' tree. Like the following example

  + pmapper
    + incphp
    + javascript
  + application_1
    + incphp->../pmapper/incphp
    + javascript->../pmapper/javascript
  + application_2
    + incphp->../pmapper/incphp
    + javascript->../pmapper/javascript

While working with symlinks is something typical under UNIX, Windows does not seem to provide this functionality. But in fact, it does, just not well documented. See eg. this article how to work with 'junctions', the equivalent of symlinks under Windows.

Last modified 8 years ago Last modified on Jul 22, 2011, 3:21:51 PM