using System; using System.Web.UI; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; using System.Collections.ObjectModel; namespace CSSamples.Samples.MapShapes { public partial class TrackShapeFinishedEvent : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.CurrentExtent = new RectangleShape(-131.22, 55.05, -54.03, 16.91); Map1.MapUnit = GeographyUnit.DecimalDegree; WorldMapKitWmsWebOverlay worldMapKitWmsWebOverlay = new WorldMapKitWmsWebOverlay(); Map1.CustomOverlays.Add(worldMapKitWmsWebOverlay); InMemoryFeatureLayer shapeLayer = new InMemoryFeatureLayer(); shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(180, 102, 255, 102), 10, GeoColor.StandardColors.DarkGreen, 1); shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Green, 4, true); shapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(180, 102, 255, 102), GeoColor.StandardColors.DarkGreen, 1); shapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; shapeLayer.DrawingQuality = DrawingQuality.HighQuality; LayerOverlay dynamicOverlay = new LayerOverlay("DynamicOverlay"); dynamicOverlay.IsBaseOverlay = false; dynamicOverlay.TileType = TileType.SingleTile; dynamicOverlay.Layers.Add("shapeLayer", shapeLayer); Map1.CustomOverlays.Add(dynamicOverlay); InMemoryMarkerOverlay markerOverlay = new InMemoryMarkerOverlay("MarkerOverlay"); markerOverlay.Features.Add("Kansas", new Feature(-94.48242, 38.75977)); markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("../../theme/default/img/marker_blue.gif", 21, 25); markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.CustomOverlays.Add(markerOverlay); } } protected void buttonDrawPoint_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Point; } protected void buttonDrawLine_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Line; } protected void buttonDrawRectangle_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Rectangle; } protected void buttonDrawSquare_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Square; } protected void buttonDrawPolygon_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Polygon; } protected void buttonDrawCircle_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Circle; } protected void buttonDrawEllipse_Click(object sender, ImageClickEventArgs e) { Map1.EditOverlay.TrackMode = TrackMode.Ellipse; } protected void buttonEditShape_Click(object sender, ImageClickEventArgs e) { LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"]; InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"]; foreach (Feature feature in shapeLayer.InternalFeatures) { Map1.EditOverlay.Features.Add(feature.Id, feature); } shapeLayer.InternalFeatures.Clear(); Map1.EditOverlay.TrackMode = TrackMode.Edit; dynamicOverlay.Redraw(); } protected void Map1_TrackShapeFinished(object sender, EventArgs e) { LayerOverlay dynamicOverlay = (LayerOverlay)Map1.CustomOverlays["DynamicOverlay"]; InMemoryFeatureLayer shapeLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["shapeLayer"]; InMemoryMarkerOverlay markerOverlay = (InMemoryMarkerOverlay)Map1.CustomOverlays["MarkerOverlay"]; foreach (Feature feature in Map1.EditOverlay.Features) { Collection returnMarkers = new Collection(); MarkerZoomLevel zoomLevel = markerOverlay.ZoomLevelSet.GetZoomLevelForDrawing(GetZoomFromScale(Map1.CurrentScale, Map1.ClientZoomLevelScales)); if (zoomLevel != null) { markerOverlay.FeatureSource.Open(); //returnMarkers include all markers contained within that shape returnMarkers = zoomLevel.GetMarkers(markerOverlay.FeatureSource.GetFeaturesInsideBoundingBox(feature.GetShape().GetBoundingBox(), ReturningColumnsType.NoColumns)); markerOverlay.FeatureSource.Close(); } shapeLayer.InternalFeatures.Add(feature.Id, feature); } Map1.EditOverlay.Features.Clear(); dynamicOverlay.Redraw(); } internal static int GetZoomFromScale(double scale, Collection zoomLevelSets) { int zoomLevel = 0; int counter = 0; foreach (double zoomLevelScale in zoomLevelSets) { if (counter == 0) { counter++; } else if (scale <= zoomLevelScale) { counter++; zoomLevel++; } else { break; } } return zoomLevel; } } }