Beispiel #1
0
 /// <summary>
 /// 提示渲染函数
 /// </summary>
 /// <param name="drv"></param>
 public sealed override void Render(Maper drv)
 {
     if (!MatchUtils.IsEmpty(this.Target = drv) && this.Target.Enable)
     {
         this.Index = MatchUtils.IsEmpty(this.Index) ? (this.Index = StampUtils.GetTimeStamp()) : this.Index;
         if (drv.Symbol.Tips.ContainsKey(this.Index))
         {
             Tips tips = drv.Symbol.Tips[this.Index];
             if (this.Equals(tips))
             {
                 this.Redraw();
             }
             else
             {
                 {
                     tips.Remove();
                 }
                 this.Render(drv);
             }
         }
         else
         {
             // 监听广播
             this.Observe(drv.Listen.DragEvent, this.Redraw);
             this.Observe(drv.Listen.ZoomEvent, this.Redraw);
             this.Observe(drv.Listen.SwapEvent, this.Redraw);
             // 绘制图形
             drv.Symbol.Tips.Add(this.Index, this);
             try
             {
                 this.Redraw();
             }
             catch
             {
                 drv.Symbol.Tips.Remove(this.Index);
             }
             finally
             {
                 if (!drv.Symbol.Tips.ContainsKey(this.Index))
                 {
                     // 移除监听
                     this.Obscure(drv.Listen.DragEvent, this.Redraw);
                     this.Obscure(drv.Listen.ZoomEvent, this.Redraw);
                     this.Obscure(drv.Listen.SwapEvent, this.Redraw);
                     {
                         this.Facade = null;
                         this.handle = null;
                         this.Target = null;
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// 渲染对象
 /// </summary>
 /// <param name="drv"></param>
 public sealed override void Render(Maper drv)
 {
     if (!MatchUtils.IsEmpty(this.Target = drv) && this.Target.Enable)
     {
         this.Index = MatchUtils.IsEmpty(this.Index) ? (this.Index = StampUtils.GetTimeStamp()) : this.Index;
         if (drv.Symbol.Draw.ContainsKey(this.Index))
         {
             Geom geom = drv.Symbol.Draw[this.Index];
             if (this.Equals(geom))
             {
                 this.Redraw();
             }
             else
             {
                 {
                     geom.Remove();
                 }
                 this.Render(drv);
             }
         }
         else
         {
             if (!MatchUtils.IsEmpty(this.Facade = drv.Vessel.Draw))
             {
                 // 监听广播
                 this.Observe(drv.Listen.ZoomEvent, this.Redraw);
                 this.Observe(drv.Listen.SwapEvent, this.Redraw);
                 // 绘制图形
                 try
                 {
                     (drv.Symbol.Draw[this.Index] = this).Redraw();
                 }
                 catch
                 {
                     drv.Symbol.Draw.Remove(this.Index);
                 }
                 finally
                 {
                     if (!drv.Symbol.Draw.ContainsKey(this.Index))
                     {
                         // 移除监听
                         this.Obscure(drv.Listen.ZoomEvent, this.Redraw);
                         this.Obscure(drv.Listen.SwapEvent, this.Redraw);
                         {
                             this.Facade = null;
                             this.Target = null;
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="facade">地图面板</param>
 /// <param name="option">地图配置</param>
 public Maper(Panel facade, Option option)
 {
     if (!MatchUtils.IsEmpty(this.facade = facade) && !MatchUtils.IsEmpty(this.option = option) && (
             this.enable = true
             ))
     {
         // 初始光标
         this.facade.Cursor = (this.sharer = new Share()).FreeCur;
         {
             // 初始参数
             this.ramble = this.option.Exist("Ramble") ? this.option.Fetch <bool>("Ramble") : true;
             this.assets = new Assets(
                 this.option.Exist("Assets") ? this.option.Fetch <string>("Assets") : null
                 );
         }
         // 初始缓存
         this.screen = new Screen(
             this.facade
             );
         this.symbol = new Symbol();
         this.widget = new Widget();
         this.listen = new Listen();
         {
             this.listen.DragEvent = new Event(this);
             this.listen.ZoomEvent = new Event(this);
             this.listen.SwapEvent = new Event(this);
         }
         // 初始尺寸
         Binding wide = new Binding();
         wide.Source = this.facade;
         wide.Mode   = BindingMode.OneWay;
         wide.Path   = new PropertyPath("ActualWidth");
         Binding high = new Binding();
         high.Source = this.facade;
         high.Mode   = BindingMode.OneWay;
         high.Path   = new PropertyPath("ActualHeight");
         // 初始画布
         (this.canvas = new Canvas()).Background = new SolidColorBrush(Color.FromRgb(229, 227, 223));
         {
             // 裁切显示区
             this.canvas.ClipToBounds = true;
             // 自适应宽度
             this.canvas.SetBinding(Canvas.WidthProperty, wide);
             // 自适应高度
             this.canvas.SetBinding(Canvas.HeightProperty, high);
         }
         // 初始地图集
         this.vessel = new Atlas(10);
         {
             // 自适应宽度
             this.vessel.SetBinding(UserControl.WidthProperty, wide);
             // 自适应高度
             this.vessel.SetBinding(UserControl.HeightProperty, high);
         }
         // 实例化图层
         this.canvas.Children.Add(this.vessel);
         this.facade.Children.Add(this.canvas);
         // 初始化画笔
         this.sketch = new MagicGraphic(this.vessel.Draw);
         {
             // 初始化线程
             this.thread = new MagicThreadFactory();
             // 初始化缓存
             this.memory = new MagicCache(
                 "MaperCache_" + StampUtils.GetTimeStamp(), 300, 75, TimeSpan.Parse("00:10:00")
                 );
         }
         // 初始化布局
         this.facade.SizeChanged += (obj, evt) =>
         {
             if (!this.screen.W.Equals(this.facade.ActualWidth) || !this.screen.H.Equals(this.facade.ActualHeight))
             {
                 // 调整屏幕大小
                 this.screen.X = (this.screen.W = this.facade.ActualWidth) / 2;
                 this.screen.Y = (this.screen.H = this.facade.ActualHeight) / 2;
                 // 调整地图大小
                 if (!MatchUtils.IsEmpty(this.netmap))
                 {
                     this.netmap.Resize();
                 }
             }
         };
         // 初始化漫游
         this.facade.MouseLeftButtonDown += new MouseButtonEventHandler(delegate(object downObj, MouseButtonEventArgs downEvt)
         {
             if (!MatchUtils.IsEmpty(this.netmap) && this.netmap.Enable && this.enable && this.ramble && (
                     downEvt.Handled = downEvt.ClickCount.Equals(1)
                     ))
             {
                 if (Mouse.Capture(this.facade, CaptureMode.SubTree))
                 {
                     Point spoint = downEvt.GetPosition(this.facade), epoint = new Point();
                     {
                         // 拖拽光标
                         this.facade.Cursor = this.sharer.DragCur;
                         {
                             MouseEventHandler mevent       = null;
                             MouseButtonEventHandler sevent = null;
                             // 绑定事件
                             this.facade.MouseMove += (mevent = new MouseEventHandler(delegate(object moveObj, MouseEventArgs moveEvt)
                             {
                                 // 捕捉光标
                                 if (this.manual = !(MatchUtils.IsEmpty(epoint = moveEvt.GetPosition(this.facade)) || Point.Equals(spoint, epoint)))
                                 {
                                     Canvas.SetTop(this.vessel, this.netmap.Nature.T - (epoint.Y = (spoint.Y - epoint.Y)));
                                     Canvas.SetLeft(this.vessel, this.netmap.Nature.L - (epoint.X = (spoint.X - epoint.X)));
                                 }
                             }));
                             this.facade.MouseLeftButtonUp += (sevent = new MouseButtonEventHandler(delegate(object stopObj, MouseButtonEventArgs stopEvt)
                             {
                                 // 恢复光标
                                 this.facade.Cursor = this.sharer.FreeCur;
                                 {
                                     stopEvt.Handled = true;
                                     try
                                     {
                                         this.facade.MouseMove -= mevent;
                                         this.facade.MouseLeftButtonUp -= sevent;
                                     }
                                     catch
                                     { }
                                     finally
                                     {
                                         // 释放光标
                                         Mouse.Capture(this.facade, CaptureMode.None);
                                         try
                                         {
                                             if (!MatchUtils.IsEmpty(this.center) && this.manual)
                                             {
                                                 this.Netmap.Moveto(this.netmap.Crd2px(this.center).Offset(new Pixel(epoint.X, epoint.Y)));
                                             }
                                         }
                                         catch
                                         { }
                                         finally
                                         {
                                             this.manual = false;
                                             {
                                                 spoint.X = 0;
                                                 spoint.Y = 0;
                                                 epoint.X = 0;
                                                 epoint.Y = 0;
                                             }
                                             mevent = null;
                                             sevent = null;
                                         }
                                     }
                                 }
                             }));
                         }
                     }
                 }
             }
         });
     }
 }
Beispiel #4
0
 /// <summary>
 /// 图层渲染函数
 /// </summary>
 /// <param name="drv">地图对象</param>
 /// <param name="job">回调函数</param>
 public sealed override void Render(Maper drv)
 {
     if (!MatchUtils.IsEmpty(this.Target = drv) && drv.Enable && !MatchUtils.IsEmpty(this.Factor))
     {
         this.Index = MatchUtils.IsEmpty(this.Index) ? (this.Index = StampUtils.GetTimeStamp()) : this.Index;
         if (this.Cover)
         {
             if (drv.Symbol.Pile.ContainsKey(this.Index))
             {
                 Geog geog = drv.Symbol.Pile[this.Index];
                 if (this.Equals(geog))
                 {
                     this.Access(this.Allow);
                 }
                 else
                 {
                     {
                         geog.Remove();
                     }
                     this.Render(drv);
                 }
             }
             else
             {
                 int order = 1;
                 try
                 {
                     drv.Vessel.Pile.Children.Add(this.Facade = new Scene());
                 }
                 catch
                 {
                     order = 0;
                 }
                 finally
                 {
                     if (order == 1)
                     {
                         // 监听广播
                         this.Observe(drv.Listen.DragEvent, this.Redraw, 1);
                         this.Observe(drv.Listen.ZoomEvent, this.Redraw, 1);
                         this.Observe(drv.Listen.SwapEvent, this.Redraw, 1);
                         // 加载图层
                         drv.Symbol.Pile.Add(this.Index, this);
                         try
                         {
                             this.Access(this.Allow);
                         }
                         catch
                         {
                             drv.Symbol.Pile.Remove(this.Index);
                         }
                         finally
                         {
                             if (drv.Symbol.Pile.ContainsKey(this.Index))
                             {
                                 if (int.TryParse(this.Index, out order))
                                 {
                                     Canvas.SetZIndex(this.Facade, order);
                                 }
                             }
                             else
                             {
                                 // 移除监听
                                 this.Obscure(drv.Listen.DragEvent, this.Redraw);
                                 this.Obscure(drv.Listen.ZoomEvent, this.Redraw);
                                 this.Obscure(drv.Listen.SwapEvent, this.Redraw);
                                 // 移除图层
                                 drv.Vessel.Pile.Children.Remove(this.Facade);
                                 {
                                     this.Facade = null;
                                     this.Target = null;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         else
         {
             if (!drv.Symbol.Tile.ContainsKey(this.Index) && !MatchUtils.IsEmpty(
                     this.Facade = drv.Vessel.Tile
                     ))
             {
                 drv.Symbol.Tile.Add(this.Index, this);
                 try
                 {
                     this.Access(MatchUtils.IsEmpty(drv.Netmap));
                 }
                 catch
                 {
                     drv.Symbol.Tile.Remove(this.Index);
                     {
                         this.Facade = null;
                         this.Target = null;
                     }
                 }
             }
         }
     }
 }