Build AJAX-Based Web Maps Using ka-Map
by Tyler Mitchell
|
Pages: 1, 2, 3, 4, 5, 6
Adding a Key/Reference Map
You don't need to have a reference in your application, but to add one you
need a REFERENCE section in the global.map file.
You can add it right after the SCALEBAR...END section:
REFERENCE
EXTENT -180 -90 180 90
SIZE 241 121
IMAGE data/keymap.png
COLOR -1 -1 -1
OUTLINECOLOR 255 0 0
END
This example requires a reference map image named keymap.png to
be saved with the cloud image and shapefiles in the data folder. You can download
Figure 2 and use it for your reference map image.

Figure 2. Reference map image (keymap.png):
ka-Map will automatically show the current extent of the map using a red box on top of the reference map, as shown in Figure 1.
Troubleshooting
Can't get ka-Map working? Here are some tips for improving your experience or finding problems with your setup.
- Use a more recent web browser version. AJAX is highly dependent on recent web browser technology.
-
Check your web server aliases to make sure that the /ka-map/ directory
points to the proper
.../kamap-0.1.1/htdocsfolder. -
Test your map file by running
shp2img. If you don't have this utility already, you should get it. If it doesn't work with your map file, then ka-Map won't either.shp2imgalso comes as part of the precompiled FWTools collection. -
Check your temporary/cache folders. For simplicity, your map file
IMAGEPATHandIMAGEURLshould correspond to the$szBaseCacheDirsetting inconfig.php. If no files are being made in that folder, then your settings are to blame. Ensure that the web server is allowed to write in that folder. -
Turn on the debug option in config.php. Setting
$bDebug = truewill draw the rectangles of the tiles on top of your map data. If nothing appears, then you have a problem with the ka-Map installation. - Consider using a more recent version of ka-Map (e.g. using CVS). There are bug fixes, performance improvements, and new features in newer versions, but I have found 0.1.1 to be the most stable at present.
-
More recent versions of ka-Map come with a
scriptsfolder, which the user that the web server runs as must be able to write into that folder. - If you are familiar with JavaScript, you could also install a debugger that can help you debug configuration problems. Consider using Mozilla's Venkman debugger.
-
If you are still having problems, you can try loading the
init.phpfile in your URL to see more runtime settings and errors (e.g.http://localhost:8080/ka-map/init.php).
Further Adventures
Testing the Map in a Web Context
The settings used in the global.map file are very simple, but in a production
environment you may need to change them. You may end up wanting to change the
IMAGEPATH and IMAGEURL settings to put your temporary map images somewhere
else on your filesystem. These settings also specify where the web browser
will be able to find the map images. If you have IMAGEURL set wrong, then the
web server won't be able to make the map available to the user.
The best way to test for this is to write a simple PHP script and test running
it. Take the following PHP script, save it to your kamap-0.1.1/htdocs folder
and then load it up using a URL like http://localhost:8080/ka-map/maptest.php.
<?php
dl('php_mapscript.'.PHP_SHLIB_SUFFIX );
$oMap = ms_newMapObj( 'global.map' );
$oImg = $oMap->draw();
$szURL = $oImg->saveWebImage();
echo "<img src=$szURL>";
?>
If you map image is drawn, then things will work in ka-Map. If not, then you have some problems with your map file.