Hi,
I've just started using MapSuite webedition and zedgraphs in it and I am finally having some success, thanks to the support team here.
However I have a new query. How can I change the size of Zedgraphs with the based on the zoom level of the Map? Could anyone point me to a sample Web application.
Also I tried doing it by add a ExtentChanged eventhandler of my own. But now the extent always goes back to the initial extent .. can anyone please point out why that is? You can get an idea from the code below.
Many Thanks,
Asim.
using System;
using System.Drawing;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
using ZedGraph;
namespace Oasis
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-123.41875, 41.96396484375, -107.158984375, 30.36240234375);
Map1.MapUnit = GeographyUnit.DecimalDegree;
WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay();
Map1.CustomOverlays.Add(worldMapKitOverlay);
//Create our Zedgraph Sytle and wire up the event.
ZedGraphStyle zedGraphStyle = new ZedGraphStyle();
zedGraphStyle.ZedGraphDrawing += new EventHandler<ZedGraphDrawingEventArgs>(zedGraphStyle_ZedGraphDrawing);
// Map Extent change event.
Map1.ExtentChanged += new EventHandler<ExtentChangedEventArgs>(Map1_ExtentChanged1);
zedGraphStyle.RequiredColumnNames.Add("Reached");
zedGraphStyle.RequiredColumnNames.Add("Remaining");
zedGraphStyle.RequiredColumnNames.Add("AreaName");
ShapeFileFeatureLayer citiesLayer = new ShapeFileFeatureLayer(@"F:\Oasis\Pak Admin Bndry\Prov_Centriods.shp");
citiesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(zedGraphStyle);
citiesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(TextStyles.City3("AreaName"));
citiesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
citiesLayer.DrawingMarginPercentage = 100;
LayerOverlay staticOverlay = new LayerOverlay();
staticOverlay.Layers.Add("Cities", citiesLayer);
staticOverlay.IsBaseOverlay = false;
Map1.CustomOverlays.Add(staticOverlay);
}
private void Map1_ExtentChanged1(object sender, ExtentChangedEventArgs e)
{
Label1.Text = Label1.Text + "yeah baby!!!";
}
private void zedGraphStyle_ZedGraphDrawing(object sender, ZedGraphDrawingEventArgs e)
{
Label1.Text = Label1.Text + "yeah baby!!!";
ChangeLabelPosition(((ShapeFileFeatureLayer)((LayerOverlay)Map1.CustomOverlays[1]).Layers["Cities"]), 100);
ZedGraphControl zedGraph = new ZedGraphControl();
zedGraph.Size = new Size(100, 100);
zedGraph.GraphPane.Fill.Type = FillType.None;
zedGraph.GraphPane.Chart.Fill.Type = FillType.None;
zedGraph.GraphPane.Border.IsVisible = false;
zedGraph.GraphPane.Chart.Border.IsVisible = false;
zedGraph.GraphPane.XAxis.IsVisible = false;
zedGraph.GraphPane.YAxis.IsVisible = false;
zedGraph.GraphPane.Legend.IsVisible = false;
zedGraph.GraphPane.Title.IsVisible = false;
PieItem pieItem1 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["Reached"]), GetColorFromGeoColor(GeoColor.StandardColors.LightBlue), 0, "White");
pieItem1.LabelDetail.IsVisible = false;
PieItem pieItem2 = zedGraph.GraphPane.AddPieSlice(Convert.ToDouble(e.Feature.ColumnValues["Remaining"]), GetColorFromGeoColor(GeoColor.StandardColors.LightGreen), 0, "Asian");
pieItem2.LabelDetail.IsVisible = false;
pieItem2.Displacement = 0.2;
zedGraph.AxisChange();
e.Bitmap = zedGraph.GraphPane.GetImage();
}
private void ChangeLabelPosition(ShapeFileFeatureLayer shapeFileLayer, int graphHeight)
{
((TextStyle)shapeFileLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[1]).XOffsetInPixel = -20;
((TextStyle)shapeFileLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[1]).YOffsetInPixel = Convert.ToSingle(graphHeight * 0.4);
}
private Color GetColorFromGeoColor(GeoColor geoColor)
{
return Color.FromArgb(geoColor.AlphaComponent, geoColor.RedComponent, geoColor.GreenComponent, geoColor.BlueComponent);
}
}
}