public moFeature Clone() { moGeometryTypeConstant sShapeType = _ShapeType; moGeometry sGeometry = null; moAttributes sAttributes = _Attributes.Clone(); if (_ShapeType == moGeometryTypeConstant.Point) { moPoint sPoint = (moPoint)_Geometry; sGeometry = sPoint.Clone(); } else if (_ShapeType == moGeometryTypeConstant.MultiPolyline) { moMultiPolyline sMultiPolyline = (moMultiPolyline)_Geometry; sGeometry = sMultiPolyline.Clone(); } else if (_ShapeType == moGeometryTypeConstant.MultiPolygon) { moMultiPolygon sMultiPolygon = (moMultiPolygon)_Geometry; sGeometry = sMultiPolygon.Clone(); } moFeature sFeature = new moFeature(sShapeType, sGeometry, sAttributes); return(sFeature); }
private void _AttributeFileds_FieldRemoved(object sender, int fieldIndex, moField fieldRemoved) { Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i < sFeatureCount; i++) { moFeature sFeature = _Features.GetItem(i); sFeature.Attributes.RemoveAt(fieldIndex); } }
/// <summary> /// 绘制所有选择要素 /// </summary> /// <param name="g"></param> /// <param name="extent"></param> /// <param name="mapScale"></param> /// <param name="dpm"></param> /// <param name="mpu"></param> /// <param name="symbol"></param> internal void DrawSelectedFeatures(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, moSymbol symbol) { //判断是否位于绘制范围内,不是,则绘制 Int32 sFeatureCount = _SelectedFeatures.Count; for (Int32 i = 0; i < sFeatureCount; i++) { moFeature sFeature = _SelectedFeatures.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == true) { moGeometry sGeometry = sFeature.Geometry; moMapDrawingTools.DrawGeometry(g, extent, mapScale, dpm, mpu, sGeometry, symbol); } } }
private moFeature CreateNewFeature() { moAttributes sAttributes = new moAttributes(); Int32 sFieldCount = _AttributeFields.Count; for (Int32 i = 0; i <= sFieldCount - 1; i++) { moField sField = _AttributeFields.GetItem(i); if (sField.ValueType == moValueTypeConstant.dInt16) { Int16 sValue = 0; sAttributes.Append(sValue); } else if (sField.ValueType == moValueTypeConstant.dInt32) { Int32 sValue = 0; sAttributes.Append(sValue); } else if (sField.ValueType == moValueTypeConstant.dInt64) { Int64 sValue = 0; sAttributes.Append(sValue); } else if (sField.ValueType == moValueTypeConstant.dSingle) { float sValue = 0; sAttributes.Append(sValue); } else if (sField.ValueType == moValueTypeConstant.dDouble) { double sValue = 0; sAttributes.Append(sValue); } else if (sField.ValueType == moValueTypeConstant.dText) { String sValue = ""; sAttributes.Append(sValue); } else { throw new Exception("Invalid value type!"); } } moFeature sFeature = new moFeature(_ShapeType, null, sAttributes); return(sFeature); }
/// <summary> /// 指定要素是否位于指定范围内,这里仅计算要素的外包矩形与范围举行是否相交,判断是否需要绘制 /// </summary> /// <param name="feature"></param> /// <param name="extent"></param> /// <returns></returns> private bool IsFeatureInExtent(moFeature feature, moRectangle extent) { moRectangle sRect = feature.GetEnvelope(); if (sRect.MaxX < extent.MinX || sRect.MinX > extent.MaxX) { return(false); } else if (sRect.MaxY < extent.MinY || sRect.MinY > extent.MaxY) { return(false); } else { return(true); } }
/// <summary> /// 绘制所有要素 /// </summary> /// <param name="g">绘图对象</param> /// <param name="extent">绘制范围(地图坐标)</param> /// <param name="mapScale">地图比例尺的倒数</param> /// <param name="dpm">每米对应的点数</param> /// <param name="mpu">地图坐标单位对应的米数</param> internal void DrawFeatures(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu) { //(1)为所有要素配置符号 SetFeatureSymbols(); //(2)判断是否位于绘制范围内,如是,则绘制 Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i < sFeatureCount; i++) { moFeature sFeature = _Features.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == true) { moGeometry sGeometry = sFeature.Geometry; moSymbol sSymbol = sFeature.Symbol; moMapDrawingTools.DrawGeometry(g, extent, mapScale, dpm, mpu, sGeometry, sSymbol); } } }
private void _AttributeFileds_FieldAppended(object sender, moField fieldAppended) { Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { moFeature sFeature = _Features.GetItem(i); if (fieldAppended.ValueType == moValueTypeConstant.dInt16) { Int16 sValue = 0; sFeature.Attributes.Append(sValue); } else if (fieldAppended.ValueType == moValueTypeConstant.dInt32) { Int32 sValue = 0; sFeature.Attributes.Append(sValue); } else if (fieldAppended.ValueType == moValueTypeConstant.dInt64) { Int64 sValue = 0; sFeature.Attributes.Append(sValue); } else if (fieldAppended.ValueType == moValueTypeConstant.dSingle) { float sValue = 0; sFeature.Attributes.Append(sValue); } else if (fieldAppended.ValueType == moValueTypeConstant.dDouble) { double sValue = 0; sFeature.Attributes.Append(sValue); } else if (fieldAppended.ValueType == moValueTypeConstant.dText) { string sValue = string.Empty; sFeature.Attributes.Append(sValue); } else { throw new Exception("Invalid field value type!"); } } }
//要素的符号是否可见 private bool IsFeatureSymbolVisible(moFeature feature) { moSymbol sSymbol = feature.Symbol; if (sSymbol.SymbolType == moSymbolTypeConstant.SimpleMarkerSymbol) { moSimpleMarkerSymbol sMarkerSymbol = (moSimpleMarkerSymbol)sSymbol; return(sMarkerSymbol.Visible); } else if (sSymbol.SymbolType == moSymbolTypeConstant.SimpleLineSymbol) { moSimpleLineSymbol sLineSymbol = (moSimpleLineSymbol)sSymbol; return(sLineSymbol.Visible); } else if (sSymbol.SymbolType == moSymbolTypeConstant.SimpleFillSymbol) { moSimpleFillSymbol sFillSymbol = (moSimpleFillSymbol)sSymbol; return(sFillSymbol.Visible); } else { throw new Exception("Invalid symbol type!"); } }
/// <summary> /// 删除指定元素 /// </summary> /// <param name="feature"></param> public void Remove(moFeature feature) { _Features.Remove(feature); }
public void Add(moFeature feature) { _Features.Add(feature); }
public void SetItem(Int32 index, moFeature feature) { _Features[index] = feature; }
/// <summary> /// 绘制所有注记 /// </summary> /// <param name="g"></param> /// <param name="extent"></param> /// <param name="mapScale"></param> /// <param name="dpm"></param> /// <param name="mpu"></param> /// <param name="placedLabelExtents"></param> internal void DrawLabels(Graphics g, moRectangle extent, double mapScale, double dpm, double mpu, List <RectangleF> placedLabelExtents) { if (_LabelRenderer == null) { return; } if (_LabelRenderer.LabelFeatures == false) { return; } Int32 sFieldIndex = _AttributeFields.FindField(_LabelRenderer.Field); if (sFieldIndex < 0) { return; } Int32 sFeatureCount = _Features.Count; for (Int32 i = 0; i <= sFeatureCount - 1; i++) { moFeature sFeature = _Features.GetItem(i); if (IsFeatureInExtent(sFeature, extent) == false) { //要素不位于显示范围内,不显示注记 continue; } if (sFeature.Symbol == null) { //要素没有配置符号,不显示注记 continue; } if (IsFeatureSymbolVisible(sFeature) == false) { //要素符号不可见,自然就不显示注记 continue; } string sLabelText = GetValueString(sFeature.Attributes.GetItem(sFieldIndex)); if (sLabelText == string.Empty) { //注记文本为空,不显示注记 continue; } //根据要素几何类型采用相应的配置方案 if (sFeature.ShapeType == moGeometryTypeConstant.Point) { //点要素,取点的右上为定位点,但要考虑点符号的大小 //(1)复制符号 moTextSymbol sTextSymbol; //最终绘制注记所采用的符号 sTextSymbol = _LabelRenderer.TextSymbol.Clone(); //复制符号 //(2)计算定位点并设置符号 PointF sSrcLabelPoint; //定位点的屏幕坐标 moPoint sPoint = (moPoint)sFeature.Geometry; PointF sSrcPoint = FromMapPoint(extent, mapScale, dpm, mpu, sPoint); //点要素的屏幕坐标 moSimpleMarkerSymbol sMarkerSymbol = (moSimpleMarkerSymbol)sFeature.Symbol; float sSymbolSize = (float)(sMarkerSymbol.Size / 1000 * dpm); //符号的屏幕尺寸 //右上方并设置符号 sSrcLabelPoint = new PointF(sSrcPoint.X + sSymbolSize / 2, sSrcPoint.Y - sSymbolSize / 2); sTextSymbol.Alignment = moTextSymbolAlignmentConstant.BottomLeft; //(3)计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, sTextSymbol); //(4)冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } else if (sFeature.ShapeType == moGeometryTypeConstant.MultiPolyline) { //线要素,为每个部分的中点配置一个注记 //(1)获取符号,线要素无需复制符号 moTextSymbol sTextSymbol = _LabelRenderer.TextSymbol; //(2)对每个部分进行配置 moMultiPolyline sMultiPolyline = (moMultiPolyline)sFeature.Geometry; Int32 sPartCount = sMultiPolyline.Parts.Count; for (Int32 j = 0; j <= sPartCount - 1; j++) { //获取注记 moPoint sMapLabelPoint = moMapTools.GetMidPointOfPolyline(sMultiPolyline.Parts.GetItem(j)); PointF sSrcLabelPoint = FromMapPoint(extent, mapScale, dpm, mpu, sMapLabelPoint); //计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, _LabelRenderer.TextSymbol); //冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } } else if (sFeature.ShapeType == moGeometryTypeConstant.MultiPolygon) { //面要素,为面积最大的外环及其内环所构成的多边形配置一个注记 //(1)获取符号,面要素无需复制符号 moTextSymbol sTextSymbol = _LabelRenderer.TextSymbol; //(2)获取注记点 moMultiPolygon sMultiPolygon = (moMultiPolygon)sFeature.Geometry; moPoint sMapLabelPoint = moMapTools.GetLabelPointOfMultiPolygon(sMultiPolygon); PointF sSrcLabelPoint = FromMapPoint(extent, mapScale, dpm, mpu, sMapLabelPoint); //(3)计算注记的屏幕范围矩形 RectangleF sLabelExtent = GetLabelExtent(g, dpm, sSrcLabelPoint, sLabelText, _LabelRenderer.TextSymbol); //(4)冲突检测 if (HasConflict(sLabelExtent, placedLabelExtents) == false) { //没有冲突,则绘制并将当前注记范围矩形加入placedLabelExtents moMapDrawingTools.DrawLabel(g, dpm, sLabelExtent.Location, sLabelText, sTextSymbol); placedLabelExtents.Add(sLabelExtent); } } else { throw new Exception("Invalid shape type!"); } } }
/// <summary> /// 新建一个要素框架 /// </summary> /// <returns></returns> public moFeature GetNewFeature() { moFeature sFeature = CreateNewFeature(); return(sFeature); }