using System; using System.Collections.Generic; using System.Drawing; using System.Web; using System.Web.Mvc; using System.Web.UI.WebControls; using ThinkGeo.MapSuite.Core; namespace ThinkGeo.MapSuite.MvcEdition { public class MyOverlay : LayerOverlay { public MyOverlay() : base() { } protected override void DrawCore(GeoCanvas canvas, object nativeImage, RectangleShape canvasExtent, GeographyUnit mapUnit) { base.DrawCore(canvas, nativeImage, canvasExtent, mapUnit); Bitmap bitmap = nativeImage as Bitmap; bitmap.Save("d:\\" + canvasExtent.ToString() + ".bmp"); } } [Serializable] public class MyCollection : OverlayCollection { private Map map; public MyCollection(Map map) : base(map) { this.map = map; } public LayerOverlaySetting MyOverlay() { MyOverlay overlay = new MyOverlay(); this.map.CustomOverlays.Add(overlay); return new LayerOverlaySetting(overlay); } } public static class MyHtmlHelperExtension { public static MyMvcControlCollection MyThinkGeo(this HtmlHelper helper) { ViewContext viewContext = helper.ViewContext; HttpContextBase httpContext = viewContext.HttpContext; return new MyMvcControlCollection(helper); } } public class MyMvcControlCollection : MvcControlCollection { private Dictionary mapControlBuilders; private HtmlHelper HtmlHelper; public MyMvcControlCollection(HtmlHelper htmlHelper) : base(htmlHelper) { this.HtmlHelper = htmlHelper; } public MapBuilder Map() { return Map(Guid.NewGuid().ToString()); } public MyMapBuilder MyMap(string name) { return MyMap(name, 640, 480); } public MyMapBuilder MyMap(string name, Unit width, Unit height) { if (mapControlBuilders == null) { mapControlBuilders = new Dictionary(); } if (mapControlBuilders.ContainsKey(name)) { mapControlBuilders.Remove(name); } Map map = new Map(name, width, height); MyMapBuilder mapBuilder = new MyMapBuilder(map, HtmlHelper.ViewContext); mapControlBuilders.Add(name, mapBuilder); return mapBuilder; } } public class MyMapBuilder : MapBuilder { public MyMapBuilder(Map map, ViewContext viewContext) : base(map, viewContext) { overlayCollection = new MyCollection(map); } public MapBuilder CustomOverlays(Action addOverlayAction) { addOverlayAction((MyCollection)overlayCollection); return this; } } }