[ka-Map-users] "Starting kamap with different maps"
Steve Walker
walker at mfgis.com
Mon Mar 9 12:24:12 EST 2009
Regine,
In January of 2007 I posted a discussion of my modifications which may in
part meet your needs:
http://lists.maptools.org/pipermail/ka-map-users/2007-January/002555.html
Excertps from my post:
I would like to share here a strategy I have been pursuing which allows me
to configure Ka-Map! (in part) from the web page level (or more precisely,
from the web pages' file system path level).
The motivation was my desire to create a separate web page for multiple
cities, states, countries, etc., and to specify important Ka-Map!
parameters (namely the map name and map extent) associated with these
pages from the same file system path as the web page itself.
I have been able to achieve this by making changes to init.php and to
config.php (as spelled out below) as well as introducing new files named
variables.php and load_mapfile.php
<snip>
Variables.php (Miami)
<?
$szMap='Florida';
$extent='-80.32,25.71,-80.14,25.86;
// also, what ever else I want index.phtml to read - $cityName='Miami' etc.
?>
Variables.php (Springfield)
<?
$szMap='Illinois';
$extent='-89.754,39.654,-89.569,39.874';
// also, what ever else I want - $cityName='Springfild' etc.
?>
<snip>
Now that I have set up the variables.php files, I wish to modify init.php
to access them. (I have ka-map-1.0.b1-20060817 installed)
So, right at the very top of init.php I want to include my variables.php <?
include_once(variables.php); // should be modified to test for existence
include_once(/var/www/ka-map/include/config.php);
The first thing this has done is to have set the mapscript szMap variable
and thus chosen my map before config.php is ever read (more about
config.php modifications below). The second thing it has done assigned
the desired map extent to a variable which I then use to over-ride the
values set in the Mapserver map file (after all, the map extent of Florida
exceeds that of Miami, and I want to show Miami)
<snip>
include/config.php is read. Here is how I have implemented that:
Essentially, I modify config.php to test whether szMap is already set, and
if so to use that value rather than the one specified in config.php. In
other words, I have taken the map choice away from config.php and placed
it at the level of the web page, where (to me) it more appropriately
belongs.
In config.php, after the parameters are set and before the first map is
identified (around line 105) I include the following code:
// if the map name is set see if we can quick load it but if not we'll
want //to use the standard approach, below
if (!isset($szMap)) { $szMap='DEFAULTMAP'; }
$my_szMapPath='/var/www/ka-map/include/mapfiles/';
$my_szMapFile=$my_szMapPath.$szMap;
if (file_exists($my_szMapFile)) { include('load_mapfile.php'); }
// if the aszMapFiles variable has been set we can skip the parameters //
below. but if not, proceed as per the standard approach
<snip>
What I have done here is introduce a new folder include/mapfiles and a new
script load_mapfile.php
This does two things, first, it finds and loads my map file, and it
allows me to create and place as many map files as I wish without having
to edit config.php for each new map, thus avoiding the possibility of
wrecking the config.php with each edit.
<snip>
Each entry in mapfiles is simply a text file with four lines representing
the contents of the array variables which previously had to be hard-wired
into the code of config.php, such as:
Chicago
/var/www/us/map/Chicago.map
50000,25000,12500,6000,3000,1500,750
GIF
These are read into the same structure as the original config.php through
the use of my new load_mapfile.php script, which looks like this:
<?php
//load_mapfile.php
//Read a text file containing ka-map required map parameters in lieu //of
specifying them within config.php
//
//$szMap and $my_szMapFile validated by default before calling
$lines = file($my_szMapFile);
$thisTitle=rtrim($lines[0]);
$thisPath=rtrim($lines[1]);
$thisScaleList=rtrim($lines[2]);
$thisScales=explode(",",$thisScaleList);
$thisFormat=rtrim($lines[3]);
$thisArray = array(
'title' => $thisTitle,
'path' => $thisPath,
'scales' => $thisScales,
'format' => $thisFormat);
//
// Note that my array is really just a single map, so I have broken the
// chance to change maps from within the web page.
$aszMapFiles = array ( $szMap => $thisArray);
?> // end load_mapfile.php
<snip>
This is working fine with 50000+ web pages
I attempted to document the process in as much detail in the posting I
identified above and repeated here:
http://lists.maptools.org/pipermail/ka-map-users/2007-January/002555.html
But please let me know if you have any questions.
-Steve
>> 1. Is it possible to create a link between an mapfile-layer and an
>> MySQL-Database. I'd like to get it reacting as an mouseclick event in
>> kamap
>> for more information opening a window with this information from the
>> database. Do you have any idea how this could work?
>>
>>
> it is possible.
> I did it for some clients.
> you need to alter the map_query_float.php file and create a page tha
> dynamically get infos from MySQL.
> you naturally need to create a link between your shp and your DB.
> Think about doing a definitive solution using Postgresql/postgis.
>
>> 2. Is it possible to get kamap starting with different maps. I
>> considered
>> something like an variable that is transferred with the URL and tells
>> kamap
>> with which map it should start instead of getting this out of the
>> config.php
>> Does anybody already realised this idea or can give me a hint / keyword
>> what to do?
>>
>>
> it's already supported, if I've undestood what you mean.
> is this link what you are looking for?
> http://www.ominiverdi.org/ka-map/ka-map/htdocs/?map=europe
>
>
> ciao
> lorenzo
>
>
>
>> Thanks very much for your help!
>>
>> Regine
>> _______________________________________________
>> ka-Map-users mailing list
>> ka-Map-users at lists.maptools.org
>> http://lists.maptools.org/mailman/listinfo/ka-map-users
>>
>>
>
>
> ------------------------------
>
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users
>
>
> End of ka-Map-users Digest, Vol 47, Issue 5
> *******************************************
>
--
Steve Walker
Middle Fork Geographic Information Services
360.671.2505
walker at mfgis.com
http://mfgis.com
More information about the ka-Map-users
mailing list