Common CustomDataSourceCommon_CustomDataSource_CSharp\CustomDataSourceWebApp_CSharp\Default_TileMapData.aspx.cs
// Copyright 2007 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions.
//
using System;
using System.Data;
using System.Configuration;
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;
using System.Collections;
using ESRI.ArcGIS.ADF.Web.DataSources;
public partial class _Default : System.Web.UI.Page, ICallbackEventHandler
{
public string sCallBackFunctionInvocation;
private string returnstring = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["GraphicColor"] = "Red";
Session["GraphicType"] = "Circle";
}
DropDownList1.Attributes.Add("onchange", "ChangeDDLColor()");
DropDownList2.Attributes.Add("onchange", "ChangeDDLType()");
sCallBackFunctionInvocation = Page.ClientScript.GetCallbackEventReference(this, "message", "HandleResponse", "context", "postBackError", true);
}
#region ICallbackEventHandler Members
string ICallbackEventHandler.GetCallbackResult()
{
return returnstring;
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgs)
{
char[] parser_char = { ',' };
if (eventArgs.Contains("ddl_color"))
{
string[] messages = eventArgs.Split(parser_char);
string graphiccolor = messages[1];
Session["GraphicColor"] = graphiccolor;
}
else if (eventArgs.Contains("ddl_type"))
{
string[] messages = eventArgs.Split(parser_char);
string graphictype = messages[1];
Session["GraphicType"] = graphictype;
}
}
#endregion
protected void Button1_Click(object sender, EventArgs e)
{
HttpPostedFile MyFile = FileUpload1.PostedFile;
int FileLen;
System.IO.Stream MyStream = null;
FileLen = MyFile.ContentLength;
byte[] input = new byte[FileLen];
MyStream = MyFile.InputStream;
System.IO.StreamReader reader;
reader = new System.IO.StreamReader(MyStream, System.Text.Encoding.ASCII);
string str;
System.Collections.ArrayList alist = new System.Collections.ArrayList();
char[] parser_char = { ',' };
do
{
str = reader.ReadLine();
if (str != null)
{
string[] messages = str.Split(parser_char);
double x = Double.Parse(messages[0]);
double y = Double.Parse(messages[1]);
ESRI.ArcGIS.ADF.Web.Geometry.Point point = new ESRI.ArcGIS.ADF.Web.Geometry.Point(x, y);
alist.Add(point);
System.Diagnostics.Debug.WriteLine(str);
}
} while (str != null);
IEnumerable gfc = Map1.GetFunctionalities();
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;
foreach (IGISFunctionality gfunc in gfc)
{
if (gfunc.Resource is ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)
{
gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
break;
}
}
if (gResource == null)
return;
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;
if (glayer == null)
{
glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
glayer.TableName = "Uploaded Points";
gResource.Graphics.Tables.Add(glayer);
}
foreach (ESRI.ArcGIS.ADF.Web.Geometry.Point pnt in alist)
{
ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol sms = new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();
sms.Color = System.Drawing.Color.FromName((string)Session["GraphicColor"]);
string graphictype = (string)Session["GraphicType"];
if (graphictype == "Circle")
{
sms.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Circle;
}
else if (DropDownList2.SelectedValue == "Square")
{
sms.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Square;
}
else
{
sms.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Star;
}
sms.Width = 14;
sms.OutlineColor = System.Drawing.Color.Black;
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(pnt, sms, null);
glayer.Add(ge);
}
if (Map1.ImageBlendingMode == ESRI.ArcGIS.ADF.Web.UI.WebControls.ImageBlendingMode.Browser)
{
Map1.RefreshResource(gResource.Name);
}
else
{
Map1.Refresh();
}
Toc1.Refresh();
Map1.CallbackResults.CopyFrom(Toc1.CallbackResults);
}
}