OpenLayers OpenLayers

KaMap Layer


The ka-Map layer for OpenLayers allows you to display output from a ka-Map backend in OpenLayers.

ka-Map is a mapping solution released under the BSD license, available from MapTools.org. ka-Map is designed to work closely with Mapserver to avoid the deficiencies that Mapserver can present when working in a tiled situation, and also caches the tiles it creates for faster re-display in the future.

In order to use ka-Map in OpenLayers, you will need a properly configured tile.php from the ka-Map distribution. In the examples/ directory of OpenLayers, there is a PHP file, named kamap.txt, which can be used rather than extracting the neccesary files from the ka-Map distribution.

Configuration variables to set in the ka-Map.txt/tile.php file:

$szPHPMapScriptModule = 'php_mapscript.'.PHP_SHLIB_SUFFIX;
$szPHPGDModule = 'php_gd.'.PHP_SHLIB_SUFFIX;

These should be the module names of your php modules for Mapscript and GD.

$aszMapFiles = array(
  "world"   => array( "World", "/path/to/your/mapfile",
               array( 10000  ), # in openlayers, the scale array doesn't matter.
               "PNG24")
 
); 

This is where you define your layers in ka-Map. You can make this array larger -- the lowercase 'world' is the key name, which you will use in your KaMap layer initializer. The first argument is a human-readable name, which is not used by OpenLayers. The second argument is the location of your Mapserver mapfile. The third element is not important, but is designed to be used by ka-Map. The fourth argument is the format type you wish to use: options are PNG24, GIF, JPEG, or PNG.

Once you have modified these variables, you should be able to create a new constructor for your KaMap layer:

 map = new OpenLayers.Map( $('map'), {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805", 'controls': [], units: "m"  } );
 var buildings = new OpenLayers.Layer.KaMap("Buildings", "http://boston.freemap.in/tile.php?", {'g':'buildings', 'map': 'boston-new'});

The arguments here are:

  • Layer name. This is used for the layer switcher.
  • URL of tile.php, which is the location that you put kamap.txt at.
  • params: 'g' is the 'group' of layers which you wish to display, 'map' is the key you used in the MapFiles array (in the example above, 'world').

You will also need to set a 'units' value on your map, if your data is projected into some unit other than degrees.

Once you have set this, you should be able to treat the map just like you would any other layer, without any ill effects.

A minimal example of a working ka-Map layer in OpenLayers would look like:

<html>
<head>
<script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>
</head>
<body>
  <div style="width:100%; height:100%" id="map"></div>
  <script defer="defer" type="text/javascript">
    var map = new OpenLayers.Map('map');
    var jpl = new OpenLayers.Layer.KaMap( "Satellite",
                    "http://www.openlayers.org/world/index.php", {g: "satellite", map: "world"});
    map.addLayer(jpl);
    map.zoomToFullExtent();
  </script>
</body>
</html>