Greg Neff
2017-02-10 18:34:01 UTC
OpenLayers v3.18
Mapguide 3.1 64 bit
IIs â Windows 10
Is it possible to change the visibility of a Mapguide map layer using the
Mapguide api and then have the change reflected in the openlayers viewer
where the Mapguide map is a layer?
I have tried the following code below and seem to be able to get the layer
visibility and set the visibility, but I donât think the changes are being
saved to the âruntimeâ or session map. (btw: When I couldnât make it work
with OpenLayers, I tried it in the AJAX viewer with an invoke url running
in the task pane and that is the code shown.)
Thanks,
Gregory B. Neff
District Engineer
Cottonwood Improvement District
8620 Highland Drive
Sandy, Utah 84093
(801) 943-7671
<%@ Import Namespace="OSGeo.MapGuide" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Changing Layer Visibility</title>
<script type="text/javascript">
function RefreshMap() {
parent.parent.Refresh();
}
</script>
</head>
<body onload="javascript:RefreshMap()">
<%
String sessionId = Request.Form.Get("SESSION");
//make sure to pass these values
//String mapguideMapResource = Request.Form.Get("mapguideMapName");
String mapguideMapResource = "Cid_Map";
//String mapguideLayer =
Request.Form.Get("mapguideCleanedLinesLayer");
String mapguideLayer = "linesCleaned2017";
String realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
realPath = realPath.Replace(@"Cid_Map\", "");
String configPath = realPath + "webconfig.ini";
MapGuideApi.MgInitializeWebTier(configPath);
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgResourceService resService = (MgResourceService
)siteConnection.CreateService(MgServiceType.ResourceService);
MgMap map = new MgMap(siteConnection);
map.Open(resService, mapguideMapResource);
MgLayerCollection layers = map.GetLayers();
//MgLayerBase layerClean2017 = layers.GetItem(mapguideLayer);
MgLayer layer = (MgLayer)layers.GetItem(mapguideLayer);
if (layer.GetVisible())
{
layer.SetVisible(false);
}
else
{
layer.SetVisible(true);
}
layer.ForceRefresh();
map.Save(resService);
Response.Write(sessionId + "</br>");
Response.Write("Map Name: " + map.GetName() + "</br>");
Response.Write(layer.GetName() + " " + layer.GetVisible());
%>
</body>
Mapguide 3.1 64 bit
IIs â Windows 10
Is it possible to change the visibility of a Mapguide map layer using the
Mapguide api and then have the change reflected in the openlayers viewer
where the Mapguide map is a layer?
I have tried the following code below and seem to be able to get the layer
visibility and set the visibility, but I donât think the changes are being
saved to the âruntimeâ or session map. (btw: When I couldnât make it work
with OpenLayers, I tried it in the AJAX viewer with an invoke url running
in the task pane and that is the code shown.)
Thanks,
Gregory B. Neff
District Engineer
Cottonwood Improvement District
8620 Highland Drive
Sandy, Utah 84093
(801) 943-7671
<%@ Import Namespace="OSGeo.MapGuide" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Changing Layer Visibility</title>
<script type="text/javascript">
function RefreshMap() {
parent.parent.Refresh();
}
</script>
</head>
<body onload="javascript:RefreshMap()">
<%
String sessionId = Request.Form.Get("SESSION");
//make sure to pass these values
//String mapguideMapResource = Request.Form.Get("mapguideMapName");
String mapguideMapResource = "Cid_Map";
//String mapguideLayer =
Request.Form.Get("mapguideCleanedLinesLayer");
String mapguideLayer = "linesCleaned2017";
String realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
realPath = realPath.Replace(@"Cid_Map\", "");
String configPath = realPath + "webconfig.ini";
MapGuideApi.MgInitializeWebTier(configPath);
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgResourceService resService = (MgResourceService
)siteConnection.CreateService(MgServiceType.ResourceService);
MgMap map = new MgMap(siteConnection);
map.Open(resService, mapguideMapResource);
MgLayerCollection layers = map.GetLayers();
//MgLayerBase layerClean2017 = layers.GetItem(mapguideLayer);
MgLayer layer = (MgLayer)layers.GetItem(mapguideLayer);
if (layer.GetVisible())
{
layer.SetVisible(false);
}
else
{
layer.SetVisible(true);
}
layer.ForceRefresh();
map.Save(resService);
Response.Write(sessionId + "</br>");
Response.Write("Map Name: " + map.GetName() + "</br>");
Response.Write(layer.GetName() + " " + layer.GetVisible());
%>
</body>