www.pudn.com > gmap-static-2005.rar > example3.aspx.cs, change:2008-08-14,size:4187b


´╗┐using System; 
using System.Data; 
using Frameworx; 
using Frameworx.GMap; 
 
public partial class example3 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
        // create new map object 
        StaticMap.Marker marker = new StaticMap.Marker(); 
        StaticMap map = new StaticMap(); 
 
      map.Width = 300; 
      map.Height = 300; 
      map.Zoom = 16; 
      map.LatCenter = 55.8592110; 
      map.LngCenter = -4.2466380; 
 
        // add markers from datasource 
        // (in this case a temporary DataTable, it could/should come from a database or other data source) 
        DataTable dt = this.GetData(); 
 
        foreach (DataRow row in dt.Rows) 
        { 
            marker = new StaticMap.Marker(); 
            marker.Lat = Convert.ToDouble(row["Lat"]); 
            marker.Lng = Convert.ToDouble(row["Lng"]); 
 
            // convert our string values to strongly-typed enums 
            marker.Size = Tools.ConvertToEnum<StaticMap.mSize>(row["Size"].ToString()); 
            marker.Color = Tools.ConvertToEnum<StaticMap.mColor>(row["Color"].ToString()); 
 
            map.Markers.Add(marker); 
        } 
       
 
 
        // render map 
        imgMap.ImageUrl = map.Render(); 
    } 
 
    /// <summary> 
    /// Populates a temporary table with marker data 
    /// </summary> 
    /// <returns></returns> 
    /// <remarks> 
    /// In the real world, this would come from a database 
    /// </remarks> 
    private DataTable GetData() 
    { 
        DataTable dt = this.GetGeoTable(); 
 
        DataRow row = dt.NewRow(); 
 
        // eyes 
        row["Lat"] = 55.859647; row["Lng"] = -4.247010; row["Color"] = "Green"; row["Size"] = "Normal"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.859659; row["Lng"] = -4.245915; row["Color"] = "Green"; row["Size"] = "Normal"; 
        dt.Rows.Add(row); 
 
        // nose 
        row = dt.NewRow(); 
        row["Lat"] = 55.859346; row["Lng"] = -4.246452; row["Color"] = "Blue"; row["Size"] = "Small"; 
        dt.Rows.Add(row); 
 
        // mouth 
        row = dt.NewRow(); 
        row["Lat"] = 55.858996; row["Lng"] = -4.245722; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.858852; row["Lng"] = -4.245894; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.858731; row["Lng"] = -4.246237; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.858731; row["Lng"] = -4.246645; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.858816; row["Lng"] = -4.246988; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
        row = dt.NewRow(); 
        row["Lat"] = 55.858948; row["Lng"] = -4.247139; row["Color"] = "Red"; row["Size"] = "Mid"; 
        dt.Rows.Add(row); 
 
         
 
        return dt; 
    } 
 
    /// <summary> 
    /// Creates a data table 
    /// </summary> 
    /// <returns></returns> 
    private DataTable GetGeoTable() 
    { 
        DataTable dt = new DataTable(); 
 
        DataColumn dCol; 
 
        dCol = new DataColumn(); 
        dCol.DataType = Type.GetType("System.Int32"); 
        dCol.ColumnName = "id"; // primary key 
        dCol.AutoIncrement = true; 
        dt.Columns.Add(dCol); 
 
        dCol = new DataColumn(); 
        dCol.DataType = Type.GetType("System.Double"); 
        dCol.ColumnName = "Lat"; 
        dt.Columns.Add(dCol); 
 
        dCol = new DataColumn(); 
        dCol.DataType = Type.GetType("System.Double"); 
        dCol.ColumnName = "Lng"; 
        dt.Columns.Add(dCol); 
 
        dCol = new DataColumn(); 
        dCol.DataType = Type.GetType("System.String"); 
        dCol.ColumnName = "Color"; 
        dt.Columns.Add(dCol); 
 
        dCol = new DataColumn(); 
        dCol.DataType = Type.GetType("System.String"); 
        dCol.ColumnName = "Size"; 
        dt.Columns.Add(dCol); 
 
        return dt; 
    } 
 
}