Ejemplo n.º 1
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;
         }
     }
 }
Ejemplo n.º 2
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));
                     }));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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));
                 }
             }
         }
     }
 }
Ejemplo n.º 4
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();
                 }
             }
         }
     }
 }