using System;
using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
namespace InfoSoftGlobal
{
///
/// Summary description for FusionMaps.
///
public class FusionMaps
{
///
/// encodes the dataURL before it's served to FusionMaps
/// If you have parameters in your dataURL, you'll necessarily need to encode it
///
/// dataURL to be fed to Map
/// Whether to add aditional string to URL to disable caching of data
/// Encoded dataURL, ready to be consumed by FusionMaps
public static string EncodeDataURL(string dataURL, bool noCacheStr)
{
string result = dataURL;
if (noCacheStr)
{
result += (dataURL.IndexOf("?") != -1) ? "&" : "?";
//Replace : in time with _, as FusionMaps cannot handle : in URLs
result += "FCCurrTime=" + DateTime.Now.ToString().Replace(":", "_");
}
return System.Web.HttpUtility.UrlEncode(result);
}
///
/// Generate html code for rendering Map
/// This function assumes that you've already included the FusionMaps JavaScript class in your page
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
/// Whether to ask Map to register itself with JavaScript
/// /// Whether transparent Map (true / false)
/// JavaScript + HTML code required to embed a Map
private static string RenderMapALL(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS, bool transparent)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat("" + Environment.NewLine, MapId);
builder.AppendFormat("
" + Environment.NewLine);
builder.Append("" + Environment.NewLine);
builder.AppendFormat("" + Environment.NewLine, MapId);
return builder.ToString();
}
///
/// Generate html code for rendering Map
/// This function assumes that you've already included the FusionMaps JavaScript class in your page
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
/// Whether to ask Map to register itself with JavaScript
/// Whether transparent Map (true / false)
/// JavaScript + HTML code required to embed a Map
public static string RenderMap(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS, bool transparent)
{
return RenderMapALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, transparent);
}
///
/// Generate html code for rendering Map
/// This function assumes that you've already included the FusionMaps JavaScript class in your page
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
/// Whether to ask Map to register itself with JavaScript
/// JavaScript + HTML code required to embed a Map
public static string RenderMap(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS)
{
return RenderMap(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, false);
}
///
/// Renders the HTML code for the Map. This
/// method does NOT embed the Map using JavaScript class. Instead, it uses
/// direct HTML embedding. So, if you see the Maps on IE 6 (or above), you'll
/// see the "Click to activate..." message on the Map.
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
///
public static string RenderMapHTML(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode)
{
return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, false, false);
}
///
/// Renders the HTML code for the Map. This
/// method does NOT embed the Map using JavaScript class. Instead, it uses
/// direct HTML embedding. So, if you see the Maps on IE 6 (or above), you'll
/// see the "Click to activate..." message on the Map.
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
/// Whether to ask Map to register itself with JavaScript
///
public static string RenderMapHTML(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS)
{
return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, false);
}
///
/// Renders the HTML code for the Map. This
/// method does NOT embed the Map using JavaScript class. Instead, it uses
/// direct HTML embedding. So, if you see the Maps on IE 6 (or above), you'll
/// see the "Click to activate..." message on the Map.
///
/// SWF File Name (and Path) of the Map which you intend to plot
/// If you intend to use dataURL method for this Map, pass the URL as this parameter. Else, set it to "" (in case of dataXML method)
/// If you intend to use dataXML method for this Map, pass the XML data as this parameter. Else, set it to "" (in case of dataURL method)
/// Id for the Map, using which it will be recognized in the HTML page. Each Map on the page needs to have a unique Id.
/// Intended width for the Map (in pixels)
/// Intended height for the Map (in pixels)
/// Whether to start the Map in debug mode
/// Whether to ask Map to register itself with JavaScript
/// Whether transparent Map (true / false)
///
public static string RenderMapHTML(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS, bool transparent)
{
return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, transparent);
}
private static string RenderMapHTMLALL(string MapSWF, string strURL, string strXML, string MapId, string MapWidth, string MapHeight, bool debugMode, bool registerWithJS, bool transparent)
{
//Generate the FlashVars string based on whether dataURL has been provided
//or dataXML.
StringBuilder strFlashVars = new StringBuilder();
string flashVariables = String.Empty;
if (strXML.Length == 0)
{
//DataURL Mode
flashVariables = String.Format("&MapWidth={0}&MapHeight={1}&debugMode={2}®isterWithJS={3}&DOMId={4}&dataURL={5}", MapWidth, MapHeight, boolToNum(debugMode), (registerWithJS), MapId, strURL);
}
else
//DataXML Mode
{
flashVariables = String.Format("&MapWidth={0}&MapHeight={1}&debugMode={2}®isterWithJS={3}&DOMId={4}&dataXML={5}", MapWidth, MapHeight, boolToNum(debugMode), boolToNum(registerWithJS), MapId, strXML);
}
strFlashVars.AppendFormat("" + Environment.NewLine, MapId);
strFlashVars.AppendFormat("" + Environment.NewLine);
strFlashVars.AppendFormat("" + Environment.NewLine, MapId);
string FlashXML = "
"; FlashXML += strFlashVars.ToString() + "
";
return FlashXML;
}
///
/// Transform the meaning of boolean value in integer value
///
/// true/false value to be transformed
/// 1 if the value is true, 0 if the value is false
private static int boolToNum(bool value)
{
return value ? 1 : 0;
}
}
}