Exemplo n.º 1
0
        public C1Mapper(IMapperOwner owner)
        {
            InitializeComponent();

#if !DYN
            _c1maps = new C1.WPF.Maps.C1Maps();
#else
            _c1maps = DynLoader.CreateC1MapsInstance("C1.WPF.Maps.C1Maps");
#endif
            //
            this._grid.Children.Add(_c1maps);

            _owner = owner;
            _owner.LayersChanged            += new EventHandler(Map_LayersChanged);
            _owner.Layers.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Layers_CollectionChanged);

            this.Background = Util.BrushFromGdiColor(Utils.FromWpfColor(_owner.BackColor));

            // hide/show standard tools as required:
            this.LayoutUpdated += (ss, ee) => HideShowTools();
            // TBD: add a property to automatically move scale so as not to obscure data

            _c1maps.FadeInTiles = false;
#if !DYN
            _c1maps.TilesLoadProgress += new EventHandler <TilesLoadProgressEventArgs>(_c1maps_TilesLoadProgress);
#else
            var handlerType   = typeof(EventHandler <>).MakeGenericType(DynLoader.GetC1MapsType("TilesLoadProgressEventArgs"));
            var handlerMethod = typeof(C1Mapper).GetMethod("_c1maps_TilesLoadProgress", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var handler       = Delegate.CreateDelegate(handlerType, this, handlerMethod);
            _c1maps.TilesLoadProgress += handler;
#endif
            //
            ResetLayers();
        }
Exemplo n.º 2
0
        private UIElement MakeItem(ILegendItem legendItem, Legend legend, IMapperOwner owner)
        {
            switch (legendItem.LegendItemKind)
            {
            case LegendItemKind.Point:
                return(MakePointItem(legendItem, legend, owner));

            case LegendItemKind.Line:
                return(MakeLineItem(legendItem, legend, owner));

            case LegendItemKind.KML:
            case LegendItemKind.None:
                return(null);

            case LegendItemKind.ColorSwatch:
                return(MakeColorSwatchItem(legendItem, legend, owner));

            case LegendItemKind.Text:
                return(MakeTextItem(legendItem, legend, owner));

            default:
                System.Diagnostics.Debug.Assert(false, "unknown legend item type");
                return(null);
            }
        }
Exemplo n.º 3
0
        private TextBlock MakeItemText(ILegendItem mapperItem, Legend mapLegend, IMapperOwner owner, out double padding)
        {
            // text:
            TextBlock tb = new TextBlock();

            tb.Foreground        = Util.BrushFromGdiColor(GetTextColor(mapLegend, mapperItem));
            tb.Text              = mapperItem == null ? mapLegend.Caption : mapperItem.LegendItemCaption;
            tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            if (mapperItem == null)
            {
                tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; // todo: give control to user?
            }
            Util.ApplyFontToTextBlock(GetFont(mapLegend, mapperItem), tb);
            padding   = tb.FontSize / 4;
            tb.Margin = new Thickness(padding, 0, padding, 0);
            return(tb);
        }
Exemplo n.º 4
0
        private UIElement MakePointItem(ILegendItem mapperItem, Legend mapLegend, IMapperOwner owner)
        {
            System.Diagnostics.Debug.Assert(mapperItem.LegendItemKind == LegendItemKind.Point);
            double padding;
            var    tb = MakeItemText(mapperItem, mapLegend, owner, out padding);

            // graphics:
            Path p      = new Path();
            var  stroke = GetStrokeColor(mapLegend, mapperItem);

            p.Stroke = Util.BrushFromGdiColor(stroke);
            var fill = mapperItem.LegendItemFillColor;

            p.Fill = Util.BrushFromGdiColor(fill);

            double size;

            if (mapperItem.LegendItemMarkerSize >= 0)
            {
                size = mapperItem.LegendItemMarkerSize;
            }
            else
            {
                size = tb.FontSize / 3; // a "heuristic" ...
            }
            Geometry eg = Util.MarkerShapeToGeometry(mapperItem.LegendItemMarkerShape, size);

            p.Data = eg;
            p.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
            p.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            p.Margin = new Thickness(size + padding, size + padding, padding, padding);

            // combine:
            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Horizontal;
            sp.Children.Add(p);
            sp.Children.Add(tb);

            return(sp);
        }
Exemplo n.º 5
0
        private UIElement MakeLineItem(ILegendItem mapperItem, Legend mapLegend, IMapperOwner owner)
        {
            System.Diagnostics.Debug.Assert(mapperItem.LegendItemKind == LegendItemKind.Line);
            double padding;
            var    tb = MakeItemText(mapperItem, mapLegend, owner, out padding);

            // graphics:
            Path p      = new Path();
            var  stroke = GetStrokeColor(mapLegend, mapperItem);

            p.Stroke = Util.BrushFromGdiColor(stroke);
            var fill = mapperItem.LegendItemFillColor;

            p.Fill            = Util.BrushFromGdiColor(fill);
            p.StrokeDashArray = Util.DashStyleToCollection(mapperItem.LegendItemDashStyle);
            if (mapperItem.LegendItemLineThickness >= 0)
            {
                p.StrokeThickness = mapperItem.LegendItemLineThickness;
            }

            LineGeometry lg = new LineGeometry();

            lg.StartPoint         = new Point(0, tb.FontSize / 3);               // "heuristic" ...
            lg.EndPoint           = new Point(tb.FontSize * 3, tb.FontSize / 3); // another one :)
            p.Data                = lg;
            p.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
            p.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
            p.Margin              = new Thickness(lg.StartPoint.X + padding, lg.StartPoint.Y + padding, padding, padding);

            // combine:
            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Horizontal;
            sp.Children.Add(p);
            sp.Children.Add(tb);

            return(sp);
        }
Exemplo n.º 6
0
        public void UpdateFromOwner(IMapperOwner owner, Legend mapLegend)
        {
            ItemsContainer.Children.Clear();
            if (owner == null || mapLegend == null)
            {
                return;
            }

            // Orientation:
            ItemsContainer.Orientation = mapLegend.Orientation == System.Windows.Forms.Orientation.Vertical ?
                                         Orientation.Vertical : Orientation.Horizontal;

            // alignment:
            HorizontalAlignment horz;
            VerticalAlignment   vert;

            Util.ContentToHorzVertAlign(mapLegend.LegendAlignment, out horz, out vert);
            this.HorizontalAlignment = horz;
            this.VerticalAlignment   = vert;

            // margins
            this.Margin = new Thickness(
                mapLegend.Margin.Left, mapLegend.Margin.Top, mapLegend.Margin.Right, mapLegend.Margin.Bottom);
            this.BorderThickness = new Thickness(
                mapLegend.BorderThickness.Left, mapLegend.BorderThickness.Top, mapLegend.BorderThickness.Right, mapLegend.BorderThickness.Bottom);
            this.Padding = new Thickness(
                mapLegend.Padding.Left, mapLegend.Padding.Top, mapLegend.Padding.Right, mapLegend.Padding.Bottom);

            //
            this.Background = Util.BrushFromGdiColor(mapLegend.BackColor);

            double padding = 0;

            if (!string.IsNullOrEmpty(mapLegend.Caption))
            {
                ItemsContainer.Children.Add(MakeLegendCaption(mapLegend, owner, out padding));
            }

            Action <IEnumerable> addItems = (items) =>
            {
                foreach (ILegendItem li in items)
                {
                    if (li.LegendItemVisible)
                    {
                        var item = MakeItem(li, mapLegend, owner);
                        if (item != null)
                        {
                            ItemsContainer.Children.Add(item);
                        }
                    }
                }
            };

            if (mapLegend.Automatic)
            {
                addItems(mapLegend.Owner.Layers);
            }
            else
            {
                addItems(mapLegend.Items);
            }
        }
Exemplo n.º 7
0
        private TextBlock MakeTextItem(ILegendItem legendItem, Legend legend, IMapperOwner owner)
        {
            double padding;

            return(MakeItemText(legendItem, legend, owner, out padding));
        }
Exemplo n.º 8
0
 private TextBlock MakeLegendCaption(Legend legend, IMapperOwner owner, out double padding)
 {
     return(MakeItemText(null, legend, owner, out padding));
 }