/// <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); } }
/// <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> /// 打开网络数据集并初始化相应变量。 /// 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); } }