ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public partial class BuildIndexTool : Form { private Collection<string> files; public Collection<string> Files { get { return files; } } public BuildIndexTool() : this(new Collection<string>()) { } internal BuildIndexTool(Collection<string> buildIndexFiles) { files = buildIndexFiles; InitializeComponent(); } private void btnCancel_Click(object sender, EventArgs e) { Close(); } private void ProgressBar_Load(object sender, EventArgs e) { this.Size = new Size(this.Size.Width, 50); progressBar1.Minimum = 1; progressBar1.Maximum = files.Count; progressBar1.Value = 1; progressBar1.Step = 1; } private void BuildIndexTool_Shown(object sender, EventArgs e) { BuildIndex(); Close(); } private void BuildIndex() { if (files != null) { for (int i = 0; i < files.Count; i++) { ShapeFileFeatureLayer.BuildIndexFile(files[i], BuildIndexMode.Rebuild); progressBar1.PerformStep(); } } } } }
using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public struct FeatureInfo { private Feature feature; private string shapeName; public Feature Feature { get { return feature; } set { feature = value; } } public string ShapeName { get { return shapeName; } set { shapeName = value; } } public override bool Equals(object obj) { if (obj == null) { return false; } if (obj is FeatureInfo) { return Equals((FeatureInfo)obj); } return false; } public override int GetHashCode() { return feature.GetHashCode() ^ shapeName.GetHashCode(); } public static bool operator ==(FeatureInfo featureInfo1, FeatureInfo featureInfo2) { return featureInfo1.Equals(featureInfo2); } public static bool operator !=(FeatureInfo featureInfo1, FeatureInfo featureInfo2) { return !(featureInfo1 == featureInfo2); } private bool Equals(FeatureInfo featureInfo) { if (this.feature != featureInfo.feature) { return false; } if (this.shapeName != featureInfo.shapeName) { return false; } return true; } } }
using System; using System.Data; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public partial class FormFeatures : Form { private string tableName; private ShapeFileFeatureLayer shapeFileLayer; public string TableName { get { return tableName; } set { tableName = value; } } public ShapeFileFeatureLayer ShapeFileLayer { get { return shapeFileLayer; } set { shapeFileLayer = value; } } public FormFeatures() { InitializeComponent(); } private void frmFeatures_Load(object sender, EventArgs e) { this.Text = "Features - " + shapeFileLayer.Name; dgridFeatures.DataSource = null; this.txtSql.Text = "Select TOP 100 * From " + TableName; ExecuteSql(); } private void btnExecuteSql_Click(object sender, EventArgs e) { ExecuteSql(); } private void ExecuteSql() { try { shapeFileLayer.Open(); DataTable dataTable = shapeFileLayer.QueryTools.ExecuteQuery(txtSql.Text); dgridFeatures.DataSource = dataTable; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); } finally { if (shapeFileLayer.IsOpen) { shapeFileLayer.Close(); } } } } }
using System.Collections.ObjectModel; using System.Windows.Forms; namespace MapSuiteExplorer { public partial class FormInformation : Form { private Collection<FeatureInfo> featuresInfo; public Collection<FeatureInfo> FeaturesInfo { get { return featuresInfo; } } public FormInformation() : this(new Collection<FeatureInfo>()) { } public FormInformation(Collection<FeatureInfo> featuresInfo) { this.featuresInfo = featuresInfo; InitializeComponent(); } private void btnOK_Click(object sender, System.EventArgs e) { Close(); } private void lstSelectedItems_SelectedIndexChanged(object sender, System.EventArgs e) { lstAssociatedData.Items.Clear(); foreach (string key in featuresInfo[this.lstSelectedItems.SelectedIndex].Feature.ColumnValues.Keys) { lstAssociatedData.Items.Add(key + ": " + featuresInfo[lstSelectedItems.SelectedIndex].Feature.ColumnValues[key]); } } private void frmInformation_Load(object sender, System.EventArgs e) { lstSelectedItems.Items.Clear(); for (int i = 0; i < featuresInfo.Count; i++) { lstSelectedItems.Items.Add(FeaturesInfo[i].ShapeName + " - " + FeaturesInfo[i].Feature.Id); } lstSelectedItems.SelectedIndex = 0; } } }
using System; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { internal partial class FormStyleEditor : Form { private StyleEditor styleEditor; private FeatureLayer baseLayer; private string shapeName; private StyleType currentStyleType; internal FeatureLayer BaseLayer { get { return baseLayer; } set { baseLayer = value; } } internal string ShapeName { get { return shapeName; } set { shapeName = value; } } internal StyleType CurrentStyleType { get { return currentStyleType; } set { currentStyleType = value; } } internal FormStyleEditor() { InitializeComponent(); } private void frmStyleEditor_Load(object sender, EventArgs e) { this.Text = "Style Editor - " + ShapeName; styleEditor = new StyleEditor(); styleEditor.AreaStyle = BaseLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle; styleEditor.LineStyle = BaseLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle; styleEditor.PointStyle = BaseLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle; styleEditor.TextStyle = BaseLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle; switch (currentStyleType) { case StyleType.Area: tabControl1.SelectedTab = tabPageAreaStyle; break; case StyleType.Line: tabControl1.SelectedTab = tabPageLineStyle; break; case StyleType.Point: tabControl1.SelectedTab = tabPagePointStyle; break; case StyleType.Text: tabControl1.SelectedTab = tabPageTextStyle; break; case StyleType.Custom: break; default: break; } } private void tabPageAreaStyle_Enter(object sender, EventArgs e) { styleEditor.StyleType = StyleType.Area; if (!tabPageAreaStyle.Controls.Contains(styleEditor)) { tabPageAreaStyle.Controls.Add(styleEditor); } } private void tabPageLineStyle_Enter(object sender, EventArgs e) { styleEditor.StyleType = StyleType.Line; if (!tabPageLineStyle.Controls.Contains(styleEditor)) { tabPageLineStyle.Controls.Add(styleEditor); } } private void tabPagePointStyle_Enter(object sender, EventArgs e) { styleEditor.StyleType = StyleType.Point; if (!tabPagePointStyle.Controls.Contains(styleEditor)) { tabPagePointStyle.Controls.Add(styleEditor); } } private void tabPageTextStyle_Enter(object sender, EventArgs e) { styleEditor.StyleType = StyleType.Text; if (!tabPageTextStyle.Controls.Contains(styleEditor)) { tabPageTextStyle.Controls.Add(styleEditor); } } private void btnOk_Click(object sender, EventArgs e) { currentStyleType = styleEditor.StyleType; Close(); } private void btnCancel_Click(object sender, EventArgs e) { Close(); } } }
using System; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public partial class GeographyUnitTool : Form { private GeographyUnit currentUnit; public GeographyUnit CurrentUnit { get { return currentUnit; } set { currentUnit = value; } } public GeographyUnitTool() { InitializeComponent(); } private void GeographyUnitTool_Load(object sender, EventArgs e) { comboBox1.Text = currentUnit.ToString(); } private void btnSetUnit_Click(object sender, EventArgs e) { switch (comboBox1.Text) { case "Unknown": currentUnit = GeographyUnit.Unknown; break; case "DecimalDegree": currentUnit = GeographyUnit.DecimalDegree; break; case "Feet": currentUnit = GeographyUnit.Feet; break; case "Meter": currentUnit = GeographyUnit.Meter; break; default: break; } Close(); } } }
using System; using System.Collections.ObjectModel; using System.Drawing; using System.Globalization; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; using System.Collections.Generic; using System.Diagnostics; namespace MapSuiteExplorer { internal partial class MainForm : Form { private const int splitterDistance = 142; private const int widthOfThemeView = 140; private ModeType mode; private FormFeatures frmFeatures; private MapEngine mapEngine; private Bitmap bitmap; private Image cacheBitmap; // toggle and previous extents private Collection<RectangleShape> cacheExtents; private int extentsCurrentIndex; // for track zoom in private Point mouseStart; private Point mouseCurrent; private bool isMouseDown; // for pan private Point mouseOffset; // set selected themeItem which will move up/down private int selectedOrder = -1; private Collection<string> filesWithoutIndex; private Collection<string> addedFiles; private bool isNotScrollBarChangeSize; private Int32 id = 100;// HotKey id private const int WM_HOTKEY = 0x0312;// HotKey message private GeographyUnit mapUnit; private ModeType Mode { get { return mode; } set { mode = value; if (!this.DesignMode) { SetCursor(); } } } internal MainForm() { mapEngine = new MapEngine(); cacheExtents = new Collection<RectangleShape>(); filesWithoutIndex = new Collection<string>(); addedFiles = new Collection<string>(); InitializeComponent(); mapUnit = GeographyUnit.DecimalDegree; txtMapUnit.Text = mapUnit.ToString(); this.MouseWheel += new MouseEventHandler(MainForm_MouseWheel); this.themeView.ThemeViewDragDrop += new EventHandler<DragDropItemEventArgs>(themeView_ThemeViewDragDrop); this.themeView.VScrollVisible += new EventHandler<EventArgs>(themeView_VScrollVisible); } private void MainForm_Load(object sender, EventArgs e) { RegHotkey(); SetupContextMenu(); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.White); bitmap = new Bitmap(map.Width, map.Height); SetScaleLineAdornment(); } private void SetScaleLineAdornment() { ScaleLineAdornmentLayer scaleLine = new ScaleLineAdornmentLayer(AdornmentLocation.LowerLeft); scaleLine.XOffsetInPixel = 5; scaleLine.YOffsetInPixel = -5; mapEngine.AdornmentLayers.Add("ScaleLine", scaleLine); } private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { UnRegHotKey(); } protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY) { DoHotkey(m); } base.WndProc(ref m); } private void DoHotkey(Message m) { IntPtr i = m.WParam; if (i.ToInt32() == id) { SetMapUnit(); } } private void SetMapUnit() { GeographyUnitTool geographyUnitTool = new GeographyUnitTool(); geographyUnitTool.CurrentUnit = mapUnit; geographyUnitTool.ShowDialog(); if (mapUnit != geographyUnitTool.CurrentUnit) { mapUnit = geographyUnitTool.CurrentUnit; txtMapUnit.Text = mapUnit.ToString(); DrawImage(); } } private void SetupContextMenu() { foreach (ToolStripItem item in mnuCurrentLayer.DropDownItems) { if (item is ToolStripSeparator) { contextMenuStrip.Items.Add(new ToolStripSeparator()); continue; } ToolStripItem contextItem = new ToolStripMenuItem(item.Text, item.Image); contextItem.Tag = item.Tag; contextItem.Click += new EventHandler(MenuItem_Click); contextMenuStrip.Items.Add(contextItem); } } private void MainForm_DragEnter(object sender, DragEventArgs e) { e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? e.Effect = DragDropEffects.All : DragDropEffects.None; } private void MainForm_DragDrop(object sender, DragEventArgs e) { string[] draggedPaths = (string[])e.Data.GetData(DataFormats.FileDrop); if ((draggedPaths != null) && (draggedPaths.Length > 0)) { filesWithoutIndex.Clear(); addedFiles.Clear(); foreach (string draggedPath in draggedPaths) { if (draggedPath.EndsWith(".shp", StringComparison.OrdinalIgnoreCase) && File.Exists(draggedPath)) { AddLayers(draggedPath, false); continue; } if (IsRasterLayerFile(draggedPath) && File.Exists(draggedPath)) { AddRasterLayers(new string[] { draggedPath }); continue; } if (Directory.Exists(draggedPath)) { AddLayersByFolder(draggedPath, false); continue; } } if (filesWithoutIndex.Count > 0) { CancelAddingLayer(); } // first layer will assign fullextent to current, otherwise keep current. if (mapEngine.CurrentExtent.Width == CustomRectangleShape.CustomTolerance) { // GetFullExtent will automatic Open layer, layer.IsOpen will be true. RectangleShape currentBoundingBox = GetFullExtent(map.Width, map.Height); if (currentBoundingBox != null) { mapEngine.CurrentExtent = currentBoundingBox; } } themeView.SetupItems(); DrawImage(); } } private RectangleShape GetFullExtent(float screenWidth, float screenHeight) { RectangleShape boundingBox = null; foreach (Layer layer in mapEngine.StaticLayers) { if (layer.HasBoundingBox) { if (!layer.IsOpen) { layer.Open(); } if (boundingBox == null) { boundingBox = layer.GetBoundingBox(); } else { boundingBox.ExpandToInclude(layer.GetBoundingBox()); } } } foreach (Layer layer in mapEngine.DynamicLayers) { if (layer.HasBoundingBox) { if (!layer.IsOpen) { layer.Open(); } if (boundingBox == null) { boundingBox = layer.GetBoundingBox(); } else { boundingBox.ExpandToInclude(layer.GetBoundingBox()); } } } if (boundingBox != null) { boundingBox = MapEngine.GetDrawingExtent(boundingBox, screenWidth, screenHeight); } return boundingBox; } private void MainForm_MouseWheel(object sender, MouseEventArgs e) { Byte noMeaning = e.Delta > 0 ? ZoomInOut(ZoomType.ZoomIn) : ZoomInOut(ZoomType.ZoomOut); } private void map_MouseDown(object sender, MouseEventArgs e) { if (mapEngine.StaticLayers.Count > 0) { switch (Mode) { case ModeType.Information: if (e.Button == MouseButtons.Left) { SelectInformation(ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, e.X, e.Y, map.Width, map.Height)); } break; case ModeType.Pan: if (e.Button == MouseButtons.Left) { mouseStart = e.Location; mouseOffset = new Point(); isMouseDown = true; cacheBitmap = map.Image; map.Image = null; } break; case ModeType.TrackZoomIn: if (e.Button == MouseButtons.Left) { mouseStart = e.Location; isMouseDown = true; return; } if (e.Button == MouseButtons.Right) { ZoomInOut(ZoomType.ZoomOut); return; } break; default: break; } } } private void map_MouseMove(object sender, MouseEventArgs e) { if (mapEngine.StaticLayers.Count > 0) { ShowCoordinate(e); if (isMouseDown) { switch (Mode) { case ModeType.Pan: mouseOffset = GetMouseOffset(e); map.Invalidate(); break; case ModeType.TrackZoomIn: if (e.Button == MouseButtons.Left) { mouseCurrent = e.Location; map.Invalidate(); } break; default: break; } } } } private Point GetMouseOffset(MouseEventArgs e) { int x = Math.Max(Math.Min(e.X, map.Width), 0); int y = Math.Max(Math.Min(e.Y, map.Height), 0); return new Point(x, y) - (Size)mouseStart; } /// <summary> /// Register HotKey /// </summary> private void RegHotkey() { id = this.GetType().GetHashCode(); //0 is none,1 is Alt,2 is Control,4 is Shift,8 is Windows NativeMethods.RegisterHotKey(this.Handle, id, 7, Keys.D8);//Ctrl+Shift+Alt+8 } private void UnRegHotKey() { NativeMethods.UnregisterHotKey(this.Handle, id); } private void ShowCoordinate(MouseEventArgs e) { PointShape WorldPointR = mapEngine.ToWorldCoordinate(e.X, e.Y, map.Width, map.Height); statusStrip.Items[1].Text = string.Format(CultureInfo.InvariantCulture, "X: {0:F4} Y: {1:F4}", WorldPointR.X, WorldPointR.Y); statusStrip.Items[2].Text = string.Format(CultureInfo.InvariantCulture, "X: {0} Y: {1}", e.X, e.Y); // TODO: the mapUnit now is always equal to DecimalDegree. if (mapUnit == GeographyUnit.DecimalDegree && ((WorldPointR.X > -180 && WorldPointR.X < 180 && WorldPointR.Y > -90 && WorldPointR.Y < 90))) { statusStrip.Items[0].Text = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(WorldPointR); return; } statusStrip.Items[0].Text = ""; } private void map_MouseUp(object sender, MouseEventArgs e) { if (isMouseDown && (mapEngine.StaticLayers.Count > 0)) { switch (Mode) { case ModeType.Pan: if (e.Button == MouseButtons.Left) { Point offset = e.Location - (Size)mouseStart; double extentWidth = mapEngine.CurrentExtent.Width; double extentHeight = mapEngine.CurrentExtent.Height; double widthFactor = -(double)offset.X / map.Width; double heightFactor = (double)offset.Y / map.Height; mapEngine.CurrentExtent.TranslateByOffset(extentWidth * widthFactor, extentHeight * heightFactor, GeographyUnit.Meter, DistanceUnit.Meter); DrawImage(); } break; case ModeType.TrackZoomIn: if (mouseStart.X != e.X && mouseStart.Y != e.Y) { double startX = Math.Min(mouseStart.X, e.X); double startY = Math.Min(mouseStart.Y, e.Y); double endX = Math.Max(mouseStart.X, e.X); double endY = Math.Max(mouseStart.Y, e.Y); double widthFactor = mapEngine.CurrentExtent.Width / map.Width; double heightFactor = mapEngine.CurrentExtent.Height / map.Height; double upperLeftX = +(startX * widthFactor + mapEngine.CurrentExtent.UpperLeftPoint.X); double upperLeftY = -(startY * heightFactor - mapEngine.CurrentExtent.UpperLeftPoint.Y); double lowerRightX = +(endX * widthFactor + mapEngine.CurrentExtent.UpperLeftPoint.X); double lowerRightY = -(endY * heightFactor - mapEngine.CurrentExtent.UpperLeftPoint.Y); RectangleShape currentExtent = new RectangleShape(upperLeftX, upperLeftY, lowerRightX, lowerRightY); mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(currentExtent, map.Width, map.Height); DrawImage(); } break; default: break; } } mouseStart = new Point(); isMouseDown = false; } private void map_Paint(object sender, PaintEventArgs e) { if (isMouseDown) { switch (Mode) { case ModeType.Pan: e.Graphics.DrawImageUnscaled(cacheBitmap, mouseOffset.X, mouseOffset.Y); break; case ModeType.TrackZoomIn: Graphics graphics = e.Graphics; int startX = Math.Min(mouseStart.X, mouseCurrent.X); int startY = Math.Min(mouseStart.Y, mouseCurrent.Y); int endX = Math.Max(mouseStart.X, mouseCurrent.X); int endY = Math.Max(mouseStart.Y, mouseCurrent.Y); graphics.DrawRectangle(new Pen(Color.Black, 2), new Rectangle(startX, startY, endX - startX, endY - startY)); graphics.FillRectangle(new SolidBrush(Color.FromArgb(80, 239, 251, 239)), new Rectangle(startX, startY, endX - startX, endY - startY)); break; default: break; } } } private void map_ClientSizeChanged(object sender, EventArgs e) { bitmap = new Bitmap(map.Width, map.Height); DrawImage(); } private void mnuHelpAbout_Click(object sender, EventArgs e) { FormAbout frmAbout = new FormAbout(); frmAbout.ShowDialog(); } private void mnuHelpDiscussionForums_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start(Properties.Resources.DiscussionForum); } private void themeItem_ThemeItemClick(object sender, LayerOrderEventArgs e) { for (int i = 0; i < themeView.Items.Count; i++) { if (e.Name == themeView.Items[i].ShapeName) { selectedOrder = i; themeView.Items[i].BorderStyle = BorderStyle.Fixed3D; themeView.Items[i].BackColor = Color.FromArgb(100, 74, 142, 207); continue; } themeView.Items[i].BorderStyle = BorderStyle.FixedSingle; themeView.Items[i].BackColor = Color.White; } } private void themeItem_ItemLinkClicked(object sender, ShapeLinkClickedEventArgs e) { switch (e.LinkType) { case LinkType.Edit: EditLayerStyle(e.ShapeName); break; case LinkType.Features: ShowAllFeatures(e.ShapeName); break; case LinkType.Remove: RemoveShapefile(e.ShapeName); break; case LinkType.ZoomToExtent: TrackToExtent(e.ShapeName); break; default: break; } } private void themeItem_ItemCheckedChanged(object sender, ShapeEventArgs e) { if (mapEngine.StaticLayers.Contains(e.ShapeName)) { mapEngine.StaticLayers[e.ShapeName].IsVisible = e.IsShow; try { DrawImage(); } catch { } } } private void mnuFileAddNewLayer_Click(object sender, EventArgs e) { AddLayersByOpenFileDialog(); } private void mnuRemoveAll_Click(object sender, EventArgs e) { RemoveAllShapefiles(); } private void mnuFileExit_Click(object sender, EventArgs e) { Close(); } private void MenuItem_Click(object sender, EventArgs e) { ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem; if (toolStripMenuItem != null) { Action(toolStripMenuItem.Tag.ToString()); } } private void ToolBar_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripButton button = e.ClickedItem as ToolStripButton; if (button != null) { Action(button.Tag.ToString()); } } private void themeView_ThemeViewDragDrop(object sender, DragDropItemEventArgs e) { mapEngine.StaticLayers.MoveTo(e.FromOrder, e.ToOrder); DrawImage(); selectedOrder = e.ToOrder; } private void themeView_VScrollVisible(object sender, EventArgs e) { // to avoid duplicate paint when Scroll Bar Change Size isNotScrollBarChangeSize = true; if (themeView.VerticalScroll.Visible) { splitContainer.SplitterDistance = splitterDistance + 16; themeView.Width = widthOfThemeView + 16; } else { splitContainer.SplitterDistance = splitterDistance; themeView.Width = widthOfThemeView; } isNotScrollBarChangeSize = false; } private void themeItem_ThemeItemRightClick(object sender, RightClickEventArgs e) { contextMenuStrip.Show(e.Point); } private void SetBackgroudColor() { if (colorDialog.ShowDialog() == DialogResult.OK) { GeoColor geocolor = new GeoColor(colorDialog.Color.R, colorDialog.Color.G, colorDialog.Color.B); mapEngine.BackgroundFillBrush = new GeoSolidBrush(geocolor); DrawImage(); } } // use OpenFileDialog private void AddLayersByOpenFileDialog() { if (openFileDialog.ShowDialog() == DialogResult.OK) { filesWithoutIndex.Clear(); Collection<string> rasterFilenames = new Collection<string>(); Collection<string> featureFilenames = new Collection<string>(); foreach (string filename in openFileDialog.FileNames) { if (IsRasterLayerFile(filename)) { rasterFilenames.Add(filename); } else { featureFilenames.Add(filename); } } AddLayers(featureFilenames, true); AddRasterLayers(rasterFilenames); if (filesWithoutIndex.Count > 0) { CancelAddingLayer(); } // first layer will assign fullextent to current, otherwise keep current. if (mapEngine.CurrentExtent.Width == CustomRectangleShape.CustomTolerance) { // GetFullExtent will automatic Open layer, layer.IsOpen will be true. RectangleShape currentBoundingBox = GetFullExtent(map.Width, map.Height); if (currentBoundingBox != null) { mapEngine.CurrentExtent = currentBoundingBox; } } themeView.SetupItems(); DrawImage(); } } /// <summary> /// Cancel Adding Layer or not /// </summary> /// <returns> /// true: Cancel /// false: Yes,No /// </returns> private void CancelAddingLayer() { //bool isCancel = false; string buildIndexMessage = string.Format(Properties.Resources.BuildIndexFilePrompt, filesWithoutIndex[0]); DialogResult result = MessageBox.Show(buildIndexMessage, "Build Index File", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); Application.DoEvents(); switch (result) { case DialogResult.Cancel: //isCancel = true; foreach (string fileName in addedFiles) { FileInfo fileInfo = new FileInfo(fileName); string shapeName = fileInfo.Name; mapEngine.StaticLayers.Remove(shapeName); if (themeView.Items.Contains(shapeName)) { themeView.Items.Remove(shapeName); } } themeView.SetupItems(); break; //case DialogResult.No: // isCancel = false; // break; case DialogResult.Yes: case DialogResult.OK: //isCancel = false; BuildIndexTool buildIndexTool = new BuildIndexTool(filesWithoutIndex); buildIndexTool.ShowDialog(); break; default: break; } //return isCancel; } private void ToggleMapExtents() { if (extentsCurrentIndex < cacheExtents.Count - 1) { mapEngine.CurrentExtent = cacheExtents[++extentsCurrentIndex]; DrawImage(); } } private void GetPreviousExtent() { if (extentsCurrentIndex > 0) { mapEngine.CurrentExtent = cacheExtents[--extentsCurrentIndex]; DrawImage(); } } private static void SetStyleByWellKnownType(ShapeFileFeatureLayer layer) { if (layer.Name.IndexOf("thinkgeo", StringComparison.OrdinalIgnoreCase) != -1) { layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GetRandomColor(ColorType.Bright), 1)); layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(190, GetRandomColor(ColorType.All))), new GeoPen(GeoColor.StandardColors.Black), 9); layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1), new GeoSolidBrush(new GeoColor(65, GetRandomColor(ColorType.All)))); return; } layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.SimpleColors.Black, 1); layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.Black), 9); layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen = new GeoPen(GeoColor.SimpleColors.Black, 1); } private static GeoColor GetRandomColor(ColorType ColorType) { GeoColor randomColor = new GeoColor(); Random random = new Random(); int Number = random.Next(0, 10); switch (ColorType) { case ColorType.All: { int R = random.Next(0, 255); int G = random.Next(0, 255); int B = random.Next(0, 255); randomColor = GeoColor.FromArgb(255, R, G, B); } break; case ColorType.Bright: { GeoColor[] Colors = new GeoColor[10]; Colors[0] = GeoColor.StandardColors.Blue; Colors[1] = GeoColor.StandardColors.Green; Colors[2] = GeoColor.StandardColors.Red; Colors[3] = GeoColor.StandardColors.Orange; Colors[4] = GeoColor.StandardColors.Magenta; Colors[5] = GeoColor.StandardColors.LimeGreen; Colors[6] = GeoColor.StandardColors.Brown; Colors[7] = GeoColor.StandardColors.Yellow; Colors[8] = GeoColor.StandardColors.Purple; Colors[9] = GeoColor.StandardColors.Maroon; randomColor = Colors[Number]; } break; case ColorType.Pastel: { GeoColor[] Colors = new GeoColor[10]; Colors[0] = GeoColor.StandardColors.LightBlue; Colors[1] = GeoColor.StandardColors.LightCoral; Colors[2] = GeoColor.StandardColors.LightCyan; Colors[3] = GeoColor.StandardColors.LightGreen; Colors[4] = GeoColor.StandardColors.LightGoldenrodYellow; Colors[5] = GeoColor.StandardColors.LightSkyBlue; Colors[6] = GeoColor.StandardColors.LightSteelBlue; Colors[7] = GeoColor.StandardColors.LightPink; Colors[8] = GeoColor.StandardColors.LightSalmon; Colors[9] = GeoColor.StandardColors.LightSeaGreen; randomColor = Colors[Number]; } break; } return randomColor; } private void SetupThemeItem(Layer layer, bool isSetupItems) { ThemeItem themeItem = new ThemeItem(); themeItem.ShapeName = layer.Name; themeItem.ItemCheckedChanged += new EventHandler<ShapeEventArgs>(themeItem_ItemCheckedChanged); themeItem.ItemLinkClicked += new EventHandler<ShapeLinkClickedEventArgs>(themeItem_ItemLinkClicked); themeItem.ThemeItemClick += new EventHandler<LayerOrderEventArgs>(themeItem_ThemeItemClick); themeItem.ThemeItemRightClick += new EventHandler<RightClickEventArgs>(themeItem_ThemeItemRightClick); themeView.Items.Add(layer.Name, themeItem); if (isSetupItems) { themeView.SetupItems(); } } private void TrackToExtent() { if (selectedOrder == -1) { MessageBox.Show(Properties.Resources.NoLayerSelected, "No Layer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } TrackToExtentCore(mapEngine.StaticLayers[selectedOrder]); } private void TrackToExtent(string shapeName) { if (mapEngine.StaticLayers.Contains(shapeName)) { TrackToExtentCore(mapEngine.StaticLayers[shapeName]); } } private void TrackToExtentCore(Layer layer) { layer.Open(); RectangleShape extent = layer.GetBoundingBox(); layer.Close(); mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(extent, map.Width, map.Height); DrawImage(); } private void EditLayerStyle() { if (selectedOrder == -1) { MessageBox.Show(Properties.Resources.NoLayerSelected, "No Layer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } EditLayerStyleCore(mapEngine.StaticLayers[selectedOrder] as FeatureLayer); } private void EditLayerStyle(string shapeName) { if (mapEngine.StaticLayers.Contains(shapeName)) { EditLayerStyleCore(mapEngine.StaticLayers[shapeName] as FeatureLayer); } } private void EditLayerStyleCore(FeatureLayer layer) { if (layer != null) { FormStyleEditor frmStyleEditor = new FormStyleEditor(); frmStyleEditor.ShapeName = layer.Name; frmStyleEditor.BaseLayer = layer; // store layer status and will recover it after serialize/deserialize bool isOpened = layer.IsOpen; // close layer to avoid serialize exception layer.Close(); MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); // use serialize to clone layer formatter.Serialize(stream, layer); frmStyleEditor.CurrentStyleType = themeView.Items[selectedOrder].StyleType; if (frmStyleEditor.ShowDialog() == DialogResult.OK) { themeView.Items[selectedOrder].StyleType = frmStyleEditor.CurrentStyleType; DrawImage(); } else { stream.Seek(0, SeekOrigin.Begin); // because user cancel modify style, so restore layer mapEngine.StaticLayers[selectedOrder] = (Layer)formatter.Deserialize(stream); } // recover layer status if (isOpened) { layer.Open(); } } } private void ShowAllFeatures() { if (selectedOrder == -1) { MessageBox.Show(Properties.Resources.NoLayerSelected, "No Layer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } ShowAllFeaturesCore(mapEngine.StaticLayers[selectedOrder]); } private void ShowAllFeatures(string shapeName) { if (mapEngine.StaticLayers.Contains(shapeName)) { ShowAllFeaturesCore(mapEngine.StaticLayers[shapeName]); } } private void ShowAllFeaturesCore(Layer layer) { if (layer is ShapeFileFeatureLayer) { if (frmFeatures == null) { frmFeatures = new FormFeatures(); } frmFeatures.TableName = Path.GetFileNameWithoutExtension(layer.Name); frmFeatures.ShapeFileLayer = (ShapeFileFeatureLayer)layer; frmFeatures.ShowDialog(); } } private void RemoveShapefile(string shapeName) { if (MessageBox.Show(string.Format(CultureInfo.InvariantCulture, Properties.Resources.RemoveLayerPrompt, shapeName), "Remove Layer", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0) == DialogResult.Yes) { int removedOrder = -1; for (int i = 0; i < themeView.Items.Count; i++) { if (shapeName == themeView.Items[i].ShapeName) { removedOrder = i; break; } } if (removedOrder == selectedOrder) { selectedOrder = -1; } mapEngine.StaticLayers.Remove(shapeName); if (themeView.Items.Contains(shapeName)) { themeView.Items.Remove(shapeName); themeView.SetupItems(); } DrawImage(); } } private void RemoveAllShapefiles() { if (MessageBox.Show(Properties.Resources.RemoveAllLayerPrompt, "Remove All Layers", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0) == DialogResult.Yes) { selectedOrder = -1; mapEngine.StaticLayers.Clear(); themeView.Items.Clear(); themeView.SetupItems(); DrawImage(); } } private void RemoveShapefile(FileNotFoundException ex) { MessageBox.Show(ex.Message + "\r\n" + ex.FileName, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); string shapeName = new FileInfo(Path.ChangeExtension(ex.FileName, ".shp")).Name; mapEngine.StaticLayers.Remove(shapeName); if (themeView.Items.Contains(shapeName)) { themeView.Items.Remove(shapeName); themeView.SetupItems(); } } private void CheckCurrentExtentCache(RectangleShape extent) { if (extent != null) { for (int i = 0; i < cacheExtents.Count; i++) { if (cacheExtents[i].UpperLeftPoint.X == extent.UpperLeftPoint.X && cacheExtents[i].UpperLeftPoint.Y == extent.UpperLeftPoint.Y && cacheExtents[i].LowerRightPoint.X == extent.LowerRightPoint.X && cacheExtents[i].LowerRightPoint.Y == extent.LowerRightPoint.Y) { // is contained return; } } for (int i = extentsCurrentIndex + 1; i < cacheExtents.Count; i++) { cacheExtents.RemoveAt(i); } extentsCurrentIndex = cacheExtents.Count; cacheExtents.Add(new RectangleShape(extent.UpperLeftPoint.X, extent.UpperLeftPoint.Y, extent.LowerRightPoint.X, extent.LowerRightPoint.Y)); } } private void SelectInformation(PointShape worldPoint) { try { Collection<FeatureInfo> features = new Collection<FeatureInfo>(); Collection<Feature> selectedFeatures = new Collection<Feature>(); foreach (Layer layer in mapEngine.StaticLayers) { FeatureLayer featureLayer = layer as FeatureLayer; if (featureLayer != null) { Collection<string> returningColumnNames = GetReturningColumnNames(featureLayer); layer.Open(); Collection<Feature> nearestFeatures = featureLayer.QueryTools.GetFeaturesNearestTo(worldPoint, mapUnit, 1, returningColumnNames); double radius = 10.0 / map.Width * mapEngine.CurrentExtent.Width; EllipseShape searchingEllipse = new EllipseShape(worldPoint, radius, radius); foreach (Feature feature in nearestFeatures) { BaseShape currentShape = feature.GetShape(); if (currentShape is AreaBaseShape) { if (currentShape.Contains(worldPoint)) { selectedFeatures.Add(feature); } } if (currentShape is LineBaseShape) { if (currentShape.Intersects(searchingEllipse)) { selectedFeatures.Add(feature); } } if (currentShape is PointBaseShape) { if (searchingEllipse.Contains(currentShape)) { selectedFeatures.Add(feature); } } } layer.Close(); foreach (Feature feature in selectedFeatures) { FeatureInfo featureInfo = new FeatureInfo(); featureInfo.Feature = feature; featureInfo.ShapeName = layer.Name; features.Add(featureInfo); } selectedFeatures.Clear(); } } if (features.Count > 0) { FormInformation frmInformation = new FormInformation(features); frmInformation.ShowDialog(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); } } private static Collection<string> GetReturningColumnNames(FeatureLayer layer) { Collection<string> returningColumnNames = new Collection<string>(); layer.Open(); foreach (FeatureSourceColumn column in layer.QueryTools.GetColumns()) { returningColumnNames.Add(column.ColumnName); } layer.Close(); return returningColumnNames; } //TODO: find a better name of method and parameter private void Action(string tag) { switch (tag) { case "Add New Layer": AddLayersByOpenFileDialog(); break; case "Add Folder": AddLayersByFolderBrowserDialog(); break; case "Set MapUnit": SetMapUnit(); break; default: if (mapEngine.StaticLayers.Count > 0) { OperationAction(tag); } break; } } private void OperationAction(string tag) { switch (tag) { case "Move Up": MoveUpDown(MoveType.MoveUp); break; case "Move Down": MoveUpDown(MoveType.MoveDown); break; case "Move To Top": MoveUpDown(MoveType.MoveToTop); break; case "Move To Bottom": MoveUpDown(MoveType.MoveToBottom); break; case "Track To Extent": TrackToExtent(); break; case "Change The Style": EditLayerStyle(); break; case "Show Features": ShowAllFeatures(); break; case "Remove": RemoveShapefile(""); break; case "Track Zoom": SetButtonPushed(tbtnTrackZoom); SetMenuItemChecked(mnuToolsZoomingTrackZoom); this.Mode = ModeType.TrackZoomIn; break; case "Zoom In": ZoomInOut(ZoomType.ZoomIn); break; case "Zoom Out": ZoomInOut(ZoomType.ZoomOut); break; case "Full Extent": mapEngine.CurrentExtent = GetFullExtent(map.Width, map.Height); DrawImage(); break; case "Toggle Extent": ToggleMapExtents(); break; case "Previous Extent": GetPreviousExtent(); break; case "Pan": SetButtonPushed(tbnPan); SetMenuItemChecked(mnuToolsPanningPan); this.Mode = ModeType.Pan; break; case "Pan Left": Pan(PanDirection.Left); break; case "Pan Right": Pan(PanDirection.Right); break; case "Pan Up": Pan(PanDirection.Up); break; case "Pan Down": Pan(PanDirection.Down); break; case "Information": SetButtonPushed(tbnInformation); SetMenuItemChecked(mnuToolsInformation); this.Mode = ModeType.Information; break; case "Backgroud Color": SetBackgroudColor(); break; default: break; } } private void AddLayersByFolderBrowserDialog() { if (folderBrowserDialog.ShowDialog() == DialogResult.OK) { if (Directory.Exists(folderBrowserDialog.SelectedPath)) { AddLayersByFolder(folderBrowserDialog.SelectedPath, true); } if (filesWithoutIndex.Count > 0) { CancelAddingLayer(); } // first layer will assign fullextent to current, otherwise keep current. if (mapEngine.CurrentExtent.Width == CustomRectangleShape.CustomTolerance) { // GetFullExtent will automatic Open layer, layer.IsOpen will be true. RectangleShape currentBoundingBox = GetFullExtent(map.Width, map.Height); if (currentBoundingBox != null) { mapEngine.CurrentExtent = currentBoundingBox; } } themeView.SetupItems(); DrawImage(); } } //TODO: do we need add if to check fileName is null or empty private void AddLayers(string fileName, bool clearBuildIndexFiles) { AddLayers(new string[] { fileName }, clearBuildIndexFiles); } private void AddLayers(IEnumerable<string> fileNames, bool clearBuildIndexFiles) { if (clearBuildIndexFiles) { filesWithoutIndex.Clear(); addedFiles.Clear(); } foreach (string fileName in fileNames) { try { string layerName = new FileInfo(fileName).Name; if (mapEngine.StaticLayers.Contains(layerName)) { continue; } ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(fileName); layer.Name = layerName; SetStyleByWellKnownType(layer); layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add(layerName, layer); SetupThemeItem(layer, false); if ((!File.Exists(layer.IndexPathFileName)) || (!File.Exists(layer.IndexPathFileName.ToUpper().Replace(".IDX", ".IDS")))) { filesWithoutIndex.Add(fileName); } addedFiles.Add(fileName); } catch (FileLoadException fle) { RemoveShapefile((FileNotFoundException)fle.InnerException); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); } } } private void AddRasterLayers(IEnumerable<string> fileNames) { foreach (string fileName in fileNames) { try { string layerName = new FileInfo(fileName).Name; string extentionName = Path.GetExtension(fileName).ToUpperInvariant(); RasterLayer rasterLayer = null; if (mapEngine.StaticLayers.Contains(layerName)) { continue; } switch (extentionName) { case ".SID": rasterLayer = new MrSidRasterLayer(fileName); break; case ".ECW": rasterLayer = new EcwRasterLayer(fileName); break; case ".JP2": rasterLayer = new Jpeg2000RasterLayer(fileName); break; case ".BMP": case ".JPG": case ".JPEG": case ".GIF": case ".TIFF": case ".TIF": rasterLayer = new GdiPlusRasterLayer(fileName); break; default: break; } if (rasterLayer != null && ValidateRasterLayer(rasterLayer)) { rasterLayer.Name = layerName; mapEngine.StaticLayers.Add(layerName, rasterLayer); SetupThemeItem(rasterLayer, false); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); } } } private bool ValidateRasterLayer(RasterLayer rasterLayer) { bool isValidate = true; try { rasterLayer.Open(); } catch (Exception ex) { isValidate = false; } finally { if (rasterLayer.IsOpen) { rasterLayer.Close(); } } return isValidate; } private void SetCursor() { switch (mode) { case ModeType.Pan: map.Cursor = new Cursor(GetType(), "Pan.ico"); break; case ModeType.Information: map.Cursor = Cursors.Hand; break; case ModeType.TrackZoomIn: map.Cursor = Cursors.Arrow; break; default: map.Cursor = Cursors.Default; break; } } private void Pan(PanDirection panDirection) { if (mapEngine.StaticLayers.Count > 0) { switch (panDirection) { case PanDirection.Down: mapEngine.Pan(PanDirection.Down, 20); break; case PanDirection.Left: mapEngine.Pan(PanDirection.Left, 20); break; case PanDirection.Right: mapEngine.Pan(PanDirection.Right, 20); break; case PanDirection.Up: mapEngine.Pan(PanDirection.Up, 20); break; default: break; } DrawImage(); } } private byte ZoomInOut(ZoomType zoomType) { if (mapEngine.StaticLayers.Count > 0) { switch (zoomType) { case ZoomType.ZoomIn: mapEngine.ZoomIn(20); break; case ZoomType.ZoomOut: mapEngine.ZoomOut(20); break; default: break; } DrawImage(); } return 0; } private void SetButtonPushed(ToolStripButton button) { foreach (ToolStripItem toolStripItem in toolStrip.Items) { ToolStripButton toolStripButton = toolStripItem as ToolStripButton; if (toolStripButton != null) { toolStripButton.Checked = false; } } button.Checked = true; } private void SetMenuItemChecked(ToolStripMenuItem item) { mnuToolsZoomingTrackZoom.Checked = false; mnuToolsPanningPan.Checked = false; mnuToolsInformation.Checked = false; item.Checked = true; } private void MoveUpDown(MoveType moveType) { if (selectedOrder == -1) { MessageBox.Show(Properties.Resources.NoLayerSelected, "No Layer Selected", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } switch (moveType) { case MoveType.MoveUp: if (selectedOrder != themeView.Items.Count - 1) { themeView.Items.MoveUp(selectedOrder); mapEngine.StaticLayers.MoveUp(selectedOrder); selectedOrder++; } break; case MoveType.MoveDown: if (selectedOrder != 0) { themeView.Items.MoveDown(selectedOrder); mapEngine.StaticLayers.MoveDown(selectedOrder); selectedOrder--; } break; case MoveType.MoveToTop: if (selectedOrder != themeView.Items.Count - 1) { themeView.Items.MoveToTop(selectedOrder); mapEngine.StaticLayers.MoveToTop(selectedOrder); selectedOrder = themeView.Items.Count - 1; } break; case MoveType.MoveToBottom: if (selectedOrder != 0) { themeView.Items.MoveToBottom(selectedOrder); mapEngine.StaticLayers.MoveToBottom(selectedOrder); selectedOrder = 0; } break; default: break; } themeView.SetupItems(); DrawImage(); } private void DrawImage() { if (!isNotScrollBarChangeSize) { try { if (mapEngine.StaticLayers.Count == 0) { // clear map map.Image = new Bitmap(map.Width, map.Height); map.BackColor = Color.White; // set no layer selected selectedOrder = -1; return; } CheckCurrentExtentCache(mapEngine.CurrentExtent); ExtentHelper.GetScale(mapEngine.CurrentExtent, map.Width, GeographyUnit.DecimalDegree); mapEngine.OpenAllLayers(); mapEngine.DrawStaticLayers(bitmap, mapUnit); mapEngine.DrawAdornmentLayers(bitmap, mapUnit); mapEngine.CloseAllLayers(); map.Image = bitmap; } catch (FileLoadException fileLoadException) { RemoveShapefile((FileNotFoundException)fileLoadException.InnerException); } catch (Exception ex) { foreach (ThemeItem themeItem in themeView.Items) { themeItem.IsShow = false; } MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0); return; } } } private static bool IsRasterLayerFile(string filename) { bool result = false; string upperFilename = filename.ToUpperInvariant(); if (upperFilename.EndsWith(".SID", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".ECW", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".JP2", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".JPEG", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".JPG", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".GIF", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".TIF", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".TIFF", StringComparison.OrdinalIgnoreCase) || upperFilename.EndsWith(".BMP", StringComparison.OrdinalIgnoreCase)) { result = true; } return result; } private void AddLayersByFolder(string folderName, bool clearBuildIndexFiles) { string[] fileNames = Directory.GetFiles(folderName, "*.*", SearchOption.AllDirectories); Collection<string> rasterFilenames = new Collection<string>(); Collection<string> featureFilenames = new Collection<string>(); foreach (string filename in fileNames) { if (IsRasterLayerFile(filename)) { rasterFilenames.Add(filename); } else if (filename.ToUpperInvariant().Contains(".SHP")) { featureFilenames.Add(filename); } } AddLayers(featureFilenames, clearBuildIndexFiles); AddRasterLayers(rasterFilenames); } } }
using System; using System.Windows.Forms; namespace MapSuiteExplorer { public partial class ThemeItem : UserControl { internal event EventHandler<ShapeEventArgs> ItemCheckedChanged; internal event EventHandler<ShapeLinkClickedEventArgs> ItemLinkClicked; internal event EventHandler<LayerOrderEventArgs> ThemeItemClick; internal event EventHandler<RightClickEventArgs> ThemeItemRightClick; private StyleType styleType; private bool isShow = true; public StyleType StyleType { get { return styleType; } set { styleType = value; } } public bool IsShow { get { return isShow; } set { isShow = value; cbxItem.Checked = IsShow; } } public string ShapeName { get { return cbxItem.Text; } set { cbxItem.Text = value; } } public ThemeItem() { InitializeComponent(); ToolTip tooTip = new ToolTip(); tooTip.SetToolTip(this.btnRemove, "Remove"); tooTip.SetToolTip(this, Properties.Resources.ThemeItemToolTip); tooTip.SetToolTip(this.cbxItem, Properties.Resources.ThemeItemCheckBoxToolTip); } private void cbxItem_CheckedChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(cbxItem.Text)) { throw new ArgumentException(Properties.Resources.ShapeNameCheck); } OnItemCheckedChanged(new ShapeEventArgs(cbxItem.Text, cbxItem.Checked)); } private void ThemeItem_Click(object sender, EventArgs e) { OnThemeItemClick(new LayerOrderEventArgs(this.cbxItem.Text)); } private void pnlTitle_MouseDown(object sender, MouseEventArgs e) { OnThemeItemClick(new LayerOrderEventArgs(this.cbxItem.Text)); DoDragDrop(this, DragDropEffects.Move); } private void btnRemove_Click(object sender, EventArgs e) { OnItemLinkClicked(new ShapeLinkClickedEventArgs(cbxItem.Text, LinkType.Remove)); } private void ThemeItem_MouseDoubleClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { OnItemLinkClicked(new ShapeLinkClickedEventArgs(cbxItem.Text, LinkType.Edit)); } } private void ThemeItem_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { OnThemeItemRightClick(new RightClickEventArgs(PointToScreen(e.Location))); } } protected virtual void OnItemCheckedChanged(ShapeEventArgs e) { EventHandler<ShapeEventArgs> handler = ItemCheckedChanged; if (handler != null) { handler(this, e); } } protected virtual void OnThemeItemClick(LayerOrderEventArgs e) { EventHandler<LayerOrderEventArgs> handler = ThemeItemClick; if (handler != null) { handler(this, e); } } protected virtual void OnItemLinkClicked(ShapeLinkClickedEventArgs e) { EventHandler<ShapeLinkClickedEventArgs> handler = ItemLinkClicked; if (handler != null) { handler(this, e); } } protected virtual void OnThemeItemRightClick(RightClickEventArgs e) { EventHandler<RightClickEventArgs> handler = ThemeItemRightClick; if (handler != null) { handler(this, e); } } } }
using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public partial class ThemeView : UserControl { internal event EventHandler<DragDropItemEventArgs> ThemeViewDragDrop; internal event EventHandler<EventArgs> VScrollVisible; private bool isVScrollVisible; private bool scrollBarWidthNeedtoChange; private GeoCollection<ThemeItem> items; public GeoCollection<ThemeItem> Items { get { return items; } } public ThemeView() { items = new GeoCollection<ThemeItem>(); InitializeComponent(); } internal void SetupItems() { scrollBarWidthNeedtoChange = false; this.Controls.Clear(); int height = 0; for (int i = items.Count - 1; i >= 0; i--) { items[i].Location = new Point(0, height); this.Controls.Add(items[i]); height += 60; } scrollBarWidthNeedtoChange = true; } private void ThemeView_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ThemeItem))) { e.Effect = DragDropEffects.Move; } } private void ThemeView_DragDrop(object sender, DragEventArgs e) { // find which theme item be draged ThemeItem currentItem = (ThemeItem)(e.Data.GetData(typeof(ThemeItem))); int selectedOrder = GetSelectedOrder(currentItem.ShapeName); // find mainform Control control = this; while (control.Parent != null) { control = control.Parent; } // 70 is toolStrip and menu's height int yOffset = (e.Y - control.Location.Y - 70) - currentItem.Location.Y; int remainder = yOffset % currentItem.Height; int divider = yOffset / currentItem.Height; int oneThirdHeight = currentItem.Height / 3; if (divider < 0 || (remainder > oneThirdHeight && divider > 0)) { DoDragDropItem(selectedOrder, selectedOrder - divider); return; } if (divider > 1 || (remainder < -oneThirdHeight && divider <= 0)) { DoDragDropItem(selectedOrder, selectedOrder - divider + 1); return; } } private void DoDragDropItem(int from, int to) { items.MoveTo(from, to); OnThemeViewDragDrop(new DragDropItemEventArgs(from, to)); SetupItems(); } private int GetSelectedOrder(string shapeName) { int selectedOrder = -1; for (int i = items.Count - 1; i >= 0; i--) { if (shapeName == this.Items[i].ShapeName) { selectedOrder = i; break; } } return selectedOrder; } private void ThemeView_Paint(object sender, PaintEventArgs e) { if (isVScrollVisible != VerticalScroll.Visible) { isVScrollVisible = VerticalScroll.Visible; OnVScrollVisible(new EventArgs()); } } protected virtual void OnThemeViewDragDrop(DragDropItemEventArgs e) { EventHandler<DragDropItemEventArgs> handler = ThemeViewDragDrop; if (handler != null) { handler(this, e); } } protected virtual void OnVScrollVisible(EventArgs e) { EventHandler<EventArgs> handler = VScrollVisible; if (handler != null) { handler(this, e); } } protected override void OnPaint(PaintEventArgs e) { if (scrollBarWidthNeedtoChange) { base.OnPaint(e); } } } }
namespace MapSuiteExplorer { public enum ColorType { All = 0, Pastel = 1, Bright = 2 } }
namespace MapSuiteExplorer { public enum ColorType { All = 0, Pastel = 1, Bright = 2 } }
namespace MapSuiteExplorer { public enum GeoCustomStyle { /// <summary>A Horizontal pattern fill.</summary> Horizontal = 0, /// <summary>A Vertical pattern fill.</summary> Vertical = 1, /// <summary>A Forward Diagonal pattern fill.</summary> ForwardDiagonal = 2, /// <summary>A Backward Diagonal pattern fill.</summary> BackwardDiagonal = 3, /// <summary>A Large Grid pattern fill.</summary> LargeGrid = 4, /// <summary>A Diagonal Cross pattern fill.</summary> DiagonalCross = 5, /// <summary>A 05 Percent pattern fill.</summary> Percent05 = 6, /// <summary>A 10 Percent pattern fill.</summary> Percent10 = 7, /// <summary>A 20 Percent pattern fill.</summary> Percent20 = 8, /// <summary>A 25 Percent pattern fill.</summary> Percent25 = 9, /// <summary>A 30 Percent pattern fill.</summary> Percent30 = 10, /// <summary>A 40 Percent pattern fill.</summary> Percent40 = 11, /// <summary>A 50 Percent pattern fill.</summary> Percent50 = 12, /// <summary>A 60 Percent pattern fill.</summary> Percent60 = 13, /// <summary>A 70 Percent pattern fill.</summary> Percent70 = 14, /// <summary>A 75 Percent pattern fill.</summary> Percent75 = 15, /// <summary>A 80 Percent pattern fill.</summary> Percent80 = 16, /// <summary>A 90 Percent pattern fill.</summary> Percent90 = 17, /// <summary>A Light Downward Diagonal pattern fill.</summary> LightDownwardDiagonal = 18, /// <summary>A Light Upward Diagonal pattern fill.</summary> LightUpwardDiagonal = 19, /// <summary>A Dark Downward Diagonal pattern fill.</summary> DarkDownwardDiagonal = 20, /// <summary>A Dark Upward Diagonal pattern fill.</summary> DarkUpwardDiagonal = 21, /// <summary>A Wide Downward Diagonal pattern fill.</summary> WideDownwardDiagonal = 22, /// <summary>A Wide Upward Diagonal pattern fill.</summary> WideUpwardDiagonal = 23, /// <summary>A Light Vertical pattern fill.</summary> LightVertical = 24, /// <summary>A Light Horizontal pattern fill.</summary> LightHorizontal = 25, /// <summary>A Narrow Vertical pattern fill.</summary> NarrowVertical = 26, /// <summary>A Narrow Horizontal pattern fill.</summary> NarrowHorizontal = 27, /// <summary>A Dark Vertical pattern fill.</summary> DarkVertical = 28, /// <summary>A Dark Horizontal pattern fill.</summary> DarkHorizontal = 29, /// <summary>A Dashed Downward Diagonal pattern fill.</summary> DashedDownwardDiagonal = 30, /// <summary>A Dashed Upward Diagonal pattern fill.</summary> DashedUpwardDiagonal = 31, /// <summary>A Dashed Horizontal pattern fill.</summary> DashedHorizontal = 32, /// <summary>A Dashed Vertical pattern fill.</summary> DashedVertical = 33, /// <summary>A Small Confetti pattern fill.</summary> SmallConfetti = 34, /// <summary>A Large Confetti pattern fill.</summary> LargeConfetti = 35, /// <summary>A Zig Zag pattern fill.</summary> ZigZag = 36, /// <summary>A Wave pattern fill.</summary> Wave = 37, /// <summary>A Diagonal Brick pattern fill.</summary> DiagonalBrick = 38, /// <summary>A Horizontal Brick pattern fill.</summary> HorizontalBrick = 39, /// <summary>A Weave pattern fill.</summary> Weave = 40, /// <summary>A Plaid pattern fill.</summary> Plaid = 41, /// <summary>A Divot pattern fill.</summary> Divot = 42, /// <summary>A Dotted Grid pattern fill.</summary> DottedGrid = 43, /// <summary>A Dotted Diamond pattern fill.</summary> DottedDiamond = 44, /// <summary>A Shingle pattern fill.</summary> Shingle = 45, /// <summary>A Trellis pattern fill.</summary> Trellis = 46, /// <summary>A Sphere pattern fill.</summary> Sphere = 47, /// <summary>A Small Grid pattern fill.</summary> SmallGrid = 48, /// <summary>A Small Checker Board pattern fill.</summary> SmallCheckerBoard = 49, /// <summary>A Large Checker Board pattern fill.</summary> LargeCheckerBoard = 50, /// <summary>A Outlined Diamond pattern fill.</summary> OutlinedDiamond = 51, /// <summary>A Solid Diamond pattern fill.</summary> SolidDiamond = 52, /// <summary>A Min pattern fill.</summary> Min = 53, /// <summary>A Max pattern fill.</summary> Max = 54, /// <summary>A Cross pattern fill.</summary> Cross = 55, /// <summary>None pattern fill.</summary> None } }
namespace MapSuiteExplorer { public enum LinkType { Edit = 0, Features = 1, Remove = 2, ZoomToExtent = 3 } }
namespace MapSuiteExplorer { public enum ModeType { None = 0, Information = 1, Pan = 2, TrackZoomIn = 3, } }
namespace MapSuiteExplorer { public enum MoveType { MoveUp = 0, MoveDown = 1, MoveToTop = 2, MoveToBottom = 3 } }
namespace MapSuiteExplorer { public enum StyleType { Area = 0, Line = 1, Point = 2, Text = 3, Custom = 4 } }
namespace MapSuiteExplorer { public enum ZoomType { ZoomIn = 0, ZoomOut = 1 } }
using System; namespace MapSuiteExplorer { public class DragDropItemEventArgs : EventArgs { private int fromOrder; private int toOrder; public int FromOrder { get { return fromOrder; } set { fromOrder = value; } } public int ToOrder { get { return toOrder; } set { toOrder = value; } } public DragDropItemEventArgs(int fromOrder, int toOrder) { this.fromOrder = fromOrder; this.toOrder = toOrder; } } }
using System; namespace MapSuiteExplorer { public class LayerOrderEventArgs : EventArgs { private string name; public string Name { get { return name; } set { name = value; } } public LayerOrderEventArgs(string name) { this.name = name; } } }
using System; using System.Drawing; namespace MapSuiteExplorer { public class RightClickEventArgs : EventArgs { private Point point; public Point Point { get { return point; } set { point = value; } } public RightClickEventArgs(Point point) { this.point = point; } } }
using System; namespace MapSuiteExplorer { public class ShapeEventArgs : EventArgs { private string shapeName; private bool isShow; public string ShapeName { get { return shapeName; } set { shapeName = value; } } public bool IsShow { get { return isShow; } set { isShow = value; } } public ShapeEventArgs(string shapeName, bool isShow) { this.shapeName = shapeName; this.isShow = isShow; } } }
using System; namespace MapSuiteExplorer { public class ShapeLinkClickedEventArgs : EventArgs { private string shapeName; private LinkType linkType; public string ShapeName { get { return shapeName; } set { shapeName = value; } } public LinkType LinkType { get { return linkType; } set { linkType = value; } } public ShapeLinkClickedEventArgs(string shapeName, LinkType linkType) { this.linkType = linkType; this.shapeName = shapeName; } } }
using System.ComponentModel; using System.Drawing; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public class MyAreaStyle { private AreaStyle style; [Category("AreaStyle")] [Description("The|color of outline pen.")] public Color OutlineColor { get { return Color.FromArgb(style.OutlinePen.Color.RedComponent, style.OutlinePen.Color.GreenComponent, style.OutlinePen.Color.BlueComponent); } set { style.OutlinePen.Color = new GeoColor(value.R, value.G, value.B); } } [Category("AreaStyle")] [Description("The|width of outline pen.")] public float OutlineThickness { get { return style.OutlinePen.Width; } set { style.OutlinePen.Width = value; } } [Category("AreaStyle")] [Description("The|color of fill solid brush.")] public Color FillColor { get { return Color.FromArgb(style.FillSolidBrush.Color.RedComponent, style.FillSolidBrush.Color.GreenComponent, style.FillSolidBrush.Color.BlueComponent); } set { style.FillSolidBrush.Color = new GeoColor(value.R, value.G, value.B); } } [Category("AreaStyle")] [Description("The|alpha component of fill solid brush.")] public byte Transparency { get { return style.FillSolidBrush.Color.AlphaComponent; } set { style.FillSolidBrush.Color = GeoColor.FromArgb(value, style.FillSolidBrush.Color); } } [Category("AreaStyle")] [Description("If|you don't need fill pattern, please select 'None' at the end of drop-down list")] public GeoCustomStyle FillPattern { get { GeoHatchBrush brush = null; if (style.Advanced.FillCustomBrush != null) { brush = (GeoHatchBrush)style.Advanced.FillCustomBrush; return GetGeoCustomStyle(brush); } return GeoCustomStyle.None; } set { style.Advanced.FillCustomBrush = value == GeoCustomStyle.None ? null : new GeoHatchBrush((GeoHatchStyle)value, style.FillSolidBrush.Color); } } public MyAreaStyle(AreaStyle style) { this.style = style; } private static GeoCustomStyle GetGeoCustomStyle(GeoHatchBrush geoHatchBrush) { GeoCustomStyle geoCustomStyle = GeoCustomStyle.None; switch (geoHatchBrush.HatchStyle) { case GeoHatchStyle.BackwardDiagonal: geoCustomStyle = GeoCustomStyle.BackwardDiagonal; break; case GeoHatchStyle.Cross: geoCustomStyle = GeoCustomStyle.Cross; break; case GeoHatchStyle.DarkDownwardDiagonal: geoCustomStyle = GeoCustomStyle.DarkDownwardDiagonal; break; case GeoHatchStyle.DarkHorizontal: geoCustomStyle = GeoCustomStyle.DarkHorizontal; break; case GeoHatchStyle.DarkUpwardDiagonal: geoCustomStyle = GeoCustomStyle.DarkUpwardDiagonal; break; case GeoHatchStyle.DarkVertical: geoCustomStyle = GeoCustomStyle.DarkVertical; break; case GeoHatchStyle.DashedDownwardDiagonal: geoCustomStyle = GeoCustomStyle.DashedDownwardDiagonal; break; case GeoHatchStyle.DashedHorizontal: geoCustomStyle = GeoCustomStyle.DashedHorizontal; break; case GeoHatchStyle.DashedUpwardDiagonal: geoCustomStyle = GeoCustomStyle.DashedUpwardDiagonal; break; case GeoHatchStyle.DashedVertical: geoCustomStyle = GeoCustomStyle.DashedVertical; break; case GeoHatchStyle.DiagonalBrick: geoCustomStyle = GeoCustomStyle.DiagonalBrick; break; case GeoHatchStyle.DiagonalCross: geoCustomStyle = GeoCustomStyle.DiagonalCross; break; case GeoHatchStyle.Divot: geoCustomStyle = GeoCustomStyle.Divot; break; case GeoHatchStyle.DottedDiamond: geoCustomStyle = GeoCustomStyle.DottedDiamond; break; case GeoHatchStyle.DottedGrid: geoCustomStyle = GeoCustomStyle.DottedGrid; break; case GeoHatchStyle.ForwardDiagonal: geoCustomStyle = GeoCustomStyle.ForwardDiagonal; break; case GeoHatchStyle.Horizontal: geoCustomStyle = GeoCustomStyle.Horizontal; break; case GeoHatchStyle.HorizontalBrick: geoCustomStyle = GeoCustomStyle.HorizontalBrick; break; case GeoHatchStyle.LargeCheckerBoard: geoCustomStyle = GeoCustomStyle.LargeCheckerBoard; break; case GeoHatchStyle.LargeConfetti: geoCustomStyle = GeoCustomStyle.LargeConfetti; break; case GeoHatchStyle.LargeGrid: geoCustomStyle = GeoCustomStyle.LargeGrid; break; case GeoHatchStyle.LightDownwardDiagonal: geoCustomStyle = GeoCustomStyle.LightDownwardDiagonal; break; case GeoHatchStyle.LightHorizontal: geoCustomStyle = GeoCustomStyle.LightHorizontal; break; case GeoHatchStyle.LightUpwardDiagonal: geoCustomStyle = GeoCustomStyle.LightUpwardDiagonal; break; case GeoHatchStyle.LightVertical: geoCustomStyle = GeoCustomStyle.LightVertical; break; case GeoHatchStyle.Max: geoCustomStyle = GeoCustomStyle.Max; break; case GeoHatchStyle.Min: geoCustomStyle = GeoCustomStyle.Min; break; case GeoHatchStyle.NarrowHorizontal: geoCustomStyle = GeoCustomStyle.NarrowHorizontal; break; case GeoHatchStyle.NarrowVertical: geoCustomStyle = GeoCustomStyle.NarrowVertical; break; case GeoHatchStyle.OutlinedDiamond: geoCustomStyle = GeoCustomStyle.OutlinedDiamond; break; case GeoHatchStyle.Percent05: geoCustomStyle = GeoCustomStyle.Percent05; break; case GeoHatchStyle.Percent10: geoCustomStyle = GeoCustomStyle.Percent10; break; case GeoHatchStyle.Percent20: geoCustomStyle = GeoCustomStyle.Percent20; break; case GeoHatchStyle.Percent25: geoCustomStyle = GeoCustomStyle.Percent25; break; case GeoHatchStyle.Percent30: geoCustomStyle = GeoCustomStyle.Percent30; break; case GeoHatchStyle.Percent40: geoCustomStyle = GeoCustomStyle.Percent40; break; case GeoHatchStyle.Percent50: geoCustomStyle = GeoCustomStyle.Percent50; break; case GeoHatchStyle.Percent60: geoCustomStyle = GeoCustomStyle.Percent60; break; case GeoHatchStyle.Percent70: geoCustomStyle = GeoCustomStyle.Percent70; break; case GeoHatchStyle.Percent75: geoCustomStyle = GeoCustomStyle.Percent75; break; case GeoHatchStyle.Percent80: geoCustomStyle = GeoCustomStyle.Percent80; break; case GeoHatchStyle.Percent90: geoCustomStyle = GeoCustomStyle.Percent90; break; case GeoHatchStyle.Plaid: geoCustomStyle = GeoCustomStyle.Plaid; break; case GeoHatchStyle.Shingle: geoCustomStyle = GeoCustomStyle.Shingle; break; case GeoHatchStyle.SmallCheckerBoard: geoCustomStyle = GeoCustomStyle.SmallCheckerBoard; break; case GeoHatchStyle.SmallConfetti: geoCustomStyle = GeoCustomStyle.SmallConfetti; break; case GeoHatchStyle.SmallGrid: geoCustomStyle = GeoCustomStyle.SmallGrid; break; case GeoHatchStyle.SolidDiamond: geoCustomStyle = GeoCustomStyle.SolidDiamond; break; case GeoHatchStyle.Sphere: geoCustomStyle = GeoCustomStyle.Sphere; break; case GeoHatchStyle.Trellis: geoCustomStyle = GeoCustomStyle.Trellis; break; case GeoHatchStyle.Vertical: geoCustomStyle = GeoCustomStyle.Vertical; break; case GeoHatchStyle.Wave: geoCustomStyle = GeoCustomStyle.Wave; break; case GeoHatchStyle.Weave: geoCustomStyle = GeoCustomStyle.Weave; break; case GeoHatchStyle.WideDownwardDiagonal: geoCustomStyle = GeoCustomStyle.WideDownwardDiagonal; break; case GeoHatchStyle.WideUpwardDiagonal: geoCustomStyle = GeoCustomStyle.WideUpwardDiagonal; break; case GeoHatchStyle.ZigZag: geoCustomStyle = GeoCustomStyle.ZigZag; break; default: geoCustomStyle = GeoCustomStyle.None; break; } return geoCustomStyle; } } }
using System.ComponentModel; using System.Drawing; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public class MyLineStyle { private LineStyle style; [Category("LineStyle")] [Description("The|color of outer pen.")] public Color LineColor { get { return Color.FromArgb(style.OuterPen.Color.RedComponent, style.OuterPen.Color.GreenComponent, style.OuterPen.Color.BlueComponent); } set { style.OuterPen.Color = new GeoColor(value.R, value.G, value.B); } } [Category("LineStyle")] [Description("The|width of outer pen.")] public float LineThickness { get { return style.OuterPen.Width; } set { style.OuterPen.Width = value; } } public MyLineStyle(LineStyle style) { this.style = style; } } }
using System.ComponentModel; using System.Drawing; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public class MyPointStyle { private PointStyle style; [Category("PointStyle")] [Description("The|point symbol type.")] public PointSymbolType SymbolType { get { return style.SymbolType; } set { style.SymbolType = value; } } [Category("PointStyle")] [Description("The|color of symbol solid brush.")] public Color FillColor { get { return Color.FromArgb(style.SymbolSolidBrush.Color.RedComponent, style.SymbolSolidBrush.Color.GreenComponent, style.SymbolSolidBrush.Color.BlueComponent); } set { style.SymbolSolidBrush.Color = new GeoColor(value.R, value.G, value.B); } } [Category("PointStyle")] [Description("The|color of symbol pen.")] public Color OutlineColor { get { return Color.FromArgb(style.SymbolPen.Color.RedComponent, style.SymbolPen.Color.GreenComponent, style.SymbolPen.Color.BlueComponent); } set { style.SymbolPen.Color = new GeoColor(value.R, value.G, value.B); } } [Category("PointStyle")] [Description("The|symbol size.")] public float SymbolSize { get { return style.SymbolSize; } set { style.SymbolSize = value; } } public MyPointStyle(PointStyle style) { this.style = style; } } }
using System.ComponentModel; using System.Drawing; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public class MyTextStyle { private TextStyle style; [Category("TextStyle")] [Description("Find|column name from features dialog when click show features button.")] public string TextColumnName { get { return style.TextColumnName; } set { style.TextColumnName = value; } } [Category("TextStyle")] [Description("The|font of text.")] public Font Font { get { return new Font(style.Font.FontName, style.Font.Size, GetFontStyle(style.Font.Style)); } set { style.Font = new GeoFont(value.Name, value.Size, GetDrawingFontStyles(value.Style)); } } [Category("TextStyle")] [Description("The|color of text solid brush.")] public Color TextColor { get { return Color.FromArgb(style.TextSolidBrush.Color.RedComponent, style.TextSolidBrush.Color.GreenComponent, style.TextSolidBrush.Color.BlueComponent); } set { style.TextSolidBrush.Color = new GeoColor(value.R, value.G, value.B); } } public MyTextStyle(TextStyle style) { this.style = style; } private static FontStyle GetFontStyle(DrawingFontStyles drawingFontStyles) { switch (drawingFontStyles) { case DrawingFontStyles.Bold: return FontStyle.Bold; case DrawingFontStyles.Italic: return FontStyle.Italic; case DrawingFontStyles.Regular: return FontStyle.Regular; case DrawingFontStyles.Strikeout: return FontStyle.Strikeout; case DrawingFontStyles.Underline: return FontStyle.Underline; default: break; } return FontStyle.Regular; } private static DrawingFontStyles GetDrawingFontStyles(FontStyle fontStyle) { switch (fontStyle) { case FontStyle.Bold: return DrawingFontStyles.Bold; case FontStyle.Italic: return DrawingFontStyles.Italic; case FontStyle.Regular: return DrawingFontStyles.Regular; case FontStyle.Strikeout: return DrawingFontStyles.Strikeout; case FontStyle.Underline: return DrawingFontStyles.Underline; default: break; } return DrawingFontStyles.Regular; } } }
using System; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace MapSuiteExplorer { public partial class StyleEditor : UserControl { private StyleType styleType; private AreaStyle areaStyle; private LineStyle lineStyle; private PointStyle pointStyle; private TextStyle textStyle; public StyleType StyleType { get { return styleType; } set { styleType = value; } } public AreaStyle AreaStyle { get { return areaStyle; } set { areaStyle = value; } } public LineStyle LineStyle { get { return lineStyle; } set { lineStyle = value; } } public PointStyle PointStyle { get { return pointStyle; } set { pointStyle = value; } } public TextStyle TextStyle { get { return textStyle; } set { textStyle = value; } } public StyleEditor() { InitializeComponent(); pbxPreview.Image = new Bitmap(pbxPreview.Width, pbxPreview.Height); } private void gridStyle_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e) { DrawPreviewImage(); } private void DrawPreviewImage() { switch (styleType) { case StyleType.Text: pbxPreview.Image = DrawSampleImage(pbxPreview.Image, textStyle); break; case StyleType.Line: pbxPreview.Image = DrawSampleImage(pbxPreview.Image, lineStyle); break; case StyleType.Point: pbxPreview.Image = DrawSampleImage(pbxPreview.Image, pointStyle); break; case StyleType.Area: pbxPreview.Image = DrawSampleImage(pbxPreview.Image, areaStyle); break; default: break; } pbxPreview.Invalidate(); } private static Image DrawSampleImage(Image image, Style style) { Image newImage = new Bitmap(image.Width, image.Height); image.Dispose(); GdiPlusGeoCanvas canvas = new GdiPlusGeoCanvas(); canvas.BeginDrawing(newImage, new RectangleShape(0, newImage.Width, newImage.Height, 0), GeographyUnit.DecimalDegree); style.DrawSample(canvas); if (canvas.IsDrawing) { canvas.EndDrawing(); } return newImage; } private void StyleEditor_ParentChanged(object sender, EventArgs e) { DrawPreviewImage(); object style = null; switch (styleType) { case StyleType.Text: style = new MyTextStyle(textStyle); break; case StyleType.Line: style = new MyLineStyle(lineStyle); break; case StyleType.Point: style = new MyPointStyle(pointStyle); break; case StyleType.Area: style = new MyAreaStyle(areaStyle); break; default: break; } if (style != null) { gridStyle.SelectedObject = style; } } } }