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(); }
/// <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; } }
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 }
/// <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); }
/// <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); }