[mapguide-users] Re: Using Mapguide OS with OpenLayers Setting Layer Visibility

Pietro Ianniello pietro.ianniello at gmail.com
Fri Feb 26 12:43:48 EST 2010


Dear Mike,
    unfortunally I don't speak PHP!

   ...have not yet used Fusion, but is really good looking!... seems rather
complex... I know OL [I used it with Mapserver + WMS], so was a logic
choise... don't know how to get map layers' legend yet... if you can give a
simple example it would be great... even in PHP, I can read PHP code...

Dear durr,

OL = OpenLayers, MG = MapGuide [Open Source]
there's a name clashing between OL and MG:
an OL layer is an MG Map, what in OL is a Base Layer is NOT what in MG is a
Base Layer.
If the MG Map is made only by Base Layers (MG speaking), you can only toggle
the whole think on and off: in Map Guide 2.0 Developer's Guide at page 31 is
written:

"*Layers within a base layer group are rendered together. Visibility
settings for
individual layers are ignored and the visibility setting for the group is
used
instead.*"

If they are not a BaseLayer, then on server side you must get lay. obj. id:

string strLID1 = mgMap.GetLayers().GetItem("*LAYER NAME 1*").GetObjectId()
...
string strLIDN = mgMap.GetLayers().GetItem("*LAYER NAME N*").GetObjectId()

[...I think we should not use above code in c#, but make a variable for each
object and despose it... there's no documentation on what must and what must
not be disposed...]
Now suppose that from above code you get the following layer object ids:
strLID1=="id1"
...
strLIDN=="idN"

and that
"id_s1", ... "id_sk"  are the one you want to show
"id_h1,..., "id_hu" are the one you want to hide

Indices
   s1,...,sk in J={1,...,n}
   h1,...,hu in [{1,...,n} - J]
...ok is not very comprehensible: say we have some layers to show with id
"id_s1", ... "id_sk" and some to hide "id_h1",..., "id_hu".

Now YOU HAVE TO FIND A WAY TO PASS THEM TO CLIENT depending on the server
side language of your chise  [note that they will not be valid any more on
MG session expiration!!!]

On client something *like*:

var _mgLayer = null;
var ccc=0;

function someFunc() {

(...)

var map = new Openlayers.Map(........);

var baseLayer = (...); *//without a Base Layer (OL speaking) you will not
get OL correctly init*

var url = "*something like
/mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&*";
var mgOptions = {
                *singleTile: true*,
                buffer: 1,
                session: "session id taken from server",
                mapDefinition: "map def, *better* from server"
[ex.:"Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition"]
            };
*var params = {
   showLayers: "id_k1,...,id_sk", //CSV of layer ids to show - taken FROM
SERVER!
    hideLayers: "id_h1,...,id_hu" //CSV of layer ids to hide - taken FROM
SERVER!
};
*
_mgLayer = new OpenLayers.Layer.MapGuide("custom lay. name", url, params,
mgOptions);
map.addLayer(mgOverlayLayer);

(...)

}//end someFunc


function swapHideShow()
{
 if(mgOverlayLayer)
 {
   if(ccc++%2==0)
   {
        _mgOverlayLayer.params.showLayers = "id_h1,...,id_hu";
        _mgOverlayLayer.params.hideLayers = "id_k1,...,id_sk";
   }
   else
   {
        _mgOverlayLayer.params.showLayers = "id_k1,...,id_sk";
        _mgOverlayLayer.params.hideLayers = "id_h1,...,id_hu";
   }
   _mgLayer.redraw(true);
 }
}

Bye,
   P.I.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapguide-users/attachments/20100226/cd423975/attachment.html


More information about the mapguide-users mailing list