public void UpdateFeatureInfos(MapUtil.FeatureInformations featureInfos, Point mousePosition) { this.lsvFeatureProperties.Items.Clear(); if (featureInfos == null) { this.Hide(); } else { this.lsvFeatureProperties.Items.Clear(); Dictionary <string, string> .KeyCollection oFieldsCollection = featureInfos.FieldsAndValuesCollection.Keys; string sValue; foreach (string sFieldName in oFieldsCollection) { this.lsvFeatureProperties.Items.Add(sFieldName); featureInfos.FieldsAndValuesCollection.TryGetValue(sFieldName, out sValue); this.lsvFeatureProperties.Items[this.lsvFeatureProperties.Items.Count - 1].SubItems.Add(sValue); } this.labLayerInfos.Text = string.Format("ͼ²ã : {0}", featureInfos.CurrentLayerInfos.AliasName); if (!this.Visible) { this.Show(); } this.Location = mousePosition; this.Activate(); } }
//public void LoadLayersToLegendControl(ProjectUtil.MapStruct mapInfosCollection, System.Windows.Forms.ImageList imageList, ref System.Windows.Forms.TreeView legendControl) //{ // if (legendControl.Nodes.Count == 0) // legendControl.Nodes.Add("layergroup", "图层", imageList.Images.IndexOfKey("layergroup")); // string sShapeType = string.Empty; // foreach (ProjectUtil.ILayerStruct item in mapInfosCollection.Layers) // { // if (item is ProjectUtil.MapLayerInfoStruct) // { // sShapeType = ((MapObjects2.ShapeTypeConstants)(item as ProjectUtil.MapLayerInfoStruct).ShapeType).ToString(); // legendControl.Nodes[0].Nodes.Add(sShapeType,item.AliasName, imageList.Images.IndexOfKey(sShapeType)); // } // else if (item is ProjectUtil.ImageLayerInfoStruct) // { // legendControl.Nodes[0].Nodes.Add("ImageLayer", item.AliasName, imageList.Images.IndexOfKey("ImageLayer")); // } // } //} public FeatureInformations GetIdentifyFeatureInfos(MapObjects2.Point mousePosition, AxMapObjects2.AxMap mapControl, MapProject.MapStruct mapInfosCollection) { FeatureInformations oFeatureInfos = null; foreach (ILayerStruct oLayerInfos in mapInfosCollection.Layers) { if (oLayerInfos.LayerType != (short)LayerTypeConstants.moMapLayer) { continue; } MapUtil.MapOperation oMapOper = new MapOperation(); MapObjects2.MapLayer oMapLayer = oMapOper.GetLayerByName(mapControl, oLayerInfos.AliasName) as MapObjects2.MapLayer; if (oMapLayer.Visible == false) { continue; } Recordset oSelectedRecords = oMapLayer.SearchShape(mousePosition, SearchMethodConstants.moAreaIntersect, ""); if (oSelectedRecords.EOF) { continue; } oSelectedRecords.MoveFirst(); oFeatureInfos = new FeatureInformations(); oFeatureInfos.CurrentLayerInfos = oLayerInfos; oFeatureInfos.Geometry = oSelectedRecords.Fields.Item("shape").Value; TableDesc oTableDesc = oSelectedRecords.TableDesc; oFeatureInfos.FieldsAndValuesCollection = new Dictionary <string, string>(); int iFieldsCount = oTableDesc.FieldCount; string sFieldName = ""; string sValue = ""; for (short i = 0; i < iFieldsCount; i++) { sFieldName = oTableDesc.get_FieldName(i); sValue = oSelectedRecords.Fields.Item(sFieldName).ValueAsString; oFeatureInfos.FieldsAndValuesCollection.Add(sFieldName, sValue); } break; } return(oFeatureInfos); }
private void mapControl_MouseDownEvent(object sender, AxMapObjects2._DMapEvents_MouseDownEvent e) { MapObjects2.Point oMousePosition = mapControl.ToMapPoint(e.x, e.y); MapUtil.MapOperation oMapOper = new MapUtil.MapOperation(); switch (GlobeVariables.CurrentOperation) { case MapUtil.MapOperationType.ZoomIn: oMapOper.ZoomInMap(mapControl.TrackRectangle(), ref mapControl); break; case MapUtil.MapOperationType.ZoomOut: oMapOper.ZoomOutMap(mapControl.TrackRectangle(), ref mapControl); break; case MapUtil.MapOperationType.Pan: mapControl.Pan(); break; case MapUtil.MapOperationType.Measure: this._measureLine = mapControl.TrackLine(); this.labMeasure.Text = string.Format("长度 : {0} 米", oMapOper.ComputeDistance(this._measureLine).ToString()); break; case MapUtil.MapOperationType.Identify: MapUtil.FeatureInformations oFeatureInfos = oMapOper.GetIdentifyFeatureInfos(oMousePosition, this.mapControl, GlobeVariables.MapInfosCollection); this._frmIdentify.UpdateFeatureInfos(oFeatureInfos, MousePosition); break; case MapUtil.MapOperationType.FetchPoint: this.OnPointFetched(oMousePosition); break; default: break; } }
//public void LoadLayersToLegendControl(ProjectUtil.MapStruct mapInfosCollection, System.Windows.Forms.ImageList imageList, ref System.Windows.Forms.TreeView legendControl) //{ // if (legendControl.Nodes.Count == 0) // legendControl.Nodes.Add("layergroup", "ͼ��", imageList.Images.IndexOfKey("layergroup")); // string sShapeType = string.Empty; // foreach (ProjectUtil.ILayerStruct item in mapInfosCollection.Layers) // { // if (item is ProjectUtil.MapLayerInfoStruct) // { // sShapeType = ((MapObjects2.ShapeTypeConstants)(item as ProjectUtil.MapLayerInfoStruct).ShapeType).ToString(); // legendControl.Nodes[0].Nodes.Add(sShapeType,item.AliasName, imageList.Images.IndexOfKey(sShapeType)); // } // else if (item is ProjectUtil.ImageLayerInfoStruct) // { // legendControl.Nodes[0].Nodes.Add("ImageLayer", item.AliasName, imageList.Images.IndexOfKey("ImageLayer")); // } // } //} public FeatureInformations GetIdentifyFeatureInfos(MapObjects2.Point mousePosition,AxMapObjects2.AxMap mapControl,MapProject.MapStruct mapInfosCollection) { FeatureInformations oFeatureInfos = null; foreach (ILayerStruct oLayerInfos in mapInfosCollection.Layers) { if (oLayerInfos.LayerType != (short)LayerTypeConstants.moMapLayer) continue; MapUtil.MapOperation oMapOper = new MapOperation(); MapObjects2.MapLayer oMapLayer = oMapOper.GetLayerByName(mapControl, oLayerInfos.AliasName) as MapObjects2.MapLayer; if (oMapLayer.Visible == false) continue; Recordset oSelectedRecords = oMapLayer.SearchShape(mousePosition,SearchMethodConstants.moAreaIntersect, ""); if (oSelectedRecords.EOF) continue; oSelectedRecords.MoveFirst(); oFeatureInfos = new FeatureInformations(); oFeatureInfos.CurrentLayerInfos = oLayerInfos; oFeatureInfos.Geometry = oSelectedRecords.Fields.Item("shape").Value; TableDesc oTableDesc = oSelectedRecords.TableDesc; oFeatureInfos.FieldsAndValuesCollection = new Dictionary<string,string>(); int iFieldsCount = oTableDesc.FieldCount; string sFieldName = ""; string sValue = ""; for (short i = 0; i < iFieldsCount; i++) { sFieldName = oTableDesc.get_FieldName(i); sValue = oSelectedRecords.Fields.Item(sFieldName).ValueAsString; oFeatureInfos.FieldsAndValuesCollection.Add(sFieldName, sValue); } break; } return oFeatureInfos; }