Example #1
0
 public AsyncLoadImage(String path, MagicCache cache, CancellationToken token, MagicThreadFactory thread, Delegate action, Object[] expect)
 {
     this.path   = path;
     this.cache  = cache;
     this.token  = token;
     this.thread = thread;
     this.action = action;
     this.expect = expect;
 }
Example #2
0
 /// <summary>
 /// 异步载图
 /// </summary>
 /// <param name="path">数据源</param>
 /// <param name="cache">数据缓存</param>
 /// <param name="token">线程令牌</param>
 /// <param name="thread">线程工厂</param>
 /// <param name="action">回调函数</param>
 /// <param name="expect">期望参数</param>
 public static MagicThread AsyncLoad(String path, MagicCache cache, MagicThreadFactory thread, Delegate action, Object[] expect)
 {
     System.Threading.CancellationTokenSource drive = new System.Threading.CancellationTokenSource();
     {
         MagicThread task = new MagicThread(path, (new AsyncLoadImage(path, cache, drive.Token, thread, action, expect)).DownLoad);
         {
             thread.Attach(task, drive);
         }
         return(task);
     }
 }
Example #3
0
 public void Dispose()
 {
     if (!MatchUtils.IsEmpty(this.thread))
     {
         this.thread.Destroy();
         {
             this.thread = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.widget))
     {
         this.widget.Dispose();
         {
             this.widget = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.symbol))
     {
         this.symbol.Dispose();
         {
             this.symbol = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.listen))
     {
         this.listen.Dispose();
         {
             this.listen = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.vessel))
     {
         this.vessel.Dispose();
         {
             this.vessel = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.option))
     {
         this.option.Clear();
         {
             this.option = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.sharer))
     {
         this.sharer.Dispose();
         {
             this.sharer = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.canvas))
     {
         this.canvas.Children.Clear();
         {
             this.canvas = null;
         }
     }
     if (!MatchUtils.IsEmpty(this.facade))
     {
         this.facade.Children.Clear();
         {
             this.facade = null;
         }
     }
     // 内存释放
     {
         this.assets = null;
         this.screen = null;
         this.center = null;
         this.sketch = null;
         this.netmap = null;
     }
 }
Example #4
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;
                                         }
                                     }
                                 }
                             }));
                         }
                     }
                 }
             }
         });
     }
 }
Example #5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="path">数据源</param>
 /// <param name="cache">数据缓存</param>
 /// <param name="action">回调函数</param>
 public AsyncLoadImage(String path, MagicCache cache, CancellationToken token, MagicThreadFactory thread, Delegate action)
     : this(path, cache, token, thread, action, null)
 {
 }