Build AJAX-Based Web Maps Using ka-Map
by Tyler Mitchell
|
Pages: 1, 2, 3, 4, 5, 6
Security Warning
In a production or public environment it is not a good practice to put your globa file
in a publicly accessible location. This example is meant only for internal
testing and to keep folder management to a minimum for getting started. Because l.mapglobal.map is
in the htdocs folder it can be accessed through a web URL. This
is a particularly bad idea if you are connecting to databases in your map file
where database user names may be explicitly set.
This commonly used folder structure keeps the htdocs folder separate
from the map file and data:
.../kamap-0.1.1/map/global.map
.../kamap-0.1.1/data/countries_simpl.*
.../kamap-0.1.1/data/day_clouds.*
Web Server Aliases
To allow your web server to use ka-Map, you need to set some web server aliases.
With FGS and MS4W this may be done for you automatically. Otherwise, you will
need to add something like this to your web server configuration, for example
in an Apache httpd.conf file:
Alias /ka-map/ "/opt/fgs/apps/kmap-0.1.1/htdocs/"
<Directory "/opt/fgs/apps/kmap-0.1.1/htdocs/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
This allows you to enter a simple URL (/ka-map/) and have it
point to the file path where ka-Map content is stored.
ka-Map Configuration Files
ka-Map comes with one main configuration file:
.../kamap-0.1.1/htdocs/config.php
Once the handful of settings in this file are set, you will have a fully functioning
ka-Map application. For FGS and MS4W packages, many of these settings
are already taken care of. There is documentation throughout config.php to
guide you through each setting. There are only three different types of settings
that you really need to worry about.
Setting Up Library Pointers
ka-Map requires both PHP MapScript and the GD module for PHP. config.php needs
to point to these library files (around line 23):
$szPHPMapScriptModule = 'php_mapscript_cvs_rel.4.6.0.beta2.'.PHP_SHLIB_SUFFIX;
$szPHPGDModule = 'php_gd.'.PHP_SHLIB_SUFFIX;
The first one points to the file name prefix for the PHP MapScript library.
This looks somewhat verbose, because the above example uses a very recent beta
version of PHP MapScript. You change this to match the filename for the php_mapscript library
that is on your system. In many cases this looks as simple as:
$szPHPMapScriptModule = 'php_mapscript.'.PHP_SHLIB_SUFFIX;
Or:
$szPHPMapScriptModule = 'php_mapscript_46.'.PHP_SHLIB_SUFFIX;
The documentation says that the pointer to php_gd will likely
need to be changed to php_gd2, if running on Windows.
Note that the PHP_SHLIB_SUFFIX variable will automatically add
the filename suffix. For example, .so or .dll, depending
on your operating system. Don't include the suffix in this filename setting.
Adding Your Map File
To have your custom application show up in ka-Map, you need to tell ka-Map
where your map file is, as well as some other map-specific settings. Around
line 80 you'll find the settings for the $aszMapFiles array. It
will already be set to use a mapping application called GMap,
but you can change it to match this one:
$aszMapFiles = array(
"weather" => array( "Global Weather",
"/opt/fgs/apps/kamap-0.1.1/htdocs/global.map",
array( 100000000, 50000000, 15000000 ),
"PNG")
);
This sets up an array of information, all stored within the $aszMapFiles variable.
The first setting is the name of the ka-Map instance you are configuring; in
this case the application is called "weather" and uses the global.map file
you created earlier. This name is used in other places, as you will see later
on.
The second setting is the text, "Global Weather", which is the
name that will appear in the drop-down box on the web page. From this drop-down
you can choose which map file you want to use.
The third setting points to the location of the global.map file.
Depending on how your system is configured, this will vary. In this example, global.map was
stored in the ka-Map htdocs folder, alongside the data folder.
Setting Map Scales and Image Formats
The fourth setting is a list of scales. These are the map scales that the user will be allowed to view the map at. For example, 1,000 would be the map scale as a representative fraction of 1:1,000. This means that one inch on screen represents one thousand inches on the ground.
The final setting is the output image format to be used, in this case "PNG".
Note that there are two closing parentheses, one after "PNG", which
ends the settings for the "weather" array. If you want to add
more than one instance to ka-Map, put a comma after this parenthesis and create
a whole new instance key.
The second closing parenthesis is on a separate line and followed by a semicolon.
It ends the settings for the $aszMapFiles array.
With those changes made to config.php, you are ready to test
your map.