Esempio n. 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;
                     }
                 }
             }
         }
     }
 }
Esempio n. 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;
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 广播消息
 /// </summary>
 /// <param name="msg">消息</param>
 public void Broadcast(Object msg)
 {
     // 生成队列
     foreach (Action <Msger> fun in this.observer)
     {
         this.schedule.Enqueue(new Motion <Msger>(
                                   fun, new Msger(this, msg)
                                   ));
     }
     // 执行队列
     if (this.complete)
     {
         try
         {
             while (!(this.complete = this.schedule.Count.Equals(0)))
             {
                 // 多线程调度
                 this.audience.Thread.Attach(new MagicThread(StampUtils.GetSequence(), new Func <IEnumerable <Motion <Msger> >, Action>((motions) =>
                 {
                     return(() =>
                     {
                         if (!MatchUtils.IsEmpty(motions))
                         {
                             foreach (Motion <Msger> motion in motions)
                             {
                                 try
                                 {
                                     motion.Fun(motion.Msg);
                                 }
                                 catch
                                 { }
                             }
                         }
                     });
                 })(this.BatchTask(this.schedule, 100))));
             }
         }
         catch
         {
             {
                 this.schedule.Clear();
             }
             this.complete = true;
         }
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 图层缩放
 /// </summary>
 public sealed override void Zoomto(int num)
 {
     if (!MatchUtils.IsEmpty(this.Target) && this.Equals(this.Target.Netmap) && this.Target.Enable && this.Enable && this.Level != num)
     {
         double deg = 0.0;
         try
         {
             deg = this.Factor[num];
         }
         catch
         {
             deg = 0.0;
         }
         finally
         {
             if (deg > 0)
             {
                 Pixel middle = this.Crd2px(this.Target.Center);
                 if (!MatchUtils.IsEmpty(middle))
                 {
                     // 缩放比率
                     double ratio = this.Factor[this.Level] / this.Factor[this.Level = num];
                     {
                         // 缩略地图
                         this.Thumb(ratio, new Pixel(
                                        middle.X - this.Nature.X,
                                        middle.Y - this.Nature.Y
                                        ));
                         // 地图属性
                         this.Grasp(middle.Ratio(ratio), this.Nature);
                         // 事件通知
                         this.Trigger(this.Target.Listen.ZoomEvent, ratio);
                     }
                     // 延时重绘
                     this.Target.Thread.Attach(new MagicThread(StampUtils.GetSequence(), () =>
                     {
                         {
                             Thread.Sleep(700);
                         }
                         this.Build(this.Crd2px(this.Target.Center));
                     }));
                 }
             }
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 获取图像数据
 /// </summary>
 public void DownLoad()
 {
     if (!this.token.IsCancellationRequested)
     {
         if (this.cache.IsExist(this.path))
         {
             Object[] result = { ImageUtils.Format(this.cache.Fetch(this.path) as byte[]) };
             if (MatchUtils.IsEmpty(this.expect))
             {
                 this.action.DynamicInvoke(result);
             }
             else
             {
                 this.action.DynamicInvoke(result.Concat(this.expect).ToArray());
             }
         }
         else
         {
             using (WebClient http = new WebClient())
             {
                 http.Headers.Set("User-Agent", "Windows NT");
                 {
                     this.token.Register(() =>
                     {
                         this.thread.Attach(new MagicThread(StampUtils.GetSequence(), http.CancelAsync));
                     });
                     // 注册回调
                     {
                         http.DownloadDataCompleted += new DownloadDataCompletedEventHandler(this.WebClient_DownLoadDataCompleted);
                     }
                     http.DownloadDataAsync(new Uri(this.path));
                 }
             }
         }
     }
 }
Esempio n. 6
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;
                                         }
                                     }
                                 }
                             }));
                         }
                     }
                 }
             }
         });
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 图层重绘函数
 /// </summary>
 /// <param name="msg">重绘消息</param>
 public sealed override void Redraw(Msger msg)
 {
     if (!MatchUtils.IsEmpty(this.Target) && this.Target.Enable && this.Enable && !MatchUtils.IsEmpty(this.Facade))
     {
         if (MatchUtils.IsEmpty(msg))
         {
             this.Redraw();
         }
         else
         {
             // Drag Event.
             if (this.Target.Listen.DragEvent.Equals(msg.Chan))
             {
                 if (this.Allow && !MatchUtils.IsEmpty(this.Nature))
                 {
                     if (this.Extent.Contain(this.Target, msg.Info as Coord))
                     {
                         this.Build(this.Crd2px(msg.Info as Coord));
                     }
                     else
                     {
                         this.Facade.Dispatcher.BeginInvoke(new Action(() =>
                         {
                             this.Facade.Children.Clear();
                         }));
                     }
                 }
                 return;
             }
             // Zoom Event.
             if (this.Target.Listen.ZoomEvent.Equals(msg.Chan))
             {
                 if (this.Allow)
                 {
                     if ((this.Level = this.Fusion(this.Target)) > -1)
                     {
                         Pixel middle = this.Crd2px(this.Target.Center);
                         if (!MatchUtils.IsEmpty(this.Nature))
                         {
                             // 缩略地图
                             this.Thumb((double)msg.Info, new Pixel(
                                            middle.X / (double)msg.Info - this.Nature.X,
                                            middle.Y / (double)msg.Info - this.Nature.Y
                                            ));
                             // 地图属性
                             this.Grasp(middle, this.Nature);
                         }
                         else
                         {
                             // 地图属性
                             this.Grasp(middle, this.Nature = new Nature());
                         }
                         // 延时重绘
                         if (this.Extent.Contain(this.Target, this.Target.Center))
                         {
                             this.Target.Thread.Attach(new MagicThread(StampUtils.GetSequence(), () =>
                             {
                                 {
                                     Thread.Sleep(700);
                                 }
                                 this.Build(this.Crd2px(this.Target.Center));
                             }));
                         }
                     }
                     else
                     {
                         if (!MatchUtils.IsEmpty(this.Nature))
                         {
                             this.Nature = null;
                             {
                                 this.Facade.Dispatcher.BeginInvoke(new Action(() =>
                                 {
                                     this.Facade.Children.Clear();
                                 }));
                             }
                         }
                     }
                 }
                 return;
             }
             // Swap Event.
             if (this.Target.Listen.SwapEvent.Equals(msg.Chan))
             {
                 Geog geog = msg.Info as Geog;
                 if (!geog.Cover || this.Equals(geog))
                 {
                     this.Redraw();
                 }
             }
         }
     }
 }
Esempio n. 8
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;
                     }
                 }
             }
         }
     }
 }