Howto Make Openlayers In Sahana Show Multi Layers (Overlay)

Proof of Concept

  1. I’m using Sahana version 0.6.2 stable release
  2. Sahana read the configuration from MySQL and then file configuration. So, we have to change all configuration in config values (Administration > Config Utils > Config Values) and then edit conf.inc file.
  3. Sahana only provides 2 layers in openlayers (this is the default configuration). You can see this in Config Values, if we want more layers, we should add manually in conf.inc file.
  4. Sahana produce a map in JPG format. We all know that JPG does not support transparency, so we should change this with PNG. We will adding some PHP codes in openlayers_fns.php.

Adding More than 2 Layers

Check Config Values (administration > Config Utils > Config Values) and find this line:

ol_wms

Change this with your own. lets try 5 for this. It mean’s there are 5 layers will be shown in openlayers. first layer is a based layer and the others become an overlay layers.

ol_wms

Second, find this line at Config Values (Administration > Config Utils > Config Values):

ol_wms_1_layers
.......
.......
.......
ol_wms_2_url

Focus to this line :

ol_wms_1_layers (fill with layer name, this is a based layer)
ol_wms_1_transparency (fill with 0)
ol_wms_1_url (fill with WMS URL)

ol_wms_2_layers (fill with layer name)
ol_wms_2_transparency (fill with 1)
ol_wms_2_url (fill with WMS URL)

As i wrote before, sahana only provides 2 layers. If we want to add more than 2 layers then we should add them manually.

Now, we have to edit conf.inc. Find this line:

$conf['ol_wms_1_description'] = '';
.............
.............
$conf['ol_wms_2_max'] = '';

Copy and change the [2]’s part (duplicating to 5) and fill with your own. See this example.

Modified Openlayers_fns.php

Now we will add some php codes and ‘hack’ openlayers_fns.php file. We have to modified cause this file produce a map in JPG format and we will change to PNG. See this file.

Go to line 121 openlayers_fns.php file and you will see this:

echo "var wmslayer$i = new OpenLayers.Layer.WMS( \"$name\",\n";
echo "\"$url\",\n";
echo "{layers: '$layers'} );\n";

Change with this one:

echo "var wmslayer$i = new OpenLayers.Layer.WMS( \"$name\",\n";
echo "\"$url\",\n";
if($conf["ol_wms_".$i."_transparency"] == 1) { $trans = ", transparent: \"true\""; }
echo "{layers: '$layers' $trans , format: \"image/png\"} );\n";

This new code will produce a map in PNG format.

Save that file, login to Sahana and check your maps. This is the result.

result sahana

Hope that helps.

6 Responses to “Howto Make Openlayers In Sahana Show Multi Layers (Overlay)”


  1. 1 Diki April 9, 2008 at 11:18 am

    Pencerahan langsung dari masternya ^^, thx mas Dudi. Minta ijin dicomot step-stepnya buat ditaro di wiki iosn-fossgis yaks.

  2. 2 dudi April 9, 2008 at 11:50 am

    kalo ada yang kurang step-nya ditambahin lagi ya dik, soalnya itu juga ngebut ngerjainnya :D

  3. 3 Mifan April 11, 2008 at 2:07 am

    Hi Dudi,
    Nice info. I created the OL plugin along with Fran Boon for Sahana.. and yes, we did limit it to 2 layers at the time…
    Anyways, we’re now working on a layer catalog module: an admin module to manage the OL layers, where we can dynamically add any number of layers.. this is work in progress at the moment, but should be completed pretty soon. In the meantime, we’d appreciate your involvement with the Sahana GIS work, so come join the community :)
    Keep up the good work.

  4. 4 Ravindra April 11, 2008 at 10:09 am

    Nice work! keep it up, i think you should contribute this how to the Sahana WIKI also. So please join the community :)

  5. 5 Amenorrhoea June 19, 2008 at 10:49 pm

    Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

    cheers, Amenorrhoea!!

  6. 6 dudi July 4, 2008 at 10:43 pm

    #Amenorrhoea: sorry for my english :) .


Leave a Reply




a