Ejemplo n.º 1
0
        private void InitializeMiniMap()
        {
            MiniMapImageTilesLayer miniMapTiles = (MiniMapImageTilesLayer)MiniMap.Layers["ImageTilesLayer"];

            SetBingMapDataProviderKey(miniMapTiles.DataProvider as BingMapDataProvider);
            MiniMapVectorItemsLayer layer   = new MiniMapVectorItemsLayer();
            MapItemStorage          storage = new MapItemStorage();

            layer.Data = storage;
            foreach (PhotoMapItem item in ((MapItemStorage)((VectorItemsLayer)MapControl.Layers[2]).Data).Items)
            {
                storage.Items.Add(new MapDot()
                {
                    Location = item.Location, Size = 4, Fill = Color.Red
                });
            }
            MapControl.MiniMap.Layers.Add(layer);
        }
Ejemplo n.º 2
0
        MiniMap CreateMiniMap(object data)
        {
            MiniMap miniMap = new MiniMap()
            {
                Height   = 200,
                Width    = 300,
                Behavior = new FixedMiniMapBehavior()
                {
                    CenterPoint = new GeoPoint(-35, 140),
                    ZoomLevel   = 3
                }
            };

            MiniMapImageTilesLayer mapLayer = new MiniMapImageTilesLayer()
            {
                DataProvider = new BingMapDataProvider()
                {
                    BingKey = bingKey,
                    Kind    = BingMapKind.Area
                }
            };

            MiniMapVectorItemsLayer vectorLayer = new MiniMapVectorItemsLayer();
            ListSourceDataAdapter   adapter     = new ListSourceDataAdapter();

            adapter.DataSource         = data;
            adapter.Mappings.Latitude  = "Latitude";
            adapter.Mappings.Longitude = "Longitude";
            adapter.DefaultMapItemType = MapItemType.Dot;
            adapter.PropertyMappings.Add(
                new MapDotSizeMapping()
            {
                DefaultValue = 10
            }
                );
            vectorLayer.Data             = adapter;
            vectorLayer.ItemStyle.Fill   = Color.FromArgb(74, 212, 255);
            vectorLayer.ItemStyle.Stroke = Color.Gray;

            miniMap.Layers.Add(mapLayer);
            miniMap.Layers.Add(vectorLayer);
            return(miniMap);
        }
        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);
        }