Click here to Skip to main content
15,892,965 members
Articles / Programming Languages / C#

Map component for building GIS applications (GisMap)

Rate me:
Please Sign up or sign in to vote.
4.47/5 (15 votes)
30 Oct 20053 min read 198K   22K   150  
Map component for building GIS and CAD/CAM applications. Reads most of the vector and raster formats, performs coordinate system transformations, accesses aerial photography via web services and more.
/**************************************************************** 
**  Copyright (C) 2004 MvisionTech Ltd.  
**  Copyright (C) 2005 Roadware Inc.
**
** This file is part of the Canvas.NET data visualization framework.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using CanvasControl;
using GeomModel;

namespace CanvasControl
{
	/// <summary>
	/// Summary description for LayersControl.
	/// </summary>
	public class LayersControl : System.Windows.Forms.UserControl
	{
		private Canvas m_canvas;
		private string m_current;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Button buttonCreate;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button buttonUp;
		private System.Windows.Forms.Button buttonDown;
		private System.Windows.Forms.Button buttonDelete;
		private System.Windows.Forms.PropertyGrid propertyGridLayers;

		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public LayersControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			listView1.GridLines = true;			
		}

		public void updateLayers()
		{
			CanvasGeomModel gm = m_canvas.getGeomModel();
			ArrayList layers = gm.getLayers();
			this.listView1.Items.Clear();

			SortedList sl = new SortedList();
			foreach(CanvasLayer lay in layers)
			{
				sl.Add(lay.Order,lay);
			}

			// Initialize the ImageList objects with bitmaps.
			int indx = 0;
			foreach(CanvasLayer lay in sl.Values)
			{				
				ListViewItem item = new ListViewItem(lay.Name,indx++);				
				item.Checked = lay.Visiable;				
				this.listView1.Items.Add(item);	
			}
		}

		public void setCanvas(Canvas c)
		{
			m_canvas = c;
			updateLayers();
			m_canvas.getGeomModel().LayerChangedEvent += new GeomModel.CanvasGeomModel.LayerChangedEventHandler(this.onLayerChanged);
		}

	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.listView1 = new System.Windows.Forms.ListView();
			this.panel1 = new System.Windows.Forms.Panel();
			this.buttonDelete = new System.Windows.Forms.Button();
			this.buttonDown = new System.Windows.Forms.Button();
			this.buttonUp = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.buttonCreate = new System.Windows.Forms.Button();
			this.panel2 = new System.Windows.Forms.Panel();
			this.propertyGridLayers = new System.Windows.Forms.PropertyGrid();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.panel1.SuspendLayout();
			this.panel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// listView1
			// 
			this.listView1.CheckBoxes = true;
			this.listView1.Dock = System.Windows.Forms.DockStyle.Left;
			this.listView1.FullRowSelect = true;
			this.listView1.Location = new System.Drawing.Point(0, 0);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(96, 144);
			this.listView1.TabIndex = 0;
			this.listView1.View = System.Windows.Forms.View.List;
			this.listView1.Click += new System.EventHandler(this.listView1_Click);
			this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
			this.listView1.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.listView1_ItemCheck);
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.buttonDelete);
			this.panel1.Controls.Add(this.buttonDown);
			this.panel1.Controls.Add(this.buttonUp);
			this.panel1.Controls.Add(this.textBox1);
			this.panel1.Controls.Add(this.buttonCreate);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(296, 38);
			this.panel1.TabIndex = 5;
			// 
			// buttonDelete
			// 
			this.buttonDelete.Location = new System.Drawing.Point(232, 8);
			this.buttonDelete.Name = "buttonDelete";
			this.buttonDelete.Size = new System.Drawing.Size(56, 23);
			this.buttonDelete.TabIndex = 4;
			this.buttonDelete.Text = "delete";
			// 
			// buttonDown
			// 
			this.buttonDown.Location = new System.Drawing.Point(192, 8);
			this.buttonDown.Name = "buttonDown";
			this.buttonDown.Size = new System.Drawing.Size(32, 23);
			this.buttonDown.TabIndex = 3;
			this.buttonDown.Text = ">>";
			this.buttonDown.Click += new System.EventHandler(this.buttonDown_Click);
			// 
			// buttonUp
			// 
			this.buttonUp.Location = new System.Drawing.Point(160, 8);
			this.buttonUp.Name = "buttonUp";
			this.buttonUp.Size = new System.Drawing.Size(32, 23);
			this.buttonUp.TabIndex = 2;
			this.buttonUp.Text = "<<";
			this.buttonUp.Click += new System.EventHandler(this.buttonUp_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(8, 8);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(96, 22);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "new-name";
			// 
			// buttonCreate
			// 
			this.buttonCreate.Location = new System.Drawing.Point(112, 8);
			this.buttonCreate.Name = "buttonCreate";
			this.buttonCreate.Size = new System.Drawing.Size(40, 23);
			this.buttonCreate.TabIndex = 0;
			this.buttonCreate.Text = "new ";
			this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
			// 
			// panel2
			// 
			this.panel2.Controls.Add(this.propertyGridLayers);
			this.panel2.Controls.Add(this.splitter1);
			this.panel2.Controls.Add(this.listView1);
			this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panel2.Location = new System.Drawing.Point(0, 38);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(296, 144);
			this.panel2.TabIndex = 6;
			// 
			// propertyGridLayers
			// 
			this.propertyGridLayers.CommandsVisibleIfAvailable = true;
			this.propertyGridLayers.Dock = System.Windows.Forms.DockStyle.Fill;
			this.propertyGridLayers.LargeButtons = false;
			this.propertyGridLayers.LineColor = System.Drawing.SystemColors.ScrollBar;
			this.propertyGridLayers.Location = new System.Drawing.Point(99, 0);
			this.propertyGridLayers.Name = "propertyGridLayers";
			this.propertyGridLayers.Size = new System.Drawing.Size(197, 144);
			this.propertyGridLayers.TabIndex = 6;
			this.propertyGridLayers.Text = "propertyGrid1";
			this.propertyGridLayers.ViewBackColor = System.Drawing.SystemColors.Window;
			this.propertyGridLayers.ViewForeColor = System.Drawing.SystemColors.WindowText;
			// 
			// splitter1
			// 
			this.splitter1.Location = new System.Drawing.Point(96, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 144);
			this.splitter1.TabIndex = 5;
			this.splitter1.TabStop = false;
			// 
			// LayersControl
			// 
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.Name = "LayersControl";
			this.Size = new System.Drawing.Size(296, 182);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		public void onLayerChanged(object sender,LayerEventArgs args)
		{
			//listView1.Items.Add(args.lay.Name);
			updateLayers();
		}

		private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count == 0)
				return;

			m_current = listView1.SelectedItems[0].Text;
			GeomModel.CanvasLayer lay = m_canvas.layerByName(m_current);
			if( lay == null)
				return;
			
			propertyGridLayers.SelectedObject = lay;
			
		}

		private void listView1_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
		{
			
			m_current = listView1.Items[e.Index].Text;
			GeomModel.CanvasLayer lay = m_canvas.layerByName(m_current);
			if( lay == null)
				return;
			if(e.CurrentValue != CheckState.Checked)
			{
				lay.Visiable = true;
				m_canvas.Invalidate();
			}
			else
			{
				lay.Visiable = false;
				m_canvas.Invalidate();
				propertyGridLayers.Update();
			}
		}

		private void buttonCreate_Click(object sender, System.EventArgs e)
		{
			CanvasLayer lay = m_canvas.createLayer(textBox1.Text,Color.GreenYellow,0,true);
			m_canvas.CurrentLayer = lay;
		}

		private void buttonUp_Click(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count == 0)
				return;
			m_canvas.getGeomModel().moveLayerUp(listView1.SelectedItems[0].Text);
		}

		private void buttonDown_Click(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count == 0)
				return;
			m_canvas.getGeomModel().moveLayerDown(listView1.SelectedItems[0].Text);	
		}

		private void listView1_Click(object sender, System.EventArgs e)
		{
			if(listView1.SelectedItems.Count == 0)
				return;
			CanvasLayer lay = m_canvas.getGeomModel().layerByName(listView1.SelectedItems[0].Text);
			if(lay != null)
				m_canvas.CurrentLayer = lay;
		}

		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
Baranovsky Eduard has been a software developer for more then 10 years. He has an experence in image processing, computer graphics and distributed systems design.

Comments and Discussions