[mapguide-users] Newbie - attempting to hidelayers based on
checkbox in separate frame with AJAX Viewer
tmblackflag
steve.calpoly at gmail.com
Wed Jul 27 16:51:55 EDT 2011
New guy here. I have a simple page with two frames, one frame has a
checkbox. I would like to use this checkbox to show/hide layers in the
second frame with the AJAX viewer. My weblayout has all frames turned off
except the viewer. When i uncheck the box it is not hiding the A-WALL-INT
layer, what am I doing wrong? This is difficult since most examples are aspx
pages called by the web layout. I need to do a custom layers pane due to the
need for 2-3 viewer frames in a single page. I do not want to force the user
to turn on/off the same layer in multiple frames. Here is my code in ASP.NET
*MILP2.ASPX (Main Page)*
<%@ Page language="c#" Debug="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="OSGeo.MapGuide" %>
<%
try
{
InitializeWebTier();
MgUserInformation userInfo = new MgUserInformation(defaultUser,
defaultPassword);
MgSite site = new MgSite();
site.Open(userInfo);
sessionId = site.CreateSession();
}
catch (Exception e)
{
Response.Write(e.Message);
}
%>
<html>
<head>
<title>Viewer Sample Application</title>
</head>
<frameset rows="100,*" frameborder="no" framespacing="0">
<frame id="titleFrame" frameborder="no"
marginwidth="0" marginheight="0"
scrolling="no"
src="header.aspx?SESSION=<%=sessionId%>">
<frame id="viewerFrame" frameborder="no"
marginwidth="0" marginheight="0"
scrolling="no"
src="../mapviewernet/ajaxviewer.aspx?SESSION=<%=sessionId%>&WEBLAYOUT=<%=webLayout%>">
</frameset>
</html>
*header.aspx (frame with checkbox)*
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="header.aspx.cs"
Inherits="header" Debug="true" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections.Specialized" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="OSGeo.MapGuide" %>
<%@ Import Namespace="System.Web" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" Text="A-WALL-INT"
Checked="True" />
<br />
<asp:Label ID="Label4" runat="server"></asp:Label>
<br />
<asp:Label ID="Label5" runat="server"></asp:Label>
<br />
<p>Session Id is: <%=sessionId%></p>
</form>
</body>
</html>
*Code behind file of header.aspx*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OSGeo.MapGuide;
using System.Collections.Specialized;
using System.IO;
using System.Text;
public partial class header : System.Web.UI.Page
{
public string sessionId = "";
protected void Page_Load(object sender, EventArgs e)
{
sessionId = Request.QueryString["SESSION"];
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
string isChecked = cb.Checked.ToString();
string layer = cb.Text.ToString();
Test_Output(layer, isChecked);
toggleLayer(sessionId, layer, isChecked);
}
protected void Test_Output(string layer, string isChecked)
{
Label5.Text = "Layer name is: " + layer.ToString() + ", is it
checked? Answer is: " + isChecked.ToString();
}
protected void toggleLayer(string sessionId, string layer, string
isChecked)
{
try
{
InitializeWebTier();
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgResourceService resourceService =
(MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
MgFeatureService featureService =
(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
MgMap map = new MgMap();
map.Open(resourceService, "RUSHMMAF01");
MgLayer existingLayer = GetLayerByName(map, "A-WALL-INT");
if (isChecked == "true")
existingLayer.SetVisible(true);
else
existingLayer.SetVisible(false);
existingLayer.ForceRefresh();
map.Save(resourceService);
}
catch (Exception e)
{
Response.Write(e.Message);
}
}
void InitializeWebTier()
{
// Initialize web tier with the site configuration file. The config
// file should be in the same directory as this script.
string s_basePath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
MapGuideApi.MgInitializeWebTier(s_basePath + "../webconfig.ini");
}
MgLayer GetLayerByName(MgMap map, String layerName)
{
MgLayer layer = null;
for (int i = 0; i < map.GetLayers().GetCount(); i++)
{
MgLayer nextLayer = (MgLayer)map.GetLayers().GetItem(i);
if (nextLayer.GetName().Equals(layerName))
{
layer = nextLayer;
break;
}
}
return layer;
}
}
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Newbie-attempting-to-hidelayers-based-on-checkbox-in-separate-frame-with-AJAX-Viewer-tp6627669p6627669.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list