Creating a custom Virtual Earth Web Part in SharePoint 2010

I had a requirement to create a web part that will pull the address information from one of the records in CRM and show it on the map.

One of the issues I faced while trying out different approaches was that after adding the web part to the SharePoint page, the scrollbar used to go missing in that page.

Finally with help of below two links I managed to develop a the web part.

http://sundium.wordpress.com/2008/06/15/dynamics-crm-40-virtual-earth/

http://virtualearthwebpart.codeplex.com/

Well we could make use of the below code to achieve that

public class MyVirtualEarthWebPart : WebPart
{
protected override void OnLoad(EventArgs e)
{
System.Web.UI.ClientScriptManager csm = Page.ClientScript;
StringBuilder builder = new StringBuilder();
string SCRIPT_NAME = "MapScript" + this.ID;

builder.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> \n");
builder.Append("<script type=\"text/javascript\" src=\"http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2\"></script> \n");
builder.Append("<script type=\"text/javascript\"> \n");
builder.Append("    var map = null; \n");
builder.Append("    var latitude = null; \n");
builder.Append("    var longitude = null; \n");
builder.Append("    var address = ''; \n");
builder.Append("    var titles = new Array(); \n");

builder.Append("    function GetMap() \n");
builder.Append("    { \n");
builder.Append("        try  \n");
builder.Append("        { \n");
builder.Append("            address = 'New C G Road, chandkheda, gandhinagar';\n");
builder.Append("            map = new VEMap('myMap');\n");
builder.Append("            map.LoadMap(null,4,VEMapStyle.Hybrid); \n");
builder.Append("            map.Find(null,address,null,null,0,10,true,true,true,true,FindCallBack); \n");
builder.Append("        } \n");
builder.Append("        catch (e) \n");
builder.Append("        { \n");
builder.Append("            alert('GetMap: ' + e.message); \n");
builder.Append("        } \n");
builder.Append("    } \n");

builder.Append("    function FindCallBack(shapeLayer, results, positions, moreResults, e) \n");
builder.Append("    { \n");
builder.Append("        try  \n");
builder.Append("        { \n");
builder.Append("             if(positions != null && positions.length > 0) \n");
builder.Append("              { \n");
builder.Append("                PlacePushPin(positions[0].LatLong.Latitude,positions[0].LatLong.Longitude); \n");
builder.Append("                latitude = positions[0].LatLong.Latitude; \n");
builder.Append("                longitude = positions[0].LatLong.Longitude; \n");
builder.Append("               } \n");
builder.Append("        } catch (e) { \n");
builder.Append("            alert('FindCallBack: ' + e.message); \n");
builder.Append("        } \n");
builder.Append("      }      \n");

builder.Append("    function PlacePushPin(lat, lon){ \n");
builder.Append("                latlong = new VELatLong(lat,lon); \n");
builder.Append("                customerPushPin = new VEShape(VEShapeType.Pushpin,latlong); \n");
builder.Append("                customerPushPin.SetTitle(address); \n");
builder.Append("                map.AddShape(customerPushPin); \n");
builder.Append("                map.SetCenterAndZoom(latlong,15);  \n");
builder.Append("                } \n");

builder.Append("_spBodyOnLoadFunctionNames.push('GetMap'); \n</script> \n");
csm.RegisterClientScriptBlock(
this.GetType(),
SCRIPT_NAME,
builder.ToString(),
false);

}
protected override void CreateChildControls()
{
base.CreateChildControls();
StringBuilder builder = new StringBuilder();
builder.Append("<div id='myMap' style='position: relative; width: 300px; height: 300px;'></div>");
this.Controls.Add(new LiteralControl(builder.ToString()));
}
}

Bye.

Advertisements

SPUpgradeException Exception message: An error has occurred on the server.http://go.microsoft.com/fwlink?LinkID=96177

Hi I got the error while trying to open the SharePoint Site after applying the MOSS SP2 update to it.

This post was helpful in resolving that error

http://social.technet.microsoft.com/forums/en-US/sharepointadmin/thread/4cce44de-4b5a-4dcb-a369-be65654ff80e/

  • Nachrichten dieses Autors suchen

    Hi Guys

    I had the same problem. and i fixed it by going here
    http://www.microsoft.com/downloads/details.aspx?familyid=A49472F9-93E…

    download the file that matches your OS. ie x32 or x64
    If you try to run the file it will tell you the patch is already installed.
    but run the file with “/extract” extrace the file to someware and run
    “dw20w.msp”
    Let it do its thing. It takes a while……Then presto. well as least for
    me.

    Let me know how you guys go with it.

    Hope it helps!