By Daniel Du
You may have been using following code snippet to open a map in basic layout (assuming a map resource named as “myMapName” is created in MapGuide Studio,):
MgMap map = new MgMap();
map.Open(resourceServices, “myMapName”);
But it does not work in fusion viewer, the error message is :
Error : " Invalid argument(s): [0] = " " The string cannot be empty "
The reason is the map name will be changed during run time in fusion viewer, so please do not use hard-coded map name when programing.
If you are using “Invoke URL” command to invoke the page, MapGuide will add some parameters for you including SESSION, MAPNAME, etc. The value of these parameters can be retrieved by Request object. Here is a demonstration of how to get map name and open a map in fusion viewer:
string mapname = Request[“MapName”].ToString()
map.open(resSvc,mapname);
Firstly, create a custom command to "invoke URL" and point the URL to your custom page.
Specify the target as "Task Pane":
Code snippet goes as below:
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="MapInformation.aspx.cs"
Inherits="AIMS2012WebApp.MapInformation" %>
<!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></title>
<script language= "javascript" type="text/javascript">
function Init() {
var aa = '<%=mapNameXX %>' ;
alert(aa);
}
</script>
</head>
<body onload="Init();">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AIMS2012WebApp
{
public partial class MapInformation : System.Web.UI.Page
{
public string mapNameXX;
protected void Page_Load(object sender, EventArgs e)
{
UtilityClass util = new UtilityClass();
util.InitializeWebTier(Request);
string sessionId = Request["Session"].ToString();
util.ConnectToServer(sessionId);
string mapName = Request["MapName"].ToString();
//public variable, alert from client side
mapNameXX = mapName;
}
}
}
The implementation of Utility class goes as below:
using System;
using System.Collections.Generic;
using System.Web;
using System.Collections;
using System.Xml;
using System.IO;
using System.Text;
using OSGeo.MapGuide;
/// <summary>
/// Summary description for Utility.
/// Created by Daniel Du, DevTech
/// </summary>
public class UtilityClass
{
MgSiteConnection siteConnection;
public void InitializeWebTier(HttpRequest Request)
{
string realPath =
Request.ServerVariables["APPL_PHYSICAL_PATH"];
String configPath = realPath + "../webconfig.ini";
MapGuideApi.MgInitializeWebTier(configPath);
}
public void ConnectToServer(String sessionID)
{
MgUserInformation userInfo =
new MgUserInformation(sessionID);
siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
}
public MgSiteConnection GetSiteConnection()
{
return siteConnection;
}
}
The result will be similar as below, please the note the map name is different with the one defined in Infrastructure Studio.