Ejemplo n.º 1
0
 /// <summary>
 /// 向地图中添加面数据集
 /// </summary>
 /// <param name="isWithStyle">是否自定义风格</param>
 public void AddRegion(Boolean isWithStyle)
 {
     try
     {
         DatasetVector dataset = m_datasource.Datasets[m_datasetRegion] as DatasetVector;
         //设置风格并添加数据集
         Layer layer = null;
         if (isWithStyle)
         {
             LayerSettingVector setting = new LayerSettingVector();
             setting.Style.LineColor        = Color.Teal;
             setting.Style.LineSymbolID     = 11;
             setting.Style.LineWidth        = 0.5;
             setting.Style.FillForeColor    = Color.FromArgb(2, 138, 226);
             setting.Style.FillBackColor    = Color.FromArgb(232, 245, 254);
             setting.Style.FillGradientMode = FillGradientMode.Radial;
             layer = m_mapControl.Map.Layers.Add(dataset, setting, true);
         }
         else
         {
             layer = m_mapControl.Map.Layers.Add(dataset, true);
         }
         //全幅显示添加的图层
         m_mapControl.Map.EnsureVisible(layer);
         m_mapControl.Map.Refresh();
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 向地图中添加线数据集
        /// </summary>
        /// <param name="isWithStyle">是否自定义风格</param>
        public void AddLine(Boolean isWithStyle)
        {
            try
            {
                DatasetVector dataset = m_datasource.Datasets[m_datasetLine] as DatasetVector;
                //设置风格并添加数据集
                Layer layer = null;
                if (isWithStyle)
                {
                    LayerSettingVector setting = new LayerSettingVector();
                    setting.Style.LineColor    = Color.Gray;
                    setting.Style.LineSymbolID = 2;
                    setting.Style.LineWidth    = 0.3;
                    layer = m_mapControl.Map.Layers.Add(dataset, setting, true);
                }
                else
                {
                    layer = m_mapControl.Map.Layers.Add(dataset, true);
                }

                //全幅显示添加的图层
                m_mapControl.Map.EnsureVisible(layer);
                m_mapControl.Map.Refresh();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 向地图中添加点数据集
 /// </summary>
 /// <param name="isWithStyle">是否自定义风格</param>
 public void AddPoint(Boolean isWithStyle)
 {
     try
     {
         DatasetVector dataset = m_datasource.Datasets[m_datasetPoint] as DatasetVector;
         //设置风格并添加数据集
         Layer layer = null;
         if (isWithStyle)
         {
             LayerSettingVector setting = new LayerSettingVector();
             setting.Style.LineColor      = Color.SeaGreen;
             setting.Style.MarkerSize     = new Size2D(4, 4);
             setting.Style.MarkerSymbolID = 12;
             layer = m_mapControl.Map.Layers.Add(dataset, setting, true);
         }
         else
         {
             layer = m_mapControl.Map.Layers.Add(dataset, true);
         }
         //全幅显示添加的图层
         m_mapControl.Map.EnsureVisible(layer);
         m_mapControl.Map.Refresh();
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 初始化控件及数据。
        /// Initialize data and control
        /// </summary>
        private void Initialize()
        {
            try
            {
                DatasourceConnectionInfo connectionInfo = new DatasourceConnectionInfo(
                    @"..\..\SampleData\City\Changchun.udb", "findClosestFacility", "");
                connectionInfo.EngineType = EngineType.UDB;
                m_workspace.Datasources.Open(connectionInfo);
                m_datasetLine = (DatasetVector)m_workspace.Datasources[0]
                                .Datasets[m_datasetName] as DatasetVector;
                m_datasetPoint       = m_datasetLine.ChildDataset;
                m_selectFacilityNode = true;
                m_selectBarrier      = false;
                m_selectEventNode    = false;
                m_Points             = new Point2Ds();
                m_barrierEdges       = new List <Int32>();
                m_barrierNodes       = new List <Int32>();
                m_selectMode         = SelectMode.SELECTPOINT;
                m_nodesList          = new List <Int32>();
                m_trackingLayer      = m_mapControl.Map.TrackingLayer;

                // 加载点数据集及线数据集并设置各自风格
                // Add point, line datasets and set their styles
                m_layerLine = m_mapControl.Map.Layers.Add(m_datasetLine, true);
                LayerSettingVector lineSetting = (LayerSettingVector)m_layerLine
                                                 .AdditionalSetting;
                GeoStyle lineStyle = new GeoStyle();
                lineStyle.LineColor = Color.LightGray;
                lineStyle.LineWidth = 0.1;
                lineSetting.Style   = lineStyle;

                m_layerPoint = m_mapControl.Map.Layers.Add(
                    m_datasetPoint, true);
                LayerSettingVector pointSetting = (LayerSettingVector)m_layerPoint
                                                  .AdditionalSetting;
                GeoStyle pointStyle = new GeoStyle();
                pointStyle.LineColor  = Color.DarkGray;
                pointStyle.MarkerSize = new Size2D(2.5, 2.5);
                pointSetting.Style    = pointStyle;

                // 调整mapControl的状态
                // Adjust the status of mapControl
                m_mapControl.Action = SuperMap.UI.Action.Select;
                m_mapControl.IsWaitCursorEnabled = false;
                m_mapControl.Map.Refresh();
                m_mapControl.MouseDown += new MouseEventHandler(m_mapControl_MouseDown);
                m_mapControl.MouseMove += new MouseEventHandler(m_mapControl_MouseMove);

                // 加载模型
                // Add model
                Load();
            }
            catch (System.Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 打开需要的工作空间,加载数据到地图上
        /// Open the workspace and add data to the map
        /// </summary>
        private void Initialize()
        {
            try
            {
                // 打开工作空间
                // Open the workspace
                String filePath = @"..\..\..\..\DATA\City\Changchun.smwu";
                WorkspaceConnectionInfo info = new WorkspaceConnectionInfo(filePath);
                info.Type = WorkspaceType.SMWU;
                m_workspace.Open(info);

                // 加载底图
                // Load the base map
                if (SuperMap.Data.Environment.CurrentCulture != "zh-CN")
                {
                    m_mapControl.Map.Open("ChangChunCityMap");
                }
                else
                {
                    m_mapControl.Map.Open("长春市区图");
                }
                // 获取公交线路(BusLine)、站点(BusStop)和网络数据集
                // Get BusLine, BusStop and network dataset
                m_datasource     = m_workspace.Datasources["changchun"];
                m_datasetLine    = m_datasource.Datasets["BusLine"] as DatasetVector;
                m_datasetStop    = m_datasource.Datasets["BusPoint"] as DatasetVector;
                m_datasetNetwork = m_datasource.Datasets["RoadNet"] as DatasetVector;

                // 底图中有线路数据集的图层,因此不再添加
                // 为突出显示站点,将站点添加到地图上并设置风格
                // The base map has a path dataset
                // Add stops the map and set their style
                m_layerStop = m_mapControl.Map.Layers.Add(m_datasetStop, true);
                m_layerStop.IsSelectable = true;

                // 设置站点数据集的图层风格
                // Set the layer style for the stops
                LayerSettingVector stopSetting = new LayerSettingVector();
                GeoStyle           stopStyle   = new GeoStyle();
                stopStyle.LineColor           = Color.FromArgb(170, 0, 192);
                stopStyle.MarkerSize          = new Size2D(4, 4);
                stopSetting.Style             = stopStyle;
                m_layerStop.AdditionalSetting = stopSetting;

                m_mapControl.Map.IsAntialias = true;
                m_mapControl.Map.Refresh();

                // 设置跟踪图层
                // Set the tracking layer
                m_trackingLayer = m_mapControl.Map.TrackingLayer;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
 /// <summary>
 /// 设置图层的一些属性
 /// Set the properties of the layer
 /// </summary>
 private void SetLayerStyle(Layer layer, Color color, Double width)
 {
     try
     {
         LayerSettingVector layerSetting = new LayerSettingVector();
         GeoStyle           style        = new GeoStyle();
         style.FillForeColor     = Color.SkyBlue;
         style.LineColor         = color;
         style.LineWidth         = width;
         layerSetting.Style      = style;
         layer.AdditionalSetting = layerSetting;
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.Message);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 打开需要的工作空间文件及事件注册
        /// </summary>
        private void Initialize()
        {
            try
            {
                //打开工作空间及地图
                WorkspaceConnectionInfo conInfo = new WorkspaceConnectionInfo(mFilePath);
                mWorkspace.Open(conInfo);
                //创建数据集
                CreateDatasets();
                //禁用鼠标等待
                mMapControl.IsWaitCursorEnabled = false;          //当前窗口的等待光标是否有效
                mMapControl.TrackMode           = TrackMode.Edit; //TrackMode.Edit在图层中创建一个新对象
                //该枚举定义了绘制方式类型常量。用来定义地图控件中绘制对象时,是在图层中创建一个新对象还是在内存中创建一个新对象,或者是在CAD图层中绘制地图几何对象(GeoMap)。

                //获得默认的对象风格
                mDefaultSetting = new LayerSettingVector();   //构造矢量图层设置新实例
                GeoStyle defaultStyle = new GeoStyle();       //构造 几何风格 对象
                defaultStyle.LineColor = Color.Green;         //颜色
                defaultStyle.LineWidth = 0.3;                 //宽度
                mDefaultSetting.Style  = defaultStyle;        //设置矢量图层的风格 为 defaultStyle
                //初始化背景图片显示时对象的风格
                mBackgroudSetting = new LayerSettingVector(); //
                GeoStyle backgroudStyle = new GeoStyle();
                backgroudStyle.FillForeColor = Color.PaleGreen;;
                backgroudStyle.LineColor     = Color.Red;
                backgroudStyle.LineWidth     = 0.3;
                mBackgroudSetting.Style      = backgroudStyle;

                mMapControl.Tracked += new TrackedEventHandler(m_mapControl_Tracked); //在地图窗口中绘制几何对象 结束后发生

                DrawPoint();                                                          //绘制点
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 8
0
        private void 添加标题ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gk066 addTitle = new gk066();

            addTitle.StartPosition = FormStartPosition.CenterScreen;    //窗体居中
            addTitle.ShowDialog();

            #region 添加标文本题
            //标题添加
            TextStyle textStyle = new TextStyle();
            textStyle.Alignment   = TextAlignment.TopCenter;
            textStyle.BackColor   = Color.FromArgb(65, 65, 65);
            textStyle.ForeColor   = Color.FromArgb(174, 241, 176);
            textStyle.BackOpaque  = false;
            textStyle.Bold        = true;
            textStyle.FontName    = "楷体";
            textStyle.FontHeight  = addTitle.FontHeight;
            textStyle.FontWidth   = addTitle.FontWidth;
            textStyle.IsSizeFixed = false;
            textStyle.Italic      = true;
            textStyle.Outline     = true;
            textStyle.Weight      = 500;

            //添加文本
            TextPart textPart = new TextPart(addTitle.title, new Point2D(850, 2150), 0);
            geoText = new GeoText(textPart, textStyle);
            //先删除后添加实现刷新效果
            if (ElementsId != -1)
            {
                ElementsIdS[0] = ElementsId;
                mapLayoutControl1.MapLayout.Elements.Delete(ElementsIdS);
            }
            //添加地图
            mapLayoutControl1.MapLayout.Elements.AddNew(geoText);
            //取得id 下次设定时删除用
            ElementsId = mapLayoutControl1.MapLayout.Elements.GetID();
            mapLayoutControl1.MapLayout.Elements.Refresh();
            #endregion

            #region 设定图层颜色 与显示比例尺
            geoMapUse = mapLayoutControl1.MapLayout.Elements.GetGeometry() as GeoMap;
            Map map = new Map();
            map.Workspace = workspace1;
            map.FromXML(workspace1.Maps.GetMapXML(geoMapUse.MapName));
            LayerSettingVector setting = map.Layers[0].AdditionalSetting as LayerSettingVector;
            setting.Style.FillForeColor     = addTitle.selectColor;
            map.Layers[0].AdditionalSetting = setting;
            workspace1.Maps.SetMapXML(geoMapUse.MapName, map.ToXML());
            workspace1.Save();
            geoMapUse         = new GeoMap();
            geoMapUse.MapName = "temp";
            //设置GeoMap对象的外切矩形
            Rectangle2D rect = new Rectangle2D(new Point2D(850, 1300), new Size2D(
                                                   1500, 1500));
            GeoRectangle geoRect = new GeoRectangle(rect, 0);
            geoMapUse.Shape = geoRect;
            //动态设置缩放比例尺
            geoMapUse.MapScale = addTitle.scaleNumerator / addTitle.scaleDenominato;
            mapLayoutControl1.MapLayout.Elements.AddNew(geoMapUse);
            //记录下mapid
            ElementsIdMap = mapLayoutControl1.MapLayout.Elements.GetID();
            mapLayoutControl1.MapLayout.Elements.Refresh();
            #endregion

            #region 添加地图比例标尺
            //添加地图带比例标尺
            geoMapScale                   = new GeoMapScale(ElementsIdMap, new Point2D(1050, 515), 550, 18);
            geoMapScale.ScaleUnit         = Unit.Kilometer;
            geoMapScale.LeftDivisionCount = 2;
            geoMapScale.SegmentCount      = 2;
            geoMapScale.ScaleType         = GeoMapScaleType.Railway;
            ////先删除后添加实现刷新效果
            if (ElementsIdScale != -1)
            {
                ElementsIdScaleArrar[0] = ElementsIdScale;
                mapLayoutControl1.MapLayout.Elements.Delete(ElementsIdScaleArrar);
            }
            //取得id 下次设定时删除用
            mapLayoutControl1.MapLayout.Elements.AddNew(geoMapScale);
            ElementsIdScale = mapLayoutControl1.MapLayout.Elements.GetID();
            mapLayoutControl1.MapLayout.Elements.Refresh();
            #endregion

            addTitle.Close();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 打开网络数据集并初始化相应变量。
        /// Open the network dataset and initialize variables
        /// </summary>
        private void Initialize()
        {
            try
            {
                // 打开数据源,得到点线数据集
                // Open datasource and get the point , line datasets
                DatasourceConnectionInfo connectionInfo = new DatasourceConnectionInfo(
                    @"..\..\SampleData\City\Changchun.udb", "FindPath2D", "");
                connectionInfo.EngineType = EngineType.UDB;
                m_workspace.Datasources.Open(connectionInfo);
                m_datasetLine               = (DatasetVector)m_workspace.Datasources[0].Datasets[m_datasetName];
                m_datasetPoint              = m_datasetLine.ChildDataset;
                m_trackingLayer             = m_mapControl.Map.TrackingLayer;
                m_trackingLayer.IsAntialias = true;

                // 初始化各变量
                // Initialzie variables
                m_flag         = 1;
                m_Points       = new Point2Ds();
                m_style        = new GeoStyle();
                m_barrierNodes = new List <Int32>();
                m_barrierEdges = new List <Int32>();
                m_selectMode   = SelectMode.SelectPoint;

                m_timer          = new Timer();
                m_timer.Interval = 200;
                m_timer.Enabled  = false;

                // 加载点数据集及线数据集并设置各自风格
                // Add point, line datasets and set their styles
                m_layerLine = m_mapControl.Map.Layers.Add(m_datasetLine, true);
                m_layerLine.IsSelectable = false;
                LayerSettingVector lineSetting = (LayerSettingVector)m_layerLine.AdditionalSetting;
                GeoStyle           lineStyle   = new GeoStyle();
                lineStyle.LineColor = Color.LightGray;
                lineStyle.LineWidth = 0.1;
                lineSetting.Style   = lineStyle;

                m_layerPoint = m_mapControl.Map.Layers.Add(m_datasetPoint, true);
                LayerSettingVector pointSetting = (LayerSettingVector)m_layerPoint.AdditionalSetting;
                GeoStyle           pointStyle   = new GeoStyle();
                pointStyle.LineColor  = Color.DarkGray;
                pointStyle.MarkerSize = new Size2D(2.5, 2.5);
                pointSetting.Style    = pointStyle;

                // 调整mapControl的状态
                // Adjust the status of mapControl
                m_mapControl.Action              = SuperMap.UI.Action.Select;
                m_mapControl.Map.IsAntialias     = true;
                m_mapControl.IsWaitCursorEnabled = false;
                m_mapControl.Map.Refresh();

                m_mapControl.MouseDown        += new MouseEventHandler(m_mapControl_MouseDown);
                m_mapControl.GeometrySelected += new GeometrySelectedEventHandler(m_mapControl_GeometrySelected);
                m_timer.Tick += new EventHandler(m_timer_Tick);
                Load();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
            }
        }
Ejemplo n.º 10
0
        private void CreateDatasets()
        {
            if (m_bAddedPointLayer)
            {
                return;
            }
            try
            {
                //创建点数据集
                Datasource datasource = m_workspace.Datasources[0];

                PrjCoordSys crtPrjSys;
                //if (m_workspace.Maps.Count == 0)
                {
                    crtPrjSys      = new PrjCoordSys();
                    crtPrjSys.Type = PrjCoordSysType.EarthLongitudeLatitude;
                }
                //else
                //{
                //crtPrjSys = m_MapControl.Map.Layers[UserHelper.MapLayerName].Dataset.PrjCoordSys;
                // }

                for (int iDeviceIndex = 0; iDeviceIndex < UserHelper.nDeviceNum; iDeviceIndex++)
                {
                    datasource.Datasets.Delete(UserHelper.sDeviceName[iDeviceIndex]);
                    DatasetVectorInfo pointLayerInfo = new DatasetVectorInfo(UserHelper.sDeviceName[iDeviceIndex], DatasetType.Point);
                    DatasetVector     pointDataset   = datasource.Datasets.Create(pointLayerInfo);

                    // 添加使用的字段
                    FieldInfo fieldInfo = new FieldInfo();
                    fieldInfo.Type = FieldType.Char;
                    fieldInfo.Name = m_filedName;
                    pointDataset.FieldInfos.Add(fieldInfo);
                    pointDataset.PrjCoordSys = crtPrjSys;

                    //将点数据集加入到地图中
                    LayerSettingVector setting = new LayerSettingVector();
                    setting.Style.LineColor      = Color.SeaGreen;
                    setting.Style.MarkerSize     = new Size2D(8, 8);
                    setting.Style.MarkerSymbolID = UserHelper.MarkerSymbolID[iDeviceIndex];
                    m_MapControl.Map.Layers.Add(pointDataset, setting, true);
                    m_MapControl.Map.Refresh();
                }

                datasource.Datasets.Delete(UserHelper.sTextName);
                DatasetVectorInfo textLayerInfo = new DatasetVectorInfo(UserHelper.sTextName, DatasetType.Text);
                DatasetVector     textDataset   = datasource.Datasets.Create(textLayerInfo);
                textDataset.PrjCoordSys = crtPrjSys;
                m_MapControl.Map.Layers.Add(textDataset, true);
                m_MapControl.Map.Refresh();

                //定义新数据集
                {
                    datasource.Datasets.Delete("Point3D");
                    DatasetVectorInfo Datasetinfo = new DatasetVectorInfo();
                    Datasetinfo.Type = DatasetType.CAD;
                    Datasetinfo.Name = "Point3D";
                    DatasetVector datset = datasource.Datasets.Create(Datasetinfo);

                    FieldInfo fieldInfo = new FieldInfo();
                    fieldInfo.Type = FieldType.Char;
                    fieldInfo.Name = m_filedName;
                    datset.FieldInfos.Add(fieldInfo);
                    datset.PrjCoordSys = crtPrjSys;

                    DatasetVector datasetPoint3D = datasource.Datasets["Point3D"] as DatasetVector;

                    if (m_SceneControl.Scene.Layers.Contains("stylePoint3D"))
                    {
                        m_layer3DPoint = m_SceneControl.Scene.Layers["stylePoint3D"] as Layer3DDataset;
                    }
                    else
                    {
                        m_layer3DPoint = m_SceneControl.Scene.Layers.Add(datasetPoint3D, new Layer3DSettingVector(), true, "stylePoint3D");
                    }
                    m_SceneControl.Scene.Refresh();
                }

                // 新建数据集
                {
                    datasource.Datasets.Delete("Region3D");
                    DatasetVectorInfo Datasetinfo = new DatasetVectorInfo();
                    Datasetinfo.Type = DatasetType.Region3D;
                    Datasetinfo.Name = "Region3D";
                    DatasetVector datset = datasource.Datasets.Create(Datasetinfo);
                    datset.PrjCoordSys = crtPrjSys;

                    DatasetVector m_datasetRegion3D = datasource.Datasets["Region3D"] as DatasetVector;
                    if (m_SceneControl.Scene.Layers.Contains("styleRegion3D"))
                    {
                        m_layer3DRegion = m_SceneControl.Scene.Layers["styleRegion3D"] as Layer3DDataset;
                    }
                    else
                    {
                        m_layer3DRegion = m_SceneControl.Scene.Layers.Add(m_datasetRegion3D, new Layer3DSettingVector(), true, "styleRegion3D");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            m_bAddedPointLayer = true;
        }