public void Render(object sender, IDrawArgs drawArgs) { if (_cntLines == null || _cntLines.Length == 0 || _contourClassItems == null || _contourClassItems.Length == 0) { return; } if (_canvas == null) { _canvas = sender as ICanvas; _canvasSizeChanged = new EventHandler(Container_SizeChanged); _canvas.OnEnvelopeChanged += _canvasSizeChanged; _conflictor = new PixelConflictor(_canvas.Container.Size); } CoordEnvelope evp = _canvas.CurrentEnvelope; _crtCanvasEnvelope = new ContourLine.ContourEnvelope((float)evp.MinX, (float)evp.MaxX, (float)evp.MinY, (float)evp.MaxY); TryUpdateLabelBuffers(drawArgs); TryProject(); TrySetSmoothMode(drawArgs); TryResetConflictor(); float minWidth = MIN_WIDTH * _canvas.ResolutionX; float minHeight = MIN_WIDTH * _canvas.ResolutionY; ContourLine.ContourEnvelope thisEvp = null; int classIdx = 0; ContourClass cntClass = null; foreach (ContourLine cntLine in _cntLines) { if (cntLine == null) { continue; } classIdx = cntLine.ClassIndex; cntClass = _contourClassItems[classIdx]; thisEvp = cntLine.Envelope; //如果不在可视区域则绘制 if (!_crtCanvasEnvelope.IsInteractived(thisEvp)) { continue; } //如果在当前比例尺下太小则不显示 if (thisEvp.Width > minWidth || thisEvp.Height > minHeight) { DrawContour(drawArgs, cntLine, cntClass, _canvas); } } }
public override void Dispose() { if (_contourClassItems != null) { foreach (ContourClass it in _contourClassItems) { it.Dispose(); } _contourClassItems = null; } if (_grahpicPath != null) { _grahpicPath.Dispose(); _grahpicPath = null; } if (_font != null) { _font.Dispose(); _font = null; } if (_labelBrush != null) { _labelBrush.Dispose(); _labelBrush = null; } if (_maskBrush != null) { _maskBrush.Dispose(); _maskBrush = null; } if (_conflictor != null) { _conflictor.Dispose(); _conflictor = null; } FreeLabelBuffers(); if (_canvas != null) { _canvas.OnEnvelopeChanged -= _canvasSizeChanged; _canvasSizeChanged = null; } base.Dispose(); }
public void Apply(IMap map) { if (map == null) { return; } if (_map != null) { _map.Dispose(); _map = null; } _map = map; (_map as Map).InternalInit(_projectionTransform, this as IFeatureRenderEnvironment); // if (_gridExchanger != null) { _gridExchanger.Enabled = false; _gridExchanger.Dispose(); _gridExchanger = null; } // _gridExchanger = new RuntimeExchanger(this as IFeatureRenderEnvironment, _environment as IMapRefresh, _map.LayerContainer, _asyncDataArrivedNotify); // (_map as Map).InternalApplyLayers(); // if (_conflictorForSymbol != null) { _conflictorForSymbol.Dispose(); } _conflictorForSymbol = new SimpleConflictor(_map.ConflictDefForSymbol, _environment); if (_conflictorForLabel != null) { _conflictorForLabel.Dispose(); } _conflictorForLabel = new PixelConflictor(_map.ConflictDefForLabel, _environment); }
// #region ILabelRender Members public void Begin(IConflictor conflictor, object environment) { _conflictor = conflictor; _environment = environment as IFeatureRenderEnvironment; }
public void Render(bool enableDisplayLevel, QuickTransformArgs quickTransformArgs, IGrid gd, Graphics g, Envelope rect, RepeatFeatureRecorder recorder) { if (g == null) { return; } _currentFeatureRects.Clear(); List <Feature> features = gd.VectorFeatures; if (features == null || features.Count == 0) { return; } _quickTransformArgs = quickTransformArgs; int fetCount = features.Count; Feature feature = null; IOutsideIndicator outsideIndicator = null; bool isfullInside = (gd as Grid)._isfullInternal; for (int i = 0; i < fetCount; i++) { feature = features[i]; if (feature == null || feature.Geometry == null) { continue; } outsideIndicator = feature.OutsideIndicator;// (feature as ISupportOutsideIndicator).OutsideIndicator; //判断是否在该级别显示 if (enableDisplayLevel && feature.DisplayLevel != -1) { if (feature.DisplayLevel > _environment.CurrentLevel) { outsideIndicator.SetOutside(true); continue; } } //可见性计算 if (!isfullInside) { if (feature.Geometry is ShapePoint) { outsideIndicator.SetOutside(!IsPointInCurrentExtent(feature, rect)); } else //Polyline,Polygon { outsideIndicator.SetOutside(!IsPolygonInCurrentExtent(feature, rect)); } if (outsideIndicator.IsOutside) { continue; } } else//整个网格都在可视区域内部 { outsideIndicator.SetOutside(false); } //是否已经在其他网格绘制过了 if (feature.IsRepeatedOverGrids) { if (recorder.IsRendered(feature.OID)) { continue; } else { recorder.AddRenderedOID(feature.OID); } } //为要素设置绘制符号 SetCurrentSymbolFromFeature(feature); if (_currentSymbol == null) { continue; } //为符号设置角度 SetAngleOfSymbol(feature); //画几何形状 try { if (feature.Geometry is ShapePoint) { PointF pt = ShapePoint2PixelPoint(feature.Geometry as ShapePoint); //位置冲突检测 if (_environment != null) { IConflictor conflictorForSymbol = _environment.ConflictorForSymbol; if (conflictorForSymbol != null && conflictorForSymbol.Enabled) { //符号冲突 if (conflictorForSymbol.IsConflicted(pt.X - _currentSymbol.SymbolHalfWidth, pt.Y - _currentSymbol.SymbolHalfHeight, _currentSymbol.SymbolSize)) { outsideIndicator.SetOutside(true); continue; } } } //画符号 DrawPointUseCurrentSymbol(g, pt); //记下要素符号矩形区域 _currentFeatureRects.Add(feature, new RectangleF((_currentSymbol as IMarkerSymbol).PixelLocation, _currentSymbol.SymbolSize)); //符号不冲突,在标注冲突检测网格中占位 #region debug //符号矩形 //PointF tpt = new PointF((pt.X - _currentSymbol.SymbolSize.Width / 2f), // (pt.Y - _currentSymbol.SymbolSize.Height / 2f)); //(_environment.ConflictorForLabel as PixelConflictor).DrawTestRectangleF(tpt, _currentSymbol.SymbolSize, Color.Yellow); #endregion if (_environment != null) { if (_environment.ConflictorForLabel != null && _environment.ConflictorForLabel.Enabled) { _environment.ConflictorForLabel.HoldPosition((pt.X - _currentSymbol.SymbolSize.Width / 2f), (pt.Y - _currentSymbol.SymbolSize.Height / 2f), _currentSymbol.SymbolSize); } } } else //Polyline,Polygon { SetGraphicsPathFromGeometry(feature.Geometry); if (_path.PointCount > 0) { DrawPathUseCurrentSymbol(g); _currentFeatureRects.Add(feature, RectangleF.Empty); } } } catch (Exception ex) { Log.WriterException("BaseFeatureRenderer", "Render(Layer:" + (_name != null ?_name : string.Empty) + ",OID:" + feature.OID.ToString() + ")", ex); } finally { _currentSymbol.Angle = 0; } } }