[mapguide-users] FW: Change Layer Visibility - Mapguide With Openlayers3

Greg Neff gbneff at cid.utah.gov
Fri Feb 10 14:35:05 PST 2017


I found my problem.  It was here:



map.Save(resService); should be map.Save();



Updating the OpenLayers mapguide layer accomplished like this:



var params = mgLayer.getSource().getParams();

params.t = new Date().getMilliseconds();

mgLayer.getSource().updateParams(params);



Thanks,



Gregory B. Neff

District Engineer

Cottonwood Improvement District

8620 Highland Drive

Sandy, Utah 84093

(801) 943-7671

*From:* Greg Neff [mailto:gbneff at cid.utah.gov]
*Sent:* Friday, February 10, 2017 11:34 AM
*To:* 'mapguide-users at lists.osgeo.org' <mapguide-users at lists.osgeo.org>
*Subject:* Change Layer Visibility - Mapguide With Openlayers3



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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20170210/4bf1091e/attachment.html>


More information about the mapguide-users mailing list