Exemplo n.º 1
0
 private void RenderFeature(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IStyle style, IFeature feature, float layerOpacity)
 {
     // Check, if we have a special renderer for this style
     if (StyleRenderers.ContainsKey(style.GetType()))
     {
         // Save canvas
         canvas.Save();
         // We have a special renderer, so try, if it could draw this
         var result = ((ISkiaStyleRenderer)StyleRenderers[style.GetType()]).Draw(canvas, viewport, layer, feature, style, _symbolCache);
         // Restore old canvas
         canvas.Restore();
         // 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 (feature.Geometry is Point)
     {
         PointRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, _symbolCache, layerOpacity * style.Opacity);
     }
     else if (feature.Geometry is MultiPoint)
     {
         MultiPointRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, _symbolCache, layerOpacity * style.Opacity);
     }
     else if (feature.Geometry is LineString)
     {
         LineStringRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, layerOpacity * style.Opacity);
     }
     else if (feature.Geometry is MultiLineString)
     {
         MultiLineStringRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, layerOpacity * style.Opacity);
     }
     else if (feature.Geometry is Polygon)
     {
         PolygonRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, layerOpacity * style.Opacity, _symbolCache);
     }
     else if (feature.Geometry is MultiPolygon)
     {
         MultiPolygonRenderer.Draw(canvas, viewport, style, feature, feature.Geometry, layerOpacity * style.Opacity, _symbolCache);
     }
     else if (feature.Geometry is IRaster)
     {
         RasterRenderer.Draw(canvas, viewport, style, feature, layerOpacity * style.Opacity, _tileCache, _currentIteration);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the style based on a numeric DataColumn, where style
        /// properties are linearly interpolated between max and min values.
        /// </summary>
        /// <param name="row">Feature</param>
        /// <returns><see cref="SharpMap.Styles.IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns>
        public virtual IStyle GetStyle(FeatureDataRow row)
        {
            double attr = 0;

            try
            {
                attr = GetAttributeValue(row);
            }
            catch
            {
                throw new ApplicationException(
                          "Invalid Attribute type in Gradient Theme - Couldn't parse attribute (must be numerical)");
            }
            if (_minStyle.GetType() != _maxStyle.GetType())
            {
                throw new ArgumentException("MinStyle and MaxStyle must be of the same type");
            }
            switch (MinStyle.GetType().FullName)
            {
            case "SharpMap.Styles.VectorStyle":
                return(CalculateVectorStyle(MinStyle as VectorStyle, MaxStyle as VectorStyle, attr));

            case "SharpMap.Styles.LabelStyle":
                return(CalculateLabelStyle(MinStyle as LabelStyle, MaxStyle as LabelStyle, attr));

            default:
                throw new ArgumentException(
                          "Only SharpMap.Styles.VectorStyle and SharpMap.Styles.LabelStyle are supported for the gradient theme");
            }
        }
Exemplo n.º 3
0
        // todo:
        // try to remove the feature argument. LabelStyle should already contain the feature specific text
        // The visible feature iterator should create this LabelStyle
        public static void Draw(SKCanvas canvas, IViewport viewport, IStyle style, IFeature feature, 
            IGeometry geometry, IDictionary<int, SKBitmapInfo> symbolBitmapCache)
        {
            var point = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle)              // case 1) LabelStyle
            {
                LabelRenderer.Draw(canvas, (LabelStyle) style, feature, (float) destination.X, (float) destination.Y);
            }
            else if (style is SymbolStyle)
            {
                var symbolStyle = (SymbolStyle)style;

                if ( symbolStyle.BitmapId >= 0)   // case 2) Bitmap Style
                {
                    DrawPointWithBitmapStyle(canvas, symbolStyle, destination, symbolBitmapCache);
                }
                else                              // case 3) SymbolStyle without bitmap
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)        // case 4) VectorStyle
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle) style, destination);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Exemplo n.º 4
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                IGeometry geometry, SymbolCache symbolCache, float opacity)
        {
            var point       = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is LabelStyle labelStyle)    // case 1) LabelStyle
            {
                LabelRenderer.Draw(canvas, labelStyle, feature, (float)destination.X, (float)destination.Y,
                                   opacity);
            }
            else if (style is SymbolStyle)
            {
                var symbolStyle = (SymbolStyle)style;

                if (symbolStyle.BitmapId >= 0)    // case 2) Bitmap Style
                {
                    DrawPointWithBitmapStyle(canvas, symbolStyle, destination, symbolCache, opacity);
                }
                else                              // case 3) SymbolStyle without bitmap
                {
                    DrawPointWithSymbolStyle(canvas, symbolStyle, destination, opacity, symbolStyle.SymbolType);
                }
            }
            else if (style is VectorStyle)        // case 4) VectorStyle
            {
                DrawPointWithVectorStyle(canvas, (VectorStyle)style, destination, opacity);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the style based on a numeric DataColumn, where style
        /// properties are linearly interpolated between max and min values.
        /// </summary>
        /// <param name="row">Feature</param>
        /// <returns><see cref="Mapsui.Styles.IStyle">Style</see> calculated by a linear interpolation between the min/max styles</returns>
        public IStyle GetStyle(IFeature row)
        {
            double attr;

            try { attr = Convert.ToDouble(row[columnName.ToUpper()]); }
            catch { throw new Exception("Invalid Attribute type in Gradient Theme - Couldn't parse attribute (must be numerical)"); }
            if (minStyle.GetType() != maxStyle.GetType())
            {
                throw new ArgumentException("MinStyle and MaxStyle must be of the same type");
            }


            var style = (IStyle)Activator.CreateInstance(MinStyle.GetType());

            if (MinStyle is LabelStyle && MaxStyle is LabelStyle)
            {
                CalculateLabelStyle(style as LabelStyle, MinStyle as LabelStyle, MaxStyle as LabelStyle, attr);
            }
            if (MinStyle is VectorStyle && MaxStyle is VectorStyle)
            {
                CalculateVectorStyle(style as VectorStyle, MinStyle as VectorStyle, MaxStyle as VectorStyle, attr);
            }
            if (MinStyle is SymbolStyle && MaxStyle is SymbolStyle)
            {
                CalculateSymbolStyle(style as SymbolStyle, MinStyle as SymbolStyle, MaxStyle as SymbolStyle, attr);
            }
            return(style);
        }
Exemplo n.º 6
0
 private void RenderFeature(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IStyle style, IFeature feature, float layerOpacity, long iteration)
 {
     // Check, if we have a special renderer for this style
     if (StyleRenderers.ContainsKey(style.GetType()))
     {
         // Save canvas
         canvas.Save();
         // We have a special renderer, so try, if it could draw this
         var styleRenderer = (ISkiaStyleRenderer)StyleRenderers[style.GetType()];
         var result        = styleRenderer.Draw(canvas, viewport, layer, feature, style, _symbolCache, iteration);
         // Restore old canvas
         canvas.Restore();
         // Was it drawn?
         if (result)
         {
             // Yes, special style renderer drawn correct
             return;
         }
     }
 }
Exemplo n.º 7
0
 private bool StyleNameExists(Design design, IStyle style, string newName)
 {
     if (design == null)
     {
         throw new ArgumentNullException("design");
     }
     if (style == null)
     {
         throw new ArgumentNullException("style");
     }
     return(design.FindStyleByName(newName, style.GetType()) != null);
 }
Exemplo n.º 8
0
        private void RenderFeature(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IStyle style, IFeature feature, float layerOpacity)
        {
            // Check, if we have a special renderer for this style
            if (StyleRenderers.ContainsKey(style.GetType()))
            {
                // Save canvas
                canvas.Save();
                // We have a special renderer, so try, if it could draw this
                var styleRenderer = (ISkiaStyleRenderer)StyleRenderers[style.GetType()];
                var result        = styleRenderer.Draw(canvas, viewport, layer, feature, style, _symbolCache);
                // Restore old canvas
                canvas.Restore();
                // 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 (feature is GeometryFeature geometryFeatureNts)
            {
                GeometryRenderer.Draw(canvas, viewport, style, layerOpacity, geometryFeatureNts, _symbolCache);
            }
            if (feature is PointFeature pointFeature)
            {
                PointRenderer.Draw(canvas, viewport, style, pointFeature, pointFeature.Point.X, pointFeature.Point.Y, _symbolCache, layerOpacity * style.Opacity);
            }
            else if (feature is RectFeature rectFeature)
            {
                RectRenderer.Draw(canvas, viewport, style, rectFeature, layerOpacity * style.Opacity);
            }
            else if (feature is RasterFeature rasterFeature)
            {
                RasterRenderer.Draw(canvas, viewport, style, rasterFeature, rasterFeature.Raster, layerOpacity * style.Opacity, _tileCache, _currentIteration);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 得到属性编辑面板
        /// </summary>
        /// <param name="tool"></param>
        /// <param name="orientation"></param>
        /// <returns></returns>
        public static Panel GetEditorPanel(this IStyle tool, Orientation orientation = Orientation.Vertical)
        {
            StackPanel panel = new StackPanel();

            panel.Orientation = orientation;
            panel.DataContext = tool;

            var propertInfo = tool.GetType().GetProperties();

            foreach (var item in propertInfo)
            {
                var control = GetEditorControl(tool, item);

                if (control != null)
                {
                    panel.Children.Add(control);
                }
            }

            return(panel);
        }
Exemplo n.º 10
0
        public static void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IStyle style, IFeature feature,
                                IGeometry geometry, SymbolCache symbolCache, float opacity)
        {
            var point       = geometry as Point;
            var destination = viewport.WorldToScreen(point);

            if (style is CalloutStyle calloutStyle)
            {
                CalloutStyleRenderer.Draw(canvas, viewport, symbolCache, opacity, destination, calloutStyle);
            }
            else if (style is LabelStyle labelStyle)
            {
                LabelRenderer.Draw(canvas, labelStyle, feature, destination, opacity);
            }
            else if (style is SymbolStyle symbolStyle)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // todo: Remove this call. ImageStyle should be used instead of SymbolStyle with BitmapId
                    ImageStyleRenderer.Draw(canvas, symbolStyle, destination, symbolCache, opacity, viewport.Rotation);
                }
                else
                {
                    SymbolStyleRenderer.Draw(canvas, symbolStyle, destination, opacity, symbolStyle.SymbolType, viewport.Rotation);
                }
            }
            else if (style is ImageStyle imageStyle)
            {
                ImageStyleRenderer.Draw(canvas, imageStyle, destination, symbolCache, opacity, viewport.Rotation);
            }
            else if (style is VectorStyle vectorStyle)
            {
                // Use the SymbolStyleRenderer and specify Ellipse
                SymbolStyleRenderer.Draw(canvas, vectorStyle, destination, opacity, SymbolType.Ellipse);
            }
            else
            {
                throw new Exception($"Style of type '{style.GetType()}' is not supported for points");
            }
        }
Exemplo n.º 11
0
 private static void Validate(Map map, IGraphics g, IGeometry geom, IStyle style)
 {
     if (map == null)
     {
         throw new ArgumentNullException("map");
     }
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (geom == null)
     {
         throw new ArgumentNullException("geom");
     }
     if (style == null)
     {
         throw new ArgumentNullException("style");
     }
     if (!(style is VectorStyle))
     {
         string s = String.Format("VectorStyle expected but was {0}", style.GetType().Name);
         throw new ArgumentException(s);
     }
 }
Exemplo n.º 12
0
        public void AddStyle(IStyle style)
        {
            var attribute = style.GetType().GetCustomAttribute <StyleAttribute>();

            this.managers.TryAdd(attribute.Name, () => style);
        }
Exemplo n.º 13
0
 private static void Validate(Map map, IGraphics g, IGeometry geom, IStyle style)
 {
     if (map == null)
         throw new ArgumentNullException("map");
     if (g == null)
         throw new ArgumentNullException("g");
     if (geom == null)
         throw new ArgumentNullException("geom");
     if (style == null)
         throw new ArgumentNullException("style");
     if (!(style is VectorStyle))
     {
         string s = String.Format("VectorStyle expected but was {0}", style.GetType().Name);
         throw new ArgumentException(s);
     }
 }