Hi,

I'm trying to create my own map control for Virtual Earth. Pllleeeeaaaseee do not ask the reason why...I just need it. The following code works in Firefox but will not work in IE. It is driving me absolutely insane. I cannot figure out why...... Any ideas? or has someone out there created their own that I can have :) The code is a little unorthodox but is work in progress.

ASP.net 2.0

Language - VB

Site Content Manager ?Dot Net Nuke

ASP.net Server Control

VB Code:

Imports System

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.ComponentModel

Imports System.Collections

Public Class MapControl

Inherits WebControl

#Region "Variables"

Private _dataSource As IEnumerable

Private _VarMap As String = "var map = null;"

Private _GetMapOpen As String = "function GetMap(){"

Private _CloseBracket As String = "}"

Private _LoadMap As String = "map.LoadMap();"

Private _PinId1 As String = "var pinid1=0;"

Private _Locs1Array As String = "var locs1 = new Array;"

Private _MapAddPushpin As String = "map.AddPushpin(pin);"

Private _IncrementPinId As String = "pinid1++;"

Private _Latitude As String = "47.6"

Private _Longitude As String = "-122.33"

Private _ZoomLevel As Integer = 10

#End Region

#Region "Properties"

Public Property DataSource() As IEnumerable

Get

Return _dataSource

End Get

Set(ByVal value As IEnumerable)

_dataSource = value

End Set

End Property

<Browsable(True), Category("Position")> _

Public Property Latitude() As String

Get

Return _Latitude

End Get

Set(ByVal value As String)

_Latitude = value

End Set

End Property

<Browsable(True), Category("Position")> _

Public Property Longitude() As String

Get

Return _Longitude

End Get

Set(ByVal value As String)

_Longitude = value

End Set

End Property

<Browsable(True), Category("Position")> _

Public Property ZoomLevel() As Integer

Get

Return _ZoomLevel

End Get

Set(ByVal value As Integer)

_ZoomLevel = value

End Set

End Property

#End Region

#Region "String Functions"

Private Function NewNamedMap(ByVal MapName As String) As String

Return "map = new VEMap('" & MapName & "');"

End Function

Private Function NewLocation(ByVal longatude As String, ByVal latitude As String) As String

Return "var loc = new VELatLong(" & longatude & "," & latitude & ");"

End Function

Private Function AddPushPin(ByVal Arr As String, ByVal Location As String) As String

Return Arr & ".push(" & Location & ");"

End Function

Private Function ForOpen(ByVal Arr As String) As String

Return "for (i=0; i < " & Arr & ".length; i++){"

End Function

Private Function RunBestMap(ByVal Arr As String) As String

Return "DoBestMap(" & Arr & ");"

End Function

#End Region

#Region "Map Strings"

Private Function MapWithDatasource() As String

Dim str As String = ""

str &= "<script "

str &= "type=""text/javascript"""

str &= ">"

str &= _GetMapOpen & _VarMap & NewNamedMap("MyNewMap") & _LoadMap

str &= _Locs1Array

str &= _PinId1

Dim DataEnum As IEnumerator

DataEnum = DataSource.GetEnumerator()

Dim i As Integer = 0

'str &= ForOpen("locs1")

While (DataEnum.MoveNext())

Dim st1, st2, st3, st4 As String

st1 = DataEnum.Current

DataEnum.MoveNext()

st2 = DataEnum.Current

DataEnum.MoveNext()

st3 = DataEnum.Current

DataEnum.MoveNext()

st4 = DataEnum.Current

str &= NewLocation(st1, st2)

str &= AddPushPin("locs1", "loc")

str &= "var pin = new VEPushpin(" & i.ToString & ", locs1[" & i.ToString & "], null, '" & st3 & "', '" & st4 & "');"

str &= "map.AddPushpin(pin);"

i += 1

End While

'str &= _CloseBracket

str &= "map.SetMapView(locs1);"

str &= _CloseBracket

str &= "</script>"

Return str

End Function

Private Function BasicMap() As String

Dim str As String = ""

str = "<script ""language=""JavaScript"">"

If Latitude <> "" And Longitude <> "" Then

str &= _GetMapOpen & _VarMap & NewNamedMap("MyNewMap") & _

"map.LoadMap(new VELatLong(" & Latitude.ToString & "," & Longitude.ToString & "), " & ZoomLevel.ToString & ",'h' ,false);" & _CloseBracket

Else

str &= _GetMapOpen & _VarMap & NewNamedMap("MyNewMap") & _LoadMap & _CloseBracket

End If

str &= "</script>"

Return str

End Function

#End Region

#Region "Control Methods"

Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)

MyBase.OnPreRender(e)

Dim meta As String = "<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">"

Dim link As String = "<script type=""text/javascript"" src=""http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2""></script>"

Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "Meta", meta)

Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "Link", link)

Controls.Add(New LiteralControl("<div id='MyNewMap' style=""position:relative; width:600px; height:300px;""></div>"))

If Not _dataSource Is Nothing Then

Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "OnLoad", MapWithDatasource)

Else

Me.Page.ClientScript.RegisterClientScriptBlock(GetType(String), "OnLoad", BasicMap)

End If

End Sub

Protected Overrides Sub OnDataBinding(ByVal e As EventArgs)

Controls.Clear()

End Sub

#End Region

End Class

  • Edited bylexter333 Wednesday, May 06, 2009 5:43 AM
  •