public static void ChangeDefaultSymbolFillColor(this GraphicsLayer layer, Brush fillBrush)
        {
            Symbol symbol = layer.GetDefaultSymbol();

            #region FSS.SFS
            if (symbol is FSS.SimpleFillSymbol && fillBrush is SolidColorBrush)
            {
                ((FSS.SimpleFillSymbol)symbol).Color = (fillBrush as SolidColorBrush).Color;
            }
            #endregion
            #region FSS.PFS
            else if (symbol is FSS.PictureFillSymbol)
            {
                FSS.PictureFillSymbol pfs = symbol as FSS.PictureFillSymbol;
                pfs.Color = fillBrush;
            }
            #endregion
            #region Default Fill Symbol
            else if (symbol is FillSymbol)
            {
                (symbol as FillSymbol).Fill = fillBrush;
            }
            #endregion
            #region Marker Symbols
            else
            {
                #region Mapping Core Marker
                ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol markerSymbol = symbol as ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol;
                if (markerSymbol != null)
                {
                    markerSymbol.Color = fillBrush;
                }
                #endregion
                else
                {
                    #region Client SMS
                    ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol simpleMarkerSymbol = symbol as ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol;
                    if (simpleMarkerSymbol != null)
                    {
                        simpleMarkerSymbol.Color = fillBrush;
                    }
                    #endregion
                    #region FSS.SMS
                    else
                    {
                        FSS.SimpleMarkerSymbol sms = symbol as FSS.SimpleMarkerSymbol;
                        if (sms != null)
                        {
                            sms.Color = fillBrush;
                        }
                    }
                    #endregion
                }
            }
            #endregion
        }
Beispiel #2
0
        void FillColorSelector_ColorPicked(object sender, ColorChosenEventArgs e)
        {
            FillSymbol fillSymbol = Symbol as FillSymbol;

            if (fillSymbol != null)
            {
                #region FSS.SFS
                if (fillSymbol is FSS.SimpleFillSymbol)
                {
                    ((FSS.SimpleFillSymbol)fillSymbol).Color = e.Color;
                    onCurrentSymbolChanged();
                }
                #endregion
                #region FSS.PFS
                else if (fillSymbol is FSS.PictureFillSymbol)
                {
                    FSS.PictureFillSymbol pfs   = fillSymbol as FSS.PictureFillSymbol;
                    SolidColorBrush       brush = pfs.Color as SolidColorBrush;
                    if (brush != null)
                    {
                        brush.Color = e.Color;
                        onCurrentSymbolChanged();
                    }
                }
                #endregion
                #region Default
                else
                {
                    SolidColorBrush brush = fillSymbol.Fill as SolidColorBrush;
                    if (brush != null)
                    {
                        brush.Color = e.Color;
                        onCurrentSymbolChanged();
                    }
                }
                #endregion
            }
            else
            {
                #region Mapping Core Marker
                ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol markerSymbol = Symbol as ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol;
                if (markerSymbol != null)
                {
                    SolidColorBrush sb = markerSymbol.Color as SolidColorBrush;
                    if (sb != null)
                    {
                        sb.Color = e.Color;
                        onCurrentSymbolChanged();
                    }
                }
                #endregion
                else
                {
                    #region Client SMS
                    ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol simpleMarkerSymbol = Symbol as ESRI.ArcGIS.Client.Symbols.SimpleMarkerSymbol;
                    if (simpleMarkerSymbol != null)
                    {
                        SolidColorBrush sb = simpleMarkerSymbol.Color as SolidColorBrush;
                        if (sb != null)
                        {
                            sb.Color = e.Color;
                            onCurrentSymbolChanged();
                        }
                    }
                    #endregion
                    #region FSS.SMS
                    else
                    {
                        FSS.SimpleMarkerSymbol sms = Symbol as FSS.SimpleMarkerSymbol;
                        if (sms != null)
                        {
                            SolidColorBrush sb = sms.Color as SolidColorBrush;
                            if (sb != null)
                            {
                                sb.Color = e.Color;
                                onCurrentSymbolChanged();
                            }
                        }
                    }
                    #endregion
                }
            }
        }
        private static void SetImagePropertiesFromJson(DependencyObject o, DependencyPropertyChangedEventArgs args)
        {
            Symbol symbol = o as Symbol;
            string json   = GetJson(symbol);

            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            SolidColorBrush selectionColor = new SolidColorBrush(Colors.Cyan);

            FS.PictureFillSymbol pfs = o as FS.PictureFillSymbol;
            if (pfs != null)
            {
                FS.PictureFillSymbol pfsN = Symbol.FromJson(json) as FS.PictureFillSymbol;
                if (pfsN != null)
                {
                    #region Copy Properties
                    pfs.Source = pfsN.Source;
                    //internal properties - for documentation
                    //pfs.Angle = pfsN.Angle;
                    //pfs.XOffset = pfsN.XOffset;
                    //pfs.YOffset = pfsN.YOffset;
                    //pfs.XScale = pfsN.XScale;
                    //pfs.YScale = pfsN.YScale;
                    pfs.BorderBrush     = pfsN.BorderBrush;
                    pfs.BorderThickness = pfsN.BorderThickness;
                    pfs.BorderStyle     = pfsN.BorderStyle;
                    pfs.Width           = pfsN.Width;
                    pfs.Height          = pfsN.Height;
                    pfs.Color           = pfsN.Color;
                    pfs.Opacity         = 0.75;
                    pfs.SelectionColor  = selectionColor;
                    #endregion
                }
                return;
            }
            FS.PictureMarkerSymbol pms = o as FS.PictureMarkerSymbol;
            if (pms != null)
            {
                FS.PictureMarkerSymbol pmsN = Symbol.FromJson(json) as FS.PictureMarkerSymbol;
                if (pmsN != null)
                {
                    #region Copy Properties
                    pms.Source            = pmsN.Source;
                    pms.Width             = pmsN.Width;
                    pms.Height            = pmsN.Height;
                    pms.XOffsetFromCenter = pmsN.XOffsetFromCenter;
                    pms.YOffsetFromCenter = pmsN.YOffsetFromCenter;
                    pms.Color             = pmsN.Color;
                    pms.Opacity           = pmsN.Opacity;
                    pms.Angle             = pmsN.Angle;
                    pms.SelectionColor    = selectionColor;
                    #endregion

                    Dictionary <string, object> jsonObject = new ESRI.ArcGIS.Client.Utils.JavaScriptSerializer().DeserializeObject(json) as Dictionary <string, object>;
                    if (jsonObject != null)
                    {
                        if (jsonObject.ContainsKey("imageData"))
                        {
                            SetImageData(pms, jsonObject["imageData"] as string);
                        }
                        else if (jsonObject.ContainsKey("url"))
                        {
                            SetImageUrl(pms, jsonObject["url"] as string);
                        }
                    }
                }
                return;
            }
            FS.SimpleFillSymbol sfs = o as FS.SimpleFillSymbol;
            if (sfs != null)
            {
                FS.SimpleFillSymbol sfsN = Symbol.FromJson(json) as FS.SimpleFillSymbol;
                if (sfsN != null)
                {
                    #region Copy Properties
                    sfs.Fill            = sfsN.Fill;
                    sfs.Style           = sfsN.Style;
                    sfs.Color           = sfsN.Color;
                    sfs.BorderBrush     = sfsN.BorderBrush;
                    sfs.BorderThickness = sfsN.BorderThickness;
                    sfs.BorderStyle     = sfsN.BorderStyle;
                    sfs.SelectionColor  = selectionColor;
                    #endregion
                }
                return;
            }
            FS.SimpleLineSymbol sls = o as FS.SimpleLineSymbol;
            if (sls != null)
            {
                FS.SimpleLineSymbol slsN = Symbol.FromJson(json) as FS.SimpleLineSymbol;
                if (slsN != null)
                {
                    #region CopyProperties
                    sls.Style          = slsN.Style;
                    sls.Color          = slsN.Color;
                    sls.Width          = slsN.Width;
                    sls.SelectionColor = selectionColor;
                    #endregion
                }
                return;
            }
            FS.SimpleMarkerSymbol sms = o as FS.SimpleMarkerSymbol;
            if (sms != null)
            {
                FS.SimpleMarkerSymbol smsN = Symbol.FromJson(json) as FS.SimpleMarkerSymbol;
                if (smsN != null)
                {
                    #region Copy properties
                    sms.Style             = smsN.Style;
                    sms.Color             = smsN.Color;
                    sms.Size              = smsN.Size;
                    sms.XOffsetFromCenter = smsN.XOffsetFromCenter;
                    sms.YOffsetFromCenter = smsN.YOffsetFromCenter;
                    sms.Angle             = smsN.Angle;
                    sms.OutlineColor      = smsN.OutlineColor;
                    sms.OutlineThickness  = smsN.OutlineThickness;
                    sms.OutlineStyle      = smsN.OutlineStyle;
                    sms.SelectionColor    = selectionColor;
                    #endregion
                }
                return;
            }
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is SymbolTemplate))
            {
                return(value);
            }

            SymbolTemplate symbolTemplate = value as SymbolTemplate;

            if (symbolTemplate.Symbol == null)
            {
                return(null);
            }
            Symbol convertedSymbol = symbolTemplate.Symbol;

            if (symbolTemplate.FeatureTemplate == null)
            {
                return(convertedSymbol);
            }

            FeatureTemplate featureTemplate = symbolTemplate.FeatureTemplate;

            if (symbolTemplate.Symbol is FSSymbols.SimpleFillSymbol ||
                symbolTemplate.Symbol is FSSymbols.PictureFillSymbol ||
                symbolTemplate.Symbol is FSSymbols.SimpleLineSymbol)
            {
                switch (featureTemplate.DrawingTool)
                {
                case FeatureEditTool.Polygon:
                    convertedSymbol = new PolygonSymbol();
                    break;

                case FeatureEditTool.AutoCompletePolygon:
                    convertedSymbol = new AutoCompletePolygonSymbol();
                    break;

                case FeatureEditTool.Circle:
                    convertedSymbol = new CircleSymbol();
                    break;

                case FeatureEditTool.Ellipse:
                    convertedSymbol = new EllipseSymbol();
                    break;

                case FeatureEditTool.Rectangle:
                    convertedSymbol = new RectangleSymbol();
                    break;

                case FeatureEditTool.Freehand:
                    if (symbolTemplate.Symbol is FSSymbols.SimpleLineSymbol)
                    {
                        convertedSymbol = new FreehandLineSymbol();
                    }
                    else
                    {
                        convertedSymbol = new FreehandPolygonSymbol();
                    }
                    break;

                case FeatureEditTool.Line:
                    convertedSymbol = new PolylineSymbol();
                    break;
                }

                if (convertedSymbol is ShapeMarkerSymbol)
                {
                    ShapeMarkerSymbol shapeMarkerSymbol = convertedSymbol as ShapeMarkerSymbol;
                    FillMarkerSymbol  fillMarkerSymbol  = convertedSymbol as FillMarkerSymbol;
                    if (symbolTemplate.Symbol is FSSymbols.SimpleFillSymbol)
                    {
                        ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleFillSymbol simpleFillSymbol =
                            symbolTemplate.Symbol as FSSymbols.SimpleFillSymbol;
                        fillMarkerSymbol.Stroke          = simpleFillSymbol.BorderBrush;
                        fillMarkerSymbol.Fill            = simpleFillSymbol.Fill;
                        fillMarkerSymbol.StrokeStyle     = simpleFillSymbol.BorderStyle;
                        fillMarkerSymbol.StrokeThickness = simpleFillSymbol.BorderThickness;
                        shapeMarkerSymbol.SelectionColor = simpleFillSymbol.SelectionColor;
                    }
                    else if (symbolTemplate.Symbol is FSSymbols.PictureFillSymbol)
                    {
                        ESRI.ArcGIS.Client.FeatureService.Symbols.PictureFillSymbol pictureFillSymbol =
                            symbolTemplate.Symbol as FSSymbols.PictureFillSymbol;
                        fillMarkerSymbol.Stroke          = pictureFillSymbol.BorderBrush;
                        fillMarkerSymbol.StrokeStyle     = pictureFillSymbol.BorderStyle;
                        fillMarkerSymbol.StrokeThickness = pictureFillSymbol.BorderThickness;
                        shapeMarkerSymbol.SelectionColor = pictureFillSymbol.SelectionColor;

                        // Create new image brush for fill in order to set stretch to Uniform
                        ImageBrush brush = new ImageBrush()
                        {
                            Stretch     = Stretch.Uniform,
                            ImageSource = pictureFillSymbol.Source
                        };
                        fillMarkerSymbol.Fill = brush;
                    }
                    else if (symbolTemplate.Symbol is FSSymbols.SimpleLineSymbol)
                    {
                        ESRI.ArcGIS.Client.FeatureService.Symbols.SimpleLineSymbol simpleLineSymbol =
                            symbolTemplate.Symbol as FSSymbols.SimpleLineSymbol;
                        shapeMarkerSymbol.Stroke          = simpleLineSymbol.Color;
                        shapeMarkerSymbol.StrokeStyle     = simpleLineSymbol.Style;
                        shapeMarkerSymbol.StrokeThickness = simpleLineSymbol.Width;
                        shapeMarkerSymbol.SelectionColor  = simpleLineSymbol.SelectionColor;

                        if (fillMarkerSymbol != null)
                        {
                            fillMarkerSymbol.Fill = new SolidColorBrush(Colors.Transparent);
                        }
                    }
                }
            }

            return(convertedSymbol);
        }