IMapDataAdapter CreateData3() { PieChartDataAdapter adapter = new PieChartDataAdapter() { DataSource = LoadDataFromXml(xmlFilepath), PieItemDataMember = "Huyen", ItemMinSize = 20, ItemMaxSize = 60 }; // Specify mappings. adapter.Mappings.Latitude = "CapitalLat"; adapter.Mappings.Longitude = "CapitalLon"; adapter.Mappings.PieSegment = "TonGiao"; adapter.Mappings.Value = "SLTinDo"; // Specify measure rules adapter.MeasureRules = new MeasureRules(); adapter.MeasureRules.RangeStops.Add(1); adapter.MeasureRules.RangeStops.Add(2); adapter.MeasureRules.RangeStops.Add(3); adapter.MeasureRules.RangeStops.Add(4); adapter.MeasureRules.RangeStops.Add(5); return(adapter); }
// Create pie chart data adapter and specify its parameters. IMapDataAdapter CreateData() { PieChartDataAdapter adapter = new PieChartDataAdapter() { DataSource = LoadDataFromXml(xmlFilepath), PieItemDataMember = "Name", ItemMinSize = 20, ItemMaxSize = 60 }; // Specify mappings. adapter.Mappings.Latitude = "CapitalLat"; adapter.Mappings.Longitude = "CapitalLon"; adapter.Mappings.PieSegment = "MedalClass"; adapter.Mappings.Value = "Quantity"; // Specify measure rules adapter.MeasureRules = new MeasureRules(); adapter.MeasureRules.RangeStops.Add(1); adapter.MeasureRules.RangeStops.Add(10); adapter.MeasureRules.RangeStops.Add(20); adapter.MeasureRules.RangeStops.Add(30); adapter.MeasureRules.RangeStops.Add(40); return(adapter); }
public SCMap AddLayerVectorData(object dataSource, LayerVectorDataOptions options = null) { options ??= new LayerVectorDataOptions(); DataSourceAdapterBase adapter; if (!string.IsNullOrWhiteSpace(options.BubbleField)) { var bubbleAdapter = new BubbleChartDataAdapter() { BubbleItemDataMember = options.BubbleField }; adapter = bubbleAdapter; //Mappings bubbleAdapter.Mappings.ImageIndex = options.ImageIndexField; bubbleAdapter.Mappings.Latitude = options.LatitudeField; bubbleAdapter.Mappings.Longitude = options.LongitudeField; bubbleAdapter.Mappings.Text = options.TextField; bubbleAdapter.Mappings.Type = options.MapItemTypeField; bubbleAdapter.Mappings.XCoordinate = options.XCoordinateField; bubbleAdapter.Mappings.YCoordinate = options.YCoordinateField; bubbleAdapter.Mappings.Value = options.ValueField; } else if (!string.IsNullOrWhiteSpace(options.PieField)) { var pieAdapter = new PieChartDataAdapter() { PieItemDataMember = options.PieField }; adapter = pieAdapter; //Mappings pieAdapter.Mappings.ImageIndex = options.ImageIndexField; pieAdapter.Mappings.Latitude = options.LatitudeField; pieAdapter.Mappings.Longitude = options.LongitudeField; pieAdapter.Mappings.Text = options.TextField; pieAdapter.Mappings.Type = options.MapItemTypeField; pieAdapter.Mappings.XCoordinate = options.XCoordinateField; pieAdapter.Mappings.YCoordinate = options.YCoordinateField; pieAdapter.Mappings.Value = options.ValueField; } else { var listAdapter = new ListSourceDataAdapter() { DefaultMapItemType = (DevExpress.XtraMap.MapItemType)options.DefaultMapItemType }; adapter = listAdapter; //Mappings listAdapter.Mappings.ImageIndex = options.ImageIndexField; listAdapter.Mappings.Latitude = options.LatitudeField; listAdapter.Mappings.Longitude = options.LongitudeField; listAdapter.Mappings.Text = options.TextField; listAdapter.Mappings.Type = options.MapItemTypeField; listAdapter.Mappings.XCoordinate = options.XCoordinateField; listAdapter.Mappings.YCoordinate = options.YCoordinateField; } //Property mappings var defaultItemColor = Utils.ColorFromString(options.DefaultItemColor); if (defaultItemColor != Color.Empty || !string.IsNullOrWhiteSpace(options.ItemColorField)) { var mapItem = new MapItemFillMapping(); if (defaultItemColor != Color.Empty) { mapItem.DefaultValue = defaultItemColor; } if (!string.IsNullOrWhiteSpace(options.ItemColorField)) { mapItem.Member = options.ItemColorField; } adapter.PropertyMappings.Add(mapItem); } var defaultStrokeColor = Utils.ColorFromString(options.DefaultStrokeColor); if (defaultStrokeColor != Color.Empty || !string.IsNullOrWhiteSpace(options.StrokeColorField)) { var mapItem = new MapItemStrokeMapping(); if (defaultStrokeColor != Color.Empty) { mapItem.DefaultValue = defaultStrokeColor; } if (!string.IsNullOrWhiteSpace(options.StrokeColorField)) { mapItem.Member = options.StrokeColorField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultDotShapeKind.HasValue || !string.IsNullOrWhiteSpace(options.DotShapeKindField)) { var mapItem = new MapDotShapeKindMapping(); if (options.DefaultDotShapeKind.HasValue) { mapItem.DefaultValue = (DevExpress.XtraMap.MapDotShapeKind)options.DefaultDotShapeKind.Value; } if (!string.IsNullOrWhiteSpace(options.DotShapeKindField)) { mapItem.Member = options.DotShapeKindField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultDotSize.HasValue || !string.IsNullOrWhiteSpace(options.DotSizeField)) { var mapItem = new MapDotSizeMapping(); if (options.DefaultDotSize.HasValue) { mapItem.DefaultValue = options.DefaultDotSize.Value; } if (!string.IsNullOrWhiteSpace(options.DotSizeField)) { mapItem.Member = options.DotSizeField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultEllipseHeight.HasValue || !string.IsNullOrWhiteSpace(options.EllipseHeightField)) { var mapItem = new MapEllipseHeightMapping(); if (options.DefaultEllipseHeight.HasValue) { mapItem.DefaultValue = options.DefaultEllipseHeight.Value; } if (!string.IsNullOrWhiteSpace(options.EllipseHeightField)) { mapItem.Member = options.EllipseHeightField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultEllipseWidth.HasValue || !string.IsNullOrWhiteSpace(options.EllipseWidthField)) { var mapItem = new MapEllipseWidthMapping(); if (options.DefaultEllipseWidth.HasValue) { mapItem.DefaultValue = options.DefaultEllipseWidth.Value; } if (!string.IsNullOrWhiteSpace(options.EllipseWidthField)) { mapItem.Member = options.EllipseWidthField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultRectangleHeight.HasValue || !string.IsNullOrWhiteSpace(options.RectangleHeightField)) { var mapItem = new MapRectangleHeightMapping(); if (options.DefaultRectangleHeight.HasValue) { mapItem.DefaultValue = options.DefaultRectangleHeight.Value; } if (!string.IsNullOrWhiteSpace(options.RectangleHeightField)) { mapItem.Member = options.RectangleHeightField; } adapter.PropertyMappings.Add(mapItem); } if (options.DefaultRectangleWidth.HasValue || !string.IsNullOrWhiteSpace(options.RectangleWidthField)) { var mapItem = new MapRectangleWidthMapping(); if (options.DefaultRectangleWidth.HasValue) { mapItem.DefaultValue = options.DefaultRectangleWidth.Value; } if (!string.IsNullOrWhiteSpace(options.RectangleWidthField)) { mapItem.Member = options.RectangleWidthField; } adapter.PropertyMappings.Add(mapItem); } //Attribute mappings if (options.Attributes != null) { foreach (string attribute in options.Attributes) { adapter.AttributeMappings.Add(new MapItemAttributeMapping() { Member = attribute, Name = attribute }); } } if (dataSource != null) { adapter.DataSource = GetDataSource(dataSource, new DataSourceParameters()); } var map = Map; MapItemStyle itemStyle; if (!options.MiniMap) { var layer = new VectorItemsLayer() { AllowEditItems = false, EnableHighlighting = false, EnableSelection = false }; if (!string.IsNullOrWhiteSpace(options.ShapeTitlesPattern)) { layer.ShapeTitlesPattern = options.ShapeTitlesPattern; layer.ShapeTitlesVisibility = VisibilityMode.Visible; } if (!string.IsNullOrWhiteSpace(options.Name)) { layer.Name = options.Name; } if (options.ItemImageIndex.HasValue) { layer.ItemImageIndex = options.ItemImageIndex.Value; } itemStyle = layer.ItemStyle; layer.Data = adapter; map.Layers.Add(layer); CurrentLayer = layer; } else { var layerMini = new MiniMapVectorItemsLayer(); if (!string.IsNullOrWhiteSpace(options.Name)) { layerMini.Name = options.Name; } if (options.ItemImageIndex.HasValue) { layerMini.ItemImageIndex = options.ItemImageIndex.Value; } itemStyle = layerMini.ItemStyle; layerMini.Data = adapter; if (map.MiniMap == null) { throw new Exception("Mini map is not created."); } map.MiniMap.Layers.Add(layerMini); CurrentLayer = layerMini; } if (itemStyle != null) { var fillColor = Utils.ColorFromString(options.FillColor); if (fillColor != Color.Empty) { itemStyle.Fill = fillColor; } var font = Utils.StringToFont(options.Font, out Color textColor); if (font != null) { itemStyle.Font = font; } if (textColor != Color.Empty) { itemStyle.TextColor = textColor; } var strokeColor = Utils.ColorFromString(options.StrokeColor); if (strokeColor != Color.Empty) { itemStyle.Stroke = strokeColor; } if (options.StrokeWidth.HasValue) { itemStyle.StrokeWidth = options.StrokeWidth.Value; } var textGlowColor = Utils.ColorFromString(options.TextGlowColor); if (textGlowColor != Color.Empty) { itemStyle.TextGlowColor = textGlowColor; } } return(this); }