Infrastructure Map Server General Discussion

Infrastructure Map Server General Discussion

Reply
Valued Contributor
scluna
Posts: 61
Registered: ‎02-20-2007
Message 1 of 9 (494 Views)

turning on/off layers in Mapguide Enterprise

494 Views, 8 Replies
02-20-2007 06:12 PM
How do I turn on or off a layer. Could anyone provide a code snippet?

Thanks
SCLuna
Distinguished Contributor
jumpinjackie
Posts: 105
Registered: ‎05-21-2006
Message 2 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

02-22-2007 02:37 PM in reply to: scluna
get the MgLayer object in question from your MgMap object.

call SetVisible(false) on that layer object. Save your map object and do a refresh on the client side.

here's a php example:

$map = new MgMap();
$map->Open($resourceService, $mapName);

$layerName = "Parcels";
$visible = true; //or false

$mapLayers = $map->GetLayers();
$layer = null;
for($i = 0; $i < $mapLayers->GetCount(); $i++)
{
$currentLayer = $mapLayers->GetItem($i);
if($currentLayer->GetName() == $layerName)
{
$layer = $currentLayer;
}
}

if($layer != null)
{
$layer->SetVisible($visible);
$layer->ForceRefresh();
$map->Save($resourceService);
}
http://themapguyde.blogspot.com
http://au.linkedin.com/in/jackieng
Valued Contributor
scluna
Posts: 61
Registered: ‎02-20-2007
Message 3 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

02-22-2007 10:14 PM in reply to: scluna
thanks for the idea.
actually i have run may asp.net code and getting an MgUnclassified Exception. when I turn the layers on and off.
The error is in line 22 when i pass the sessionid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: OSGeo.MapGuide.MgUnclassifiedException: An unclassified exception occurred.

Source Error:


Line 20: InitializeWebTier();
Line 21:
Line 22: MgUserInformation userInfo = new MgUserInformation(SessionId);
Line 23: MgSiteConnection siteConnection = new MgSiteConnection();
Line 24: siteConnection.Open(userInfo);

___________________________________________
MgLayerCollection LayerCol = map.GetLayers();
MgLayer layer = LayerCol.GetItem("Soils");
if (layer.IsVisible())
{
layer.SetVisible(false);
}
else
{
layer.SetVisible(true);
}

layer.ForceRefresh();
map.Save(resourceService);
SCLuna
Distinguished Contributor
jumpinjackie
Posts: 105
Registered: ‎05-21-2006
Message 4 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

02-25-2007 10:09 PM in reply to: scluna
Try the following:

- Check the value of sessionId, it's gotta look like a long string of hexadecimal numbers.

- Wrap that code in a try-catch block, catch MgException and call its GetDetails(). Hopefully, that can reveal more information.
http://themapguyde.blogspot.com
http://au.linkedin.com/in/jackieng
Member
SAustin
Posts: 3
Registered: ‎03-23-2007
Message 5 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

03-23-2007 04:48 PM in reply to: scluna
I've gotten that error when trying to change the visibility of base map layers with AJAX viewer. Here is a quote from the Web API Reference doc that helped me:

the visibility of base map layers (those of type MgLayerType::BaseMap) cannot be changed. Attempting to do so will throw an MgInvalidOperationException

http://mapguide.osgeo.org/files/mapguide/docs/webapi/d6/de2/class_mg_layer_1970fbe700599c7fd6f8603708158486.html#1970fbe700599c7fd6f8603708158486
Valued Contributor
scluna
Posts: 61
Registered: ‎02-20-2007
Message 6 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

04-25-2007 12:28 AM in reply to: scluna
Thanks jackie/SAustin,

I already made a workaround on this and it's working now.
SCLuna
Active Member
ales6
Posts: 10
Registered: ‎09-03-2007
Message 7 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

09-04-2007 06:21 AM in reply to: scluna
Hi SCLuna

Currently searching solution (workaround) form my .net sample
..did not found solution how to fix the problem.

I still get message:
Type 'OSGeo.MapGuide.MgUnclassifiedException' in Assembly 'MapGuideDotNetApi, Version=1.1.0.301, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

Can you help me, please.

by ales6
Member
SAustin
Posts: 3
Registered: ‎03-23-2007
Message 8 of 9 (494 Views)

Re: turning on/off layers in Mapguide Enterprise

07-10-2008 04:26 PM in reply to: scluna
This is actually possible with base layers Here is some info that I used in my solution.
http://www.nabble.com/Fwd:-Swithing-base-MgLayerGroup-on-off-...-fails--td14454152.html
Valued Contributor
mitchellhastings1484
Posts: 68
Registered: ‎12-18-2003
Message 9 of 9 (201 Views)

Re: turning on/off layers in Mapguide Enterprise

01-23-2014 11:00 AM in reply to: scluna

Thanks for the code Jakie.

 

I added a snipet to the search.php to turn on a layer that was being searched if it was off by default.

below is the code I added an else statement at the end.  Seems to work ok.

 

 

try
{
$featureSrvc = $siteConnection->CreateService(MgServiceType::FeatureService);

//Create a temporary map runtime object, locate the layer
$map = new MgMap();
$map->Open($resourceService, $mapName);
$layers = $map->GetLayers();
$layer = null;
//fwrite($logHandle,"found layers:".$layers->GetCount()."\n");
for($i = 0; $i < $layers->GetCount(); $i++)
{
$layer = $layers->GetItem($i);
//fwrite($logHandle,"found layer:".$layer->GetName()."\n");
if($layer->GetName() == $layerName)

break;
}

if($layer == null)
{
trigger_error(FormatMessage("SEARCHLAYERNOTFOUND", $locale, array($layerName)));
}
else
{
$layer->SetVisible($visible);
$layer->ForceRefresh();
$map->Save($resourceService);
}

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community