void bindUIToSymbol() { if (SymbolPicker != null) { SymbolPicker.Symbol = Symbol; } ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol markerSymbol = Symbol as ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol; FSS.SimpleMarkerSymbol fsSimpleMarkerSymbol = Symbol as FSS.SimpleMarkerSymbol; FSS.SimpleLineSymbol fsSimpleLineSymbol = Symbol as FSS.SimpleLineSymbol; FSS.SimpleFillSymbol fsSimpleFillSymbol = Symbol as FSS.SimpleFillSymbol; SimpleMarkerSymbol simpleMarkerSymbol = Symbol as SimpleMarkerSymbol; FillSymbol fillSymbol = Symbol as FillSymbol; LineSymbol lineSymbol = Symbol as LineSymbol; if (Symbol != null) { #region Size if (PointThickness != null) { // we support Size property on SimpleMarkerSymbol and ImageFillSymbol ImageFillSymbol imagefillSymbol = Symbol as ImageFillSymbol; if (imagefillSymbol != null) { PointThickness.IsEnabled = true; PointThickness.TargetThickness = new Thickness(imagefillSymbol.Size); } else { if (markerSymbol != null) { PointThickness.IsEnabled = true; PointThickness.TargetThickness = new Thickness(markerSymbol.Size); } else { if (simpleMarkerSymbol != null) { PointThickness.IsEnabled = true; PointThickness.TargetThickness = new Thickness(simpleMarkerSymbol.Size); } else if (fsSimpleMarkerSymbol != null) { PointThickness.IsEnabled = true; PointThickness.TargetThickness = new Thickness(fsSimpleMarkerSymbol.Size); } else { PointThickness.IsEnabled = false; } } } } #endregion #region Border Thickness if (SymbolBorderThickness != null) { if (fillSymbol != null) { SymbolBorderThickness.IsEnabled = true; SymbolBorderThickness.TargetThickness = new Thickness(fillSymbol.BorderThickness); } else if (lineSymbol != null) { SymbolBorderThickness.IsEnabled = true; SymbolBorderThickness.TargetThickness = new Thickness(lineSymbol.Width); } else if (fsSimpleMarkerSymbol != null) { if (fsSimpleMarkerSymbol.OutlineColor != null) { SymbolBorderThickness.IsEnabled = true; SymbolBorderThickness.TargetThickness = new Thickness( double.IsNaN(fsSimpleMarkerSymbol.OutlineThickness) ? 0 : fsSimpleMarkerSymbol.OutlineThickness); } else { SymbolBorderThickness.IsEnabled = false; } } else { SymbolBorderThickness.IsEnabled = false; } } #endregion #region BorderColor if (OutlineColorSelector != null) { if (fsSimpleMarkerSymbol != null) { SolidColorBrush sb = fsSimpleMarkerSymbol.OutlineColor as SolidColorBrush; if (sb != null) { OutlineColorSelector.IsEnabled = true; OutlineColorSelector.ColorBrush = sb; } else { OutlineColorSelector.IsEnabled = false; } } else if (fillSymbol != null) { SolidColorBrush sb = fillSymbol.BorderBrush as SolidColorBrush; if (sb != null) { OutlineColorSelector.IsEnabled = true; OutlineColorSelector.ColorBrush = sb; } else { OutlineColorSelector.IsEnabled = false; } } else if (lineSymbol != null) { SolidColorBrush sb = lineSymbol.Color as SolidColorBrush; if (sb != null) { OutlineColorSelector.IsEnabled = true; OutlineColorSelector.ColorBrush = sb; } else { OutlineColorSelector.IsEnabled = false; } } else { OutlineColorSelector.IsEnabled = false; } } #endregion #region Fill Color if (FillColorSelector != null) { if (fillSymbol != null) { SolidColorBrush sb = fillSymbol.Fill as SolidColorBrush; if (sb != null) { FillColorSelector.IsEnabled = true; FillColorSelector.ColorBrush = sb; } else { FillColorSelector.IsEnabled = false; } } else { if (markerSymbol != null) { SolidColorBrush sb = markerSymbol.Color as SolidColorBrush; if (sb != null) { FillColorSelector.IsEnabled = true; FillColorSelector.ColorBrush = sb; } else { FillColorSelector.IsEnabled = false; } } else if (fsSimpleMarkerSymbol != null) { SolidColorBrush sb = fsSimpleMarkerSymbol.Color as SolidColorBrush; if (sb != null) { FillColorSelector.IsEnabled = true; FillColorSelector.ColorBrush = sb; } else { FillColorSelector.IsEnabled = false; } } else if (simpleMarkerSymbol != null) { SolidColorBrush sb = simpleMarkerSymbol.Color as SolidColorBrush; if (sb != null) { FillColorSelector.IsEnabled = true; FillColorSelector.ColorBrush = sb; } else { FillColorSelector.IsEnabled = false; } } else { FillColorSelector.IsEnabled = false; } } } #endregion #region Opacity if (OpacitySlider != null) { if (markerSymbol != null) { OpacitySlider.Value = markerSymbol.Opacity; } else if (simpleMarkerSymbol != null) { if (simpleMarkerSymbol.Color != null) { OpacitySlider.Value = simpleMarkerSymbol.Color.GetOpacity(); } } else if (fsSimpleMarkerSymbol != null) { if (fsSimpleMarkerSymbol.Color != null) { OpacitySlider.Value = fsSimpleMarkerSymbol.Color.GetOpacity(); } } else if (fsSimpleLineSymbol != null) { if (fsSimpleLineSymbol.Color != null) { OpacitySlider.Value = fsSimpleLineSymbol.Color.GetOpacity(); } } else if (fsSimpleFillSymbol != null) { if (fsSimpleFillSymbol.Color != null) { OpacitySlider.Value = fsSimpleFillSymbol.Color.A / 255d; } } else if (fillSymbol != null) { if (fillSymbol.Fill != null) { OpacitySlider.Value = fillSymbol.Fill.GetOpacity(); } } else if (lineSymbol != null) { if (lineSymbol.Color != null) { OpacitySlider.Value = lineSymbol.Color.GetOpacity(); } } } #endregion #region Border Opacity if (BorderOpacitySlider != null) { if (fillSymbol != null) { if (fillSymbol.BorderBrush != null) { BorderOpacitySlider.Visibility = System.Windows.Visibility.Visible; BorderOpacitySlider.Value = fillSymbol.BorderBrush.GetOpacity(); } else { BorderOpacitySlider.Visibility = System.Windows.Visibility.Collapsed; } } else if (fsSimpleMarkerSymbol != null && fsSimpleMarkerSymbol.OutlineColor != null) { BorderOpacitySlider.Visibility = System.Windows.Visibility.Visible; BorderOpacitySlider.Value = fsSimpleMarkerSymbol.OutlineColor.GetOpacity(); } else { BorderOpacitySlider.Visibility = System.Windows.Visibility.Collapsed; } } #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; } }
void OpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (Symbol is ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol) { ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol symbol = (ESRI.ArcGIS.Mapping.Core.Symbols.MarkerSymbol)Symbol; symbol.Opacity = e.NewValue; onCurrentSymbolChanged(); } else if (Symbol is FSS.SimpleMarkerSymbol) { FSS.SimpleMarkerSymbol symbol = (FSS.SimpleMarkerSymbol)Symbol; if (symbol.Color != null) { symbol.Color.SetOpacity(e.NewValue); onCurrentSymbolChanged(); } } else if (Symbol is FSS.SimpleLineSymbol) { FSS.SimpleLineSymbol symbol = (FSS.SimpleLineSymbol)Symbol; if (symbol.Color != null) { symbol.Color.SetOpacity(e.NewValue); onCurrentSymbolChanged(); } } else if (Symbol is FSS.SimpleFillSymbol) { FSS.SimpleFillSymbol symbol = (FSS.SimpleFillSymbol)Symbol; if (symbol.Color != null) { symbol.Color = Color.FromArgb(Convert.ToByte(255 * e.NewValue), symbol.Color.R, symbol.Color.G, symbol.Color.B); onCurrentSymbolChanged(); } } else if (Symbol is SimpleMarkerSymbol) { SimpleMarkerSymbol symbol = (SimpleMarkerSymbol)Symbol; if (symbol.Color != null) { symbol.Color.SetOpacity(e.NewValue); onCurrentSymbolChanged(); } } else if (Symbol is LineSymbol) { LineSymbol symbol = (LineSymbol)Symbol; if (symbol.Color != null) { symbol.Color.SetOpacity(e.NewValue); onCurrentSymbolChanged(); } } else if (Symbol is FillSymbol) { FillSymbol symbol = (FillSymbol)Symbol; if (symbol.Fill != null) { symbol.Fill.SetOpacity(e.NewValue); onCurrentSymbolChanged(); } } }
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); }