Пример #1
0
        private static void RenderFeature(IViewport viewport, Canvas canvas, IFeature feature, IStyle style, SymbolCache symbolCache, bool rasterizing)
        {
            if (style is LabelStyle)
            {
                var labelStyle = (LabelStyle)style;
                canvas.Children.Add(LabelRenderer.RenderLabel(feature.Geometry.GetBoundingBox().GetCentroid(),
                                                              labelStyle, viewport, labelStyle.GetLabelText(feature)));
            }
            else
            {
                Shape  renderedGeometry;
                object cachedObject;
                if (feature.RenderedGeometry.TryGetValue(style, out cachedObject))
                {
                    renderedGeometry = (Shape)cachedObject; // Has to be Shape
                    PositionGeometry(renderedGeometry, viewport, style, feature);
                }
                else
                {
                    renderedGeometry = RenderGeometry(viewport, style, feature, symbolCache);
                    if (!rasterizing)
                    {
                        feature.RenderedGeometry[style] = renderedGeometry;
                    }
                }

                if (!canvas.Children.Contains(renderedGeometry))
                {
                    // Adding twice can happen when a single feature has two identical styles
                    canvas.Children.Add(renderedGeometry);
                }
            }
        }
Пример #2
0
        private static void RenderFeature(IReadOnlyViewport viewport, Canvas canvas, IFeature feature, IStyle style, SymbolCache symbolCache, bool rasterizing)
        {
            //// Check, if we have a special renderer for this style
            //if (StyleRenderers.ContainsKey(style.GetType()))
            //{
            //    // We have a special renderer, so try, if it could draw this
            //    var result = ((IXamlStyleRenderer)StyleRenderers[style.GetType()]).Draw(canvas, viewport, layer, feature, style, symbolCache);
            //    // Was it drawn?
            //    if (result)
            //        // Yes, special style renderer drawn correct
            //        return;
            //}
            //// No special style renderer handled this up to now, than try standard renderers
            if (style is LabelStyle)
            {
                var labelStyle = (LabelStyle)style;
                var labelText  = labelStyle.GetLabelText(feature);
                if (string.IsNullOrEmpty(labelText))
                {
                    return;
                }
                canvas.Children.Add(LabelRenderer.RenderLabel(feature.Geometry.BoundingBox.Centroid,
                                                              labelStyle, viewport, labelText));
            }
            else
            {
                Shape renderedGeometry;
                if (feature.RenderedGeometry.TryGetValue(style, out var cachedObject))
                {
                    renderedGeometry = (Shape)cachedObject; // Has to be Shape
                    PositionGeometry(renderedGeometry, viewport, style, feature);
                }
                else
                {
                    renderedGeometry = RenderGeometry(viewport, style, feature, symbolCache);
                    if (!rasterizing)
                    {
                        feature.RenderedGeometry[style] = renderedGeometry;
                    }
                }

                if (!canvas.Children.Contains(renderedGeometry))
                {
                    // Adding twice can happen when a single feature has two identical styles
                    canvas.Children.Add(renderedGeometry);
                }
            }
        }