November 21, 2014
Hot Topics:

Building a Webpart to Display a Virtual Earth Map

  • July 26, 2007
  • By Mark Strawmyer
  • Send Email »
  • More Articles »

Webpart Display

Building an ASP.NET webpart requires that you have webpart zones and other plumbing set up within your appliation. This is likely to be a topic of another article if enough people are interested, but for now you'll skip the background. The following sample control is a pretty basic webpart that doesn't do much more than get added to the display and render a map from the appropriate data source.

<%@ Control Language="C#"            AutoEventWireup="true"            CodeBehind="CompositeVirtualEarthMap.ascx.cs"            Inherits="MyColts.Net.Composite.                      CompositeVirtualEarthMap" %><script type="text/javascript"        src="http://dev.virtualearth.net/mapcontrol/v4/             mapcontrol.js"></script><script type="text/javascript">   var map = null;   var layerID = 1;   function GetMap()   {      map = new VEMap('myMap');      map.LoadMap();      map.HideDashboard();      AddMyLayer(VELayerType.GeoRSS);   }   function AddMyLayer(type)   {      if( layerID > 1 )      {         map.DeleteAllPushpins();         map.DeleteLayer(layerID - 1);      }      var veLayerSpec = new VELayerSpecification();      veLayerSpec.Type = type;      veLayerSpec.ID = layerID;      veLayerSpec.LayerSource = "./geoaddress.geodata?mode="         + mode;      veLayerSpec.Method = 'get';      map.DeleteAllPushpins();      map.AddLayer(veLayerSpec);      layerID++;   }   function ShowGroups()   {      AddMyLayer(VELayerType.GeoRSS);   }</script><table cellpadding="0"       cellspacing="5"       border="0" width="948px"       style="border:1px solid #e6e5e5;">   <tr>      <td valign="top" style="width:698px">         <table cellpadding="0"                cellspacing="0"                border="0"                width="100%">            <tr>               <td>                  <div id='myMap' width:100%; height:400px;"></div>                  <a href="#" onclick="ShowGroups();">                     Show Top 50 Groups Map</a>&nbsp;               </td>            </tr>         </table>      </td>   </tr></table>

The following code is from the codebehind file associated with the item.

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace MyColts.Net.Composite{   public partial class CompositeVirtualEarthMap :      System.Web.UI.UserControl, IWebPart   {      #region IWebPart stuff      public string Title      {         get { return "Group and Friend Virtual Earth Mashup"; }         set { }      }      public string Subtitle      {         get { return ""; }         set { }      }      public string Description      {         get { return ""; }         set { }      }      public string TitleUrl      {         get { return ""; }         set { }      }      public string TitleIconImageUrl      {         get { return ""; }         set { }      }      public string CatalogIconImageUrl      {         get { return ""; }         set { }      }      #endregion      protected void Page_Load(object sender, EventArgs e)      { this.Page.ClientScript.RegisterStartupScript         (typeof(CompositeVirtualEarthMap), "LoadMapStartup",          "window.onload = function () { GetMap(); }; \r\n", true);      }   }}




Page 3 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Rocket Fuel