Common_CustomRenderers_CSharp\LabelPointRenderer.aspx.cs
// Copyright 2010 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. // public partial class LabelPointRendererPage : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { if (!ScriptManager1.IsInAsyncPostBack) { // Potential inital load. Check if graphics resource has the graphics layer, and if not, create it ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = MapResourceManager1.ResourceItems.Find("GraphicsDataSource"); ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsMapResource = mapResourceItem.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource; if (graphicsMapResource != null) { // Check whether the map extent is null, meaning the map has not yet been initialized if (Map1.Extent == null) { // Forces earlier initialization of map and will set map extent ESRI.ArcGIS.ADF.Web.DataSources.IMapResource primaryMapResource = Map1.PrimaryMapResourceInstance; } // Call helper method in App_Code which generates a random graphics layer. In real-world situations, // the random layer could be replaced with, for instance, the result of a query. Once the layer is // created, apply the renderer and add the layer to the graphics resource. ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer = ESRI.ADF.Samples.Renderers.GenerateGraphicsHelper.CreatePointFeatures("points", Map1.Extent, 50); if (featureGraphicsLayer != null) { // Apply the LabelPointRenderer to the graphics layer ESRI.ADF.Samples.Renderers.LabelPointRenderer renderer = new ESRI.ADF.Samples.Renderers.LabelPointRenderer(); renderer.LabelColumn = "RandomName"; // Name of column that contains the label text renderer.BackgroundColor = System.Drawing.Color.FromArgb(255, 255, 255, 200); featureGraphicsLayer.Renderer = renderer; // Assign renderer // If a layer of the same name has already been added, remove it if (graphicsMapResource.Graphics.Tables.Contains("points")) graphicsMapResource.Graphics.Tables.Remove("points"); // Add the layer to the graphics resource graphicsMapResource.Graphics.Tables.Add(featureGraphicsLayer); } } // Refresh the graphics resource so the newly added layer shows up Map1.RefreshResource("GraphicsDataSource"); } } }