コード例 #1
0
        private static IEnumerable <Object> getFeatureIdsFromIndexes(IFeatureLayer layer,
                                                                     IEnumerable <Int32> indexes)
        {
            foreach (Int32 index in indexes)
            {
                FeatureDataRow feature = layer.SelectedFeatures[index].Row as FeatureDataRow;
                Debug.Assert(feature != null);

                if (!feature.HasOid)
                {
                    throw new InvalidOperationException("Feature must have Object identifier " +
                                                        "in order to highlight.");
                }

                yield return(feature.GetOid());
            }
        }
コード例 #2
0
 private static String fdrLabel(FeatureDataRow fdr)
 {
     return(String.Format("Feature {0} with GeometryType {1}: {2}",
                          fdr.GetOid(), fdr.Geometry.GeometryTypeName, fdr.Geometry));
 }
コード例 #3
0
        protected override IEnumerable <TRenderObject> DoRenderFeature(IFeatureDataRecord inFeature,
                                                                       LabelStyle style,
                                                                       RenderState renderState,
                                                                       ILayer inLayer)
        {
            FeatureDataRow feature = inFeature as FeatureDataRow;
            LabelLayer     layer   = inLayer as LabelLayer;

            if (style == null)
            {
                throw new ArgumentNullException("style", "LabelStyle is a required argument " +
                                                "to properly render the label");
            }

            Label2D newLabel = null;

            LabelLayer.LabelTextFormatter formatter = null;
            LabelCollisionDetection2D     collisionDetector;

            if (layer != null)
            {
                if (!layer.RenderCache.TryGetValue(feature.GetOid(), out newLabel))
                {
                    formatter = layer.TextFormatter;
                }

                collisionDetector = layer.CollisionDetector;
                collisionDetector.TextRenderer = TextRenderer;
            }
            else
            {
                if (!textFormatters.TryGetValue(style, out formatter))
                {
                    // setup formatter based on style.LabelFormatExpression
                    formatter = delegate(FeatureDataRow row)
                    {
                        return(row.Evaluate(style.LabelExpression));
                    };

                    textFormatters.Add(style, formatter);
                }

                if (!collisionDetectors.TryGetValue(style, out collisionDetector))
                {
                    collisionDetector = new LabelCollisionDetection2D();
                    collisionDetector.TextRenderer = TextRenderer;
                    collisionDetectors.Add(style, collisionDetector);
                }
            }

            if (newLabel == null)
            {
                String labelText = formatter.Invoke(feature);
                if (feature.Geometry is ILineString)

                {
                    newLabel = new Label2D(labelText, new Point2D(), style);
                    calculateLabelOnLineString(feature.Geometry as ILineString, ref newLabel);
                }
                else
                {
                    ICoordinate p = feature.Geometry.Extents.Center;
                    Double      x = p[Ordinates.X], y = p[Ordinates.Y];


                    /* Moved to RenderLabel function
                     * if (style.HorizontalAlignment != HorizontalAlignment.Right || style.VerticalAlignment != VerticalAlignment.Bottom)
                     * {
                     * Size2D size = TextRenderer.MeasureString(labelText, style.Font);
                     * //Point2D pt = RenderTransform.TransformVector(Math.Ceiling(size.Width), Math.Ceiling(size.Height));
                     * size = new Size2D(size.Width / (Double)RenderTransform[0,0], size.Height / (Double)RenderTransform[1,1]);
                     * switch (style.HorizontalAlignment)
                     * {
                     *  case HorizontalAlignment.Center:
                     *      x -= (Int32)(size.Width / 2.0f);
                     *      break;
                     *  case HorizontalAlignment.Left:
                     *      x -= size.Width;
                     *      break;
                     *  default:
                     *      break;
                     * }
                     *
                     * switch (style.VerticalAlignment)
                     * {
                     *  case VerticalAlignment.Middle:
                     *      y += (Int32)(size.Height / 2.0f);
                     *      break;
                     *  case VerticalAlignment.Top:
                     *      y += size.Height;
                     *      break;
                     *  default:
                     *      break;
                     * }
                     * }
                     */

                    newLabel = new Label2D(labelText, new Point2D(x, y), style);
                }

                if (layer != null)
                {
                    layer.RenderCache.Add(feature.GetOid(), newLabel);
                }
            }

            // now find out if we even need to render this label...
            if (style.CollisionDetectionType != CollisionDetectionType.None)
            {
                if (style.CollisionDetectionType == CollisionDetectionType.Simple)
                {
                    if (collisionDetector.SimpleCollisionTest(newLabel))
                    {
                        // we are not going to render this label
                        if (layer != null)
                        {
                            layer.RenderCache.Remove(newLabel);
                        }

                        yield break;
                    }
                }
                else if (style.CollisionDetectionType == CollisionDetectionType.Advanced)
                {
                    if (collisionDetector.AdvancedCollisionTest(newLabel))
                    {
                        // we are not going to render this label
                        if (layer != null)
                        {
                            layer.RenderCache.Remove(newLabel);
                        }

                        yield break;
                    }
                }
            }

            foreach (TRenderObject ro in RenderLabel(newLabel))
            {
                yield return(ro);
            }
        }