Esempio 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();
        }
Esempio n. 2
0
        /// <summary>
        /// Refreshes the tile source if needed, based on owner setting.
        /// </summary>
        private void RefreshTileSource()
        {
            if (_owner == null)
            {
                return;
            }

            Action <string> setSource = (typeName) =>
            {
                if (_c1maps.Source == null || _c1maps.Source.GetType().FullName == typeName)
                {
                    _c1maps.Source = DynLoader.CreateC1MapsInstance(typeName);
                }
            };

            switch (_owner.TileSource)
            {
            case TileSource.None:
                if (_c1maps.Source != null)
                {
                    _c1maps.Source = null;
                }
                break;

            case TileSource.VirtualEarthAerial:
                setSource("C1.WPF.Maps.VirtualEarthAerialSource");
                break;

            case TileSource.VirtualEarthHybrid:
                setSource("C1.WPF.Maps.VirtualEarthHybridSource");
                break;

            case TileSource.VirtualEarthRoad:
                setSource("C1.WPF.Maps.VirtualEarthRoadSource");
                break;

#if not_yet
            case MapTileSource.OpenStreet:
                if (!(_c1maps.Source is C1.C1Report.CustomFields.OpenStreetMapsSource))
                {
                    _c1maps.Source = new C1.C1Report.CustomFields.OpenStreetMapsSource();
                }
                break;

            case MapTileSource.CloudMade:
                if (!(_c1maps.Source is C1.C1Report.CustomFields.CloudMadeMapsSource))
                {
                    _c1maps.Source = new C1.C1Report.CustomFields.CloudMadeMapsSource("tbd: allow to specify key");
                }
                break;
#endif
            default:
                System.Diagnostics.Debug.Assert(false, "unknown MapTileSource");
                break;
            }
        }
Esempio n. 3
0
            public LinesMapsLayer(LayerBase owner)
                : base(owner)
            {
#if !DYN
                _lines = new ObservableCollection <WPF.Maps.C1VectorPolyline>();
#else
                var genericCollType   = typeof(ObservableCollection <>);
                var specLinesCollType = genericCollType.MakeGenericType(DynLoader.GetC1MapsType("C1.WPF.Maps.C1VectorPolyline"));
                _lines = Activator.CreateInstance(specLinesCollType);
#endif
                _vectorLayer.ItemsSource = _lines;
            }
Esempio n. 4
0
            public PointsMapsLayer(LayerBase owner)
                : base(owner)
            {
#if !DYN
                _marks = new ObservableCollection <WPF.Maps.C1VectorPlacemark>();
#else
                var genericCollType   = typeof(ObservableCollection <>);
                var specMarksCollType = genericCollType.MakeGenericType(DynLoader.GetC1MapsType("C1.WPF.Maps.C1VectorPlacemark"));
                _marks = Activator.CreateInstance(specMarksCollType);
#endif
                _vectorLayer.ItemsSource = _marks;
            }
Esempio n. 5
0
            public VectorLayer(LayerBase owner)
                : base(owner)
            {
#if !DYN
                _vectorLayer = new C1.WPF.Maps.C1VectorLayer();
#else
                _vectorLayer = DynLoader.CreateC1MapsInstance("C1.WPF.Maps.C1VectorLayer");
#endif
                _vectorLayer.Name = MapLayer.Key;
                // AutoHide may yield unexpected results:
#if !DYN
                _vectorLayer.LabelVisibility = WPF.Maps.LabelVisibility.Visible;
#else
                _vectorLayer.LabelVisibility = DynLoader.GetC1MapsEnumValue("C1.WPF.Maps.LabelVisibility.Visible");
#endif
            }
Esempio n. 6
0
        /// <summary>
        /// Adds a line to the lines layer.
        /// </summary>
        /// <param name="longitude1"></param>
        /// <param name="latitude1"></param>
        /// <param name="longitude2"></param>
        /// <param name="latitude2"></param>
        /// <param name="stroke"></param>
        /// <param name="fill"></param>
        /// <param name="dashes"></param>
        public void DrawLine(
            string layerKey,
            double longitude1, double latitude1, double longitude2, double latitude2,
            Brush stroke, Brush fill, DoubleCollection dashes, double thickness)
        {
#if !DYN
            C1.WPF.Maps.C1VectorPolyline line = new C1VectorPolyline();
#else
            dynamic line = DynLoader.CreateC1MapsInstance("C1VectorPolyline");
#endif
            line.Points = new PointCollection()
            {
                new Point(longitude1, latitude1),
                new Point(longitude2, latitude2),
            };
            line.StrokeDashArray = dashes;
            line.Stroke          = stroke;
            line.Fill            = fill;
            line.StrokeThickness = thickness;

            LinesMapsLayer ll = _layers.Find((l) => l.MapLayer.Key == layerKey) as LinesMapsLayer;
            System.Diagnostics.Debug.Assert(ll != null);
            ll.AddLine(line);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        /// <param name="layerKey"></param>
        /// <param name="longitude"></param>
        /// <param name="latitude"></param>
        /// <param name="caption"></param>
        /// <param name="font"></param>
        /// <param name="markShape"></param>
        /// <param name="size"></param>
        /// <param name="stroke"></param>
        /// <param name="fill"></param>
        public void DrawPoint(string layerKey,
                              double longitude, double latitude,
                              string caption, System.Drawing.Font font, System.Drawing.Color textColor,
                              MarkerShape markShape, double size, System.Drawing.Color stroke, System.Drawing.Color fill)
        {
#if !DYN
            var mark = new C1.WPF.Maps.C1VectorPlacemark();
            mark.Lod = new C1.WPF.Maps.LOD(1, 300, 0, 10); // tbd: allow to control this
#else
            dynamic mark = DynLoader.CreateC1MapsInstance("C1VectorPlacemark");
            mark.Lod = DynLoader.CreateC1MapsInstance("C1.WPF.Maps.LOD", 1, 300, 0, 10);
#endif
            mark.GeoPoint = new Point(longitude, latitude);

            if (!string.IsNullOrEmpty(caption))
            {
                mark.Label = caption;
                Util.ApplyFontToControl(font, mark);
                if (!Util.IsColorEmpty(textColor))
                {
                    mark.Foreground = Util.BrushFromGdiColor(textColor);
                }
                // mark.LabelPosition = WPF.Maps.LabelPosition.Right | WPF.Maps.LabelPosition.Bottom;
                // mark.Background = new SolidColorBrush(Colors.Red);
                // TBD: label:
                // - setting mark.LabelPosition makes the label tiny. clarify.
            }

            mark.Geometry = Util.MarkerShapeToGeometry(markShape, size);
            mark.Stroke   = Util.BrushFromGdiColor(stroke);
            mark.Fill     = Util.BrushFromGdiColor(fill);

            PointsMapsLayer ml = _layers.Find((l) => l.MapLayer.Key == layerKey) as PointsMapsLayer;
            System.Diagnostics.Debug.Assert(ml != null);
            ml.AddMark(mark);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a System.Drawing.Image representing the current map.
        /// </summary>
        /// <param name="dpiX">The horizontal resolution of the image.</param>
        /// <param name="dpiY">The vertical resolution of the image.</param>
        /// <returns>The image (bitmap).</returns>
        public System.Drawing.Image GetImage(double dpiX, double dpiY)
        {
            if (_doingEvents)
            {
                return(null);
            }

            RefreshTileSource();

            // apply layer-wide properties:
            foreach (MapsLayerBase lb in _layers)
            {
                lb.UpdateLayerProperties();
            }

            // clear old legends:
            for (int i = _grid.Children.Count - 1; i >= 0; --i)
            {
                if (_grid.Children[i] is MapperLegend)
                {
                    _grid.Children.RemoveAt(i);
                }
            }

            // add new ones:
            if (_owner != null)
            {
                foreach (Legend ml in _owner.Legends)
                {
                    if (ml.Visible)
                    {
                        var l = new MapperLegend();
                        _grid.Children.Add(l);
                        l.Visibility = System.Windows.Visibility.Visible;
                        l.UpdateFromOwner(_owner, ml);
                    }
                }
            }

            this.Measure(new System.Windows.Size(this.Width, this.Height));
            this.Arrange(new System.Windows.Rect(new System.Windows.Size(this.Width, this.Height)));
            this.UpdateLayout();

            // there's no TilesMode in WPF Maps anymore, as its probably the only mode now(?).
            // NOTE: we must DoEvents() at least once even if _tilesRemaining==0, otherwise
            // we don't get the image.
#if skip_dima
#if !DYN
            if (_c1maps.TilesMode == MapTilesMode.Native)
#else
            if (_c1maps.TilesMode == DynLoader.GetC1MapsEnumValue("C1.WPF.Maps.MapTilesMode.Native"))
#endif
#endif
            {
                int oldTilesRemaining = _tilesRemaining;
                DoEvents();
                const int MAX_WAIT_LOOPS     = 200;
                const int MAX_NOCHANGE_LOOPS = 30;
                int       nochange_loops     = 0;
                for (int i = 0; i < MAX_WAIT_LOOPS && nochange_loops < MAX_NOCHANGE_LOOPS && _tilesRemaining > 0; ++i)
                {
                    System.Threading.Thread.Sleep(300);
                    DoEvents();
                    if (oldTilesRemaining == _tilesRemaining)
                    {
                        ++nochange_loops;
                    }
                }
            }
            return(MakeImage(dpiX, dpiY));
        }
Esempio n. 9
0
        /// <summary>
        /// Loads a KML or KMZ file from the specified stream into the layer.
        /// </summary>
        /// <param name="vl">The layer to load the stream into.</param>
        /// <param name="stream">The source stream.</param>
        /// <param name="addingItemProc">The callback to call for each KML item.</param>
        /// <param name="maxBounds">OUT: The union of all loaded items' bounds.</param>
        private static void LoadKML(dynamic vl, Stream stream, AddingKmlItemDelegate addingItemProc, out Rect maxBounds)
        {
            maxBounds = Rect.Empty;
#if !DYN
            var vects = KmlReader.Read(stream);
#else
            dynamic vects = DynLoader.CallC1MapsStaticMethod("C1.WPF.Maps.KmlReader", "Read", stream);
#endif
            vl.BeginUpdate();
#if !DYN
            foreach (C1VectorItemBase vect in vects)
            {
#else
            for (int i = 0; i < vects.Count; ++i)
            {
                dynamic vect = vects[i];
#endif
                if (addingItemProc != null)
                {
                    var oldName = ToolTipService.GetToolTip(vect) as string;
                    var newName = oldName;
                    Nullable <System.Drawing.Color> stroke, fill;
                    bool trackCoords;
                    if (!addingItemProc(ref newName, out stroke, out fill, out trackCoords))
                    {
                        continue;
                    }
                    if (stroke.HasValue)
                    {
                        vect.Stroke = Util.BrushFromGdiColor(stroke.Value);
                    }
                    if (fill.HasValue)
                    {
                        vect.Fill = Util.BrushFromGdiColor(fill.Value);
                    }
                    if (newName != oldName)
                    {
                        ToolTipService.SetToolTip(vect, newName);
#if !DYN
                        if (vect is C1VectorPlacemark)
                        {
                            ((C1VectorPlacemark)vect).Label = newName;
                        }
#else
                        if (vect.GetType() == DynLoader.GetC1MapsType("C1VectorPlacemark"))
                        {
                            vect.Label = newName;
                        }
#endif
                    }
                    if (trackCoords)
                    {
                        maxBounds.Union(vect.Bounds);
                    }
                }
                else
                {
                    maxBounds.Union(vect.Bounds);
                }

                vl.Children.Add(vect);
            }
            vl.EndUpdate();
        }