public int GetMapID() { int mapID = -1; int count = 0; LayoutSelection layoutSelection = mapLayoutControl1.MapLayout.Selection; LayoutElements layoutElements = mapLayoutControl1.MapLayout.Elements; layoutElements.Refresh(); for (int i = 0; i < layoutSelection.Count; i++) { int ID = layoutSelection[i]; layoutElements.SeekID(ID); Geometry geometry = layoutElements.GetGeometry(); if (geometry.Type == GeometryType.GeoMap) { mapID = ID; count++; } if (count > 1) { mapID = -1; } } return(mapID); }
/// <summary> /// 对象添加事件 /// Maplayout tracked eventhandle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void m_mapLayoutControl_ElementAdded(object sender, ElementEventArgs e) { try { LayoutElements elements = m_mapLayoutControl.MapLayout.Elements; if (elements.SeekID(e.ID)) { Geometry gemetry = elements.GetGeometry(); if (gemetry != null) { GeoNorthArrow northArrow = gemetry as GeoNorthArrow; if (northArrow != null) { northArrow.BindingGeoMapID = m_mapID; } GeoMapScale mapScale = gemetry as GeoMapScale; if (mapScale != null) { mapScale.BindingGeoMapID = m_mapID; } elements.SetGeometry(gemetry); elements.Refresh(); m_mapLayoutControl.MapLayout.Refresh(); } } } catch (Exception ex) { Trace.WriteLine(ex.Message); } }