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 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 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:


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.


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


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 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.


9 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 😀

  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 :).

  7. 7 joie July 16, 2010 at 8:24 am

    Hi. My classmates and I are doing a project for Sahana. We are going to customize it as our school requirement. I wanted to ask about how to add OpenLayers as the GIS mapping for Sahana. I really don’t know how to do it.

    Your help will be gladly appreciated. Thank you.


  8. 8 boing boing May 7, 2013 at 11:38 pm

    Great blog you have here.. It’s difficult to find excellent writing like yours nowadays. I really appreciate people like you! Take care!!

  9. 9 Suzanna June 28, 2013 at 11:50 pm

    What’s up to all, the contents present at this website are genuinely amazing for people knowledge, well, keep up the nice work fellows.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: