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; } }
/// <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(); } } } } }
/// <summary> /// GenreBoxList选项改变事件 /// </summary> /// <param name="obj"></param> /// <param name="evt"></param> private void GenreBox_SelectionChanged(object obj, SelectionChangedEventArgs evt) { ContentPresenter content = this.GenreBox_SelectionVisual <ContentPresenter>( this.GenreBox.ItemContainerGenerator.ContainerFromItem(this.GenreBox.SelectedItem) ); if (!MatchUtils.IsEmpty(content)) { Grid grid = null; try { grid = (Grid)content.ContentTemplate.FindName("GenreBoxItem", content); } catch { grid = null; } finally { if (grid != null) { switch ((string)this.GenreBoxGrid.Tag) { case "MAP": { Geog tile = null; try { tile = this.genre.Target.Symbol.Tile[grid.Tag as string]; } catch { tile = null; } finally { if (tile != null) { tile.Access(true); } } break; } case "LAP": { Geog pile = null; try { pile = this.genre.Target.Symbol.Pile[grid.Tag as string]; } catch { pile = null; } finally { if (pile != null) { pile.Access(!pile.Allow); } } break; } } } } } // 清空选中 this.GenreBox.SelectedItem = null; }
/// <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; } } } } } }
/// <summary> /// 构建控件 /// </summary> public void Build() { if (!this.ready && (this.ready = true)) { // 设置位置 if ("left".Equals(this.genre.Anchor)) { // 设置样式 this.GenreBox.Style = this.FindResource("GENRE_LIST_LEFT") as Style; { Canvas.SetTop(this, 18); Canvas.SetLeft(this, 18); // 适配位置 Grid.SetColumn(this.Genre1px, 0); Grid.SetColumn(this.GenreBox, 1); Grid.SetColumn(this.GenreBtnGrid, 0); Grid.SetColumn(this.GenreBoxGrid, 1); } } else { // 设置样式 this.GenreBox.Style = this.FindResource("GENRE_LIST_RIGHT") as Style; { Canvas.SetTop(this, 18); Canvas.SetRight(this, 53); // 适配位置 Grid.SetColumn(this.Genre1px, 1); Grid.SetColumn(this.GenreBox, 0); Grid.SetColumn(this.GenreBtnGrid, 1); Grid.SetColumn(this.GenreBoxGrid, 0); } this.GenreGrid.SizeChanged += new SizeChangedEventHandler((obj, evt) => { Canvas.SetRight(this, this.GenreGrid.ActualWidth + 18); }); } } // 重绘控件 if (Visibility.Visible.Equals(this.GenreBoxGrid.Visibility)) { List <GenreOption> genreList = new List <GenreOption>(); { switch ((string)this.GenreBoxGrid.Tag) { case "MAP": { this.GenreBoxGrid.Margin = new Thickness(0, 0, 0, 0); { Geog[] tiles = this.genre.Target.Symbol.Tile.Values.ToArray <Geog>(); for (int i = 1, l = tiles.Length; i <= l; i++) { Geog tile = tiles[i - 1]; { if (tile.Allow) { string radius = ( "left".Equals(this.genre.Anchor) ? ( l == 1 ? "0,5,5,0" : i == 1 ? "0,5,0,0" : i == l ? "0,0,5,5" : "0,0,0,0" ) : ( l == 1 ? "5,0,0,5" : i == 1 ? "5,0,0,0" : i == l ? "0,0,5,5" : "0,0,0,0" ) ); // 添加数据 if (tile.Equals(this.genre.Target.Netmap)) { genreList.Add( new GenreOption(tile.Index, tile.Title, "#0000FF", radius, this.FindResource("GENRE_07") as ImageSource) ); } else { genreList.Add( new GenreOption(tile.Index, tile.Title, "#000000", radius, this.FindResource("GENRE_08") as ImageSource) ); } } } } } break; } case "LAP": { this.GenreBoxGrid.Margin = new Thickness(0, 45, 0, 0); { Geog[] piles = this.genre.Target.Symbol.Pile.Values.ToArray <Geog>(); for (int i = 1, l = piles.Length; i <= l; i++) { Geog pile = piles[i - 1]; { string radius = ( "left".Equals(this.genre.Anchor) ? ( l == 1 ? "0,5,5,0" : i == 1 ? "0,5,0,0" : i == l ? "0,0,5,5" : "0,0,0,0" ) : ( l == 1 ? "5,0,0,5" : i == 1 ? "5,0,0,0" : i == l ? "0,0,5,5" : "0,0,0,0" ) ); // 添加数据 if (pile.Fusion(this.genre.Target) > -1 && pile.Extent.Contain(this.genre.Target, this.genre.Target.Center)) { if (pile.Allow) { genreList.Add( new GenreOption(pile.Index, pile.Title, "#0000FF", radius, this.FindResource("GENRE_09") as ImageSource) ); } else { genreList.Add( new GenreOption(pile.Index, pile.Title, "#000000", radius, this.FindResource("GENRE_10") as ImageSource) ); } } else { genreList.Add( new GenreOption(pile.Index, pile.Title, "#000000", radius, this.FindResource("GENRE_11") as ImageSource) ); } } } } break; } } // 绑定数据 this.GenreBox.ItemsSource = genreList; } } }