Imports Microsoft.VisualBasic Imports System.web Imports System.Text 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 Shared Function EncodeDataURL(ByVal dataURL As String, ByVal noCacheStr As Boolean) As String Dim result As String = dataURL If noCacheStr = True Then result = result & IIf(dataURL.IndexOf("?") <> -1, "&", "?") 'Replace : in time with _, as FusionMaps cannot handle : in URLs result = result & "FCCurrTime=" & DateTime.Now.ToString().Replace(":", "_") End If Return HttpUtility.UrlEncode(result) End Function ''' ''' 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 Shared Function RenderMapALL(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean, ByVal transparent As Boolean) As String Dim builder As New StringBuilder builder.Append("" + Environment.NewLine) builder.Append("
" & Environment.NewLine) builder.Append("Map." & Environment.NewLine) builder.Append("
" & Environment.NewLine) builder.Append("" + Environment.NewLine) builder.AppendFormat("" & Environment.NewLine) Return builder.ToString() End Function ''' ''' 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 Shared Function RenderMap(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean, ByVal transparent As Boolean) As String Return RenderMapALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, transparent) End Function ''' ''' 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 Shared Function RenderMap(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean) As String Return RenderMap(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, False) End Function ''' ''' 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 Shared Function RenderMapHTML(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean) As String Return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, False, False) End Function ''' ''' 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 Shared Function RenderMapHTML(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean) As String Return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, False) End Function ''' ''' 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 Shared Function RenderMapHTML(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean, ByVal transparent As Boolean) As String Return RenderMapHTMLALL(MapSWF, strURL, strXML, MapId, MapWidth, MapHeight, debugMode, registerWithJS, transparent) End Function Private Shared Function RenderMapHTMLALL(ByVal MapSWF As String, ByVal strURL As String, ByVal strXML As String, ByVal MapId As String, ByVal MapWidth As String, ByVal MapHeight As String, ByVal debugMode As Boolean, ByVal registerWithJS As Boolean, ByVal transparent As Boolean) As String 'Generate the FlashVars string based on whether dataURL has been provided 'or dataXML. Dim strFlashVars As New StringBuilder() Dim flashVariables As String = String.Empty If strXML.Length = 0 Then '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) End If strFlashVars.Append("" & Environment.NewLine) strFlashVars.Append("" & Environment.NewLine) strFlashVars.Append("" + Environment.NewLine) strFlashVars.Append("" + Environment.NewLine) strFlashVars.Append("" & Environment.NewLine) strFlashVars.Append("" & Environment.NewLine) Dim strwmode As String = "" If (transparent = True) Then strFlashVars.Append("" & Environment.NewLine) strwmode = "wmode=""transparent""" End If strFlashVars.AppendFormat("" + Environment.NewLine) strFlashVars.Append("" + Environment.NewLine) strFlashVars.AppendFormat("" + Environment.NewLine, MapId) Dim FlashXML As String = "
" FlashXML = FlashXML & strFlashVars.ToString() + "
" Return FlashXML End Function ''' ''' 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 Shared Function boolToNum(ByVal value As Boolean) As Integer Return IIf(value = True, 1, 0) End Function End Class End Namespace