//在view中加载图形,和同步图形 void SyncToView() { IView view = InputCB.SelectedItem as IView; //为图形赋值“Name”属性,以便图形和数据关联 foreach (int monID in _MonGraphics.Keys) { MonPoint mp = _allMons[monID] as MonPoint; IGraphicCollection gc = _MonGraphics[monID]; foreach (IGraphic g in gc) { g.Attributes["Name"] = mp.name; } } //将图形添加到view中 string layerID = "DemoLayer"; //图层ID IGraphicsLayer gLayer = getDemoLayer(view, layerID); //获取图层函数 foreach (int id in _MonGraphics.Keys) { IGraphicCollection gc = _MonGraphics[id]; gLayer.addGraphics(gc); } //使数据与图形关联 List <DGObject> sls = _allMons.merge(); gLayer.syncObjects(sls); //计算新建图形范围,并在地图中显示该范围 IEnvelope ext = null; foreach (IGraphicCollection gc in _MonGraphics.Values) { IEnvelope itemExt = GraphicsUtil.GetGraphicsEnvelope(gc); if (ext == null) { ext = itemExt; } else { ext = ext.Union(itemExt); } } _mainFrame.activeView = view; view.zoomTo(ext); }
void StartAnalyzing() { //Get input view IView view = InputCB.SelectedItem as IView; _spatialRef = view.spatialReference; //create new layer view.removeLayer("Rectanglelayer"); //clear the previous layer string layerID = "Rectanglelayer"; IGraphicsLayer mlayer = Runtime.graphicEngine.newGraphicsLayer(layerID, layerID); var sym_fill = GraphicsUtil.GetDefaultFillSymbol(); var renderer = Runtime.graphicEngine.newSimpleRenderer(sym_fill); mlayer.setRenderer(renderer); mlayer.Opacity = 1.0; view.addLayer(mlayer); //Define local variables IGraphic m; int count = 0; int result = 5; double monpointX; double monpointY; _monpoints = _prj.getSelectedObjs(_monitoringDomain, "MonPoint"); foreach (DGObject mp in _mps) { MonPoint _mp = mp as MonPoint; foreach (string key in _mp.readingsDict.Keys) { List <MonReading> a = _mp.readingsDict[key]; foreach (MonReading b in a) { if (System.Math.Abs(b.value) > mptb) { count++; } } if (count <= 50) { result = 5; } else if (count <= 150) { result = 4; } else if (count <= 250) { result = 3; } else if (count <= 350) { result = 2; } else { result = 1; } ISymbol symbol = GetSymbol(result); //Obtain borehole coordinates IGraphicsLayer mplayer = view.getLayer("MonPoint"); IGraphicCollection mpcollection = mplayer.getGraphics(_mp); m = mpcollection[0]; IGeometry mpgeometry = m.Geometry; IMapPoint mpmappoint = mpgeometry as IMapPoint; monpointX = mpmappoint.X; monpointY = mpmappoint.Y; //Draw rectangle IMapPoint p1 = Runtime.geometryEngine.newMapPoint(monpointX + 2200, monpointY + 2200, _spatialRef); IMapPoint p2 = Runtime.geometryEngine.newMapPoint(monpointX + 2200, monpointY - 2200, _spatialRef); IMapPoint p3 = Runtime.geometryEngine.newMapPoint(monpointX - 2200, monpointY - 2200, _spatialRef); IMapPoint p4 = Runtime.geometryEngine.newMapPoint(monpointX - 2200, monpointY + 2200, _spatialRef); m = Runtime.graphicEngine.newQuadrilateral(p1, p2, p3, p4); m.Symbol = symbol; IGraphicCollection gc = Runtime.graphicEngine.newGraphicCollection(); gc.Add(m); mlayer.addGraphics(gc); } } }