1: private bool _isActivated;
2: DispatcherTimer _dTimer;//use to control autoplay
3: private Border _Border;//stackpanel used to hold the slider and textblock
4: private CheckBox _chkboxAutoPlay;//auto paly animation?
5: private Slider _slider;//time slider
6: private TextBlock _textblock;//date textblock
7: private FeatureLayer _FLayer;//business layer
8: private GraphicsLayer _GLayerSymbol;//do nothing with Business FeatureLayer, using another graphicslayer to display symobls
9: private GraphicsLayer _GLayerText;//becuase the binding didn't work well in wp7 api, so using another textsymbol in a graphicslayer
10: //instead of a custom markersymbol with a text in it(using binding).
11: private double _salesmin, _salesmax;//use to determine symbol size
12: private enum SymbolSize
13: {
14: small=20,
15: middle=40,
16: large=60
17: }
18: public Map map1 { get; set; }
19: public bool IsActivated
20: {
21: get { return _isActivated; }
22: set
23: {
24: if (_isActivated != value)
25: {
26: _isActivated = value;
27: if (value)
28: {
29: SlidePanel(Visibility.Visible, TimeSpan.FromMilliseconds(300));
30: _FLayer.Visible = false;
31: map1.Layers.Add(_GLayerSymbol);
32: map1.Layers.Add(_GLayerText);
33: InitSymbols();
34: _chkboxAutoPlay.Visibility = Visibility.Visible;
35: _slider.ValueChanged += _slider_ValueChanged;
36: map1.ExtentChanged += map1_ExtentChanged;
37: }
38: else
39: {
40: SlidePanel(Visibility.Collapsed, TimeSpan.FromMilliseconds(300));
41: _FLayer.Visible = true;
42: map1.Layers.Remove(_GLayerText);
43: map1.Layers.Remove(_GLayerSymbol);
44: UnInitSymbols();
45: _chkboxAutoPlay.Visibility = Visibility.Collapsed;
46: map1.ExtentChanged -= map1_ExtentChanged;
47:
48: _slider.ValueChanged -= _slider_ValueChanged;
49: _chkboxAutoPlay.IsChecked = false;
50: _dTimer.Stop();
51: }
52: }
53: }
54: }
55:
56: /// <summary>
57: /// display or hide the time panel with a slide animation
58: /// </summary>
59: /// <param name="visible"></param>
60: /// <param name="duration"></param>
61: private void SlidePanel(Visibility visible, TimeSpan duration)
62: {
63: DoubleAnimation da = new DoubleAnimation();
64: da.Duration = duration;
65: if (visible == Visibility.Visible)
66: {
67: //_Border.Visibility = Visibility.Visible;
68: da.From = 0;
69: da.To = 100;
70: }
71: else
72: {
73: //_Border.Visibility = Visibility.Collapsed;
74: da.From = 100;
75: da.To = 0;
76: }
77: Storyboard sb = new Storyboard();
78: Storyboard.SetTarget(da, _Border);
79: Storyboard.SetTargetProperty(da, new PropertyPath("Height"));
80: sb.Children.Add(da);
81: sb.Begin();
82: }
83:
84: private void InitSymbols()
85: {
86: foreach (Graphic g in _FLayer.Graphics)
87: {
88: //determin symbol size
89: double size = -1;
90: if ((double)g.Attributes["D1101"] <= (_salesmax + _salesmin)/2 * 1 / 3)
91: size = (double)SymbolSize.small;
92: else if ((double)g.Attributes["D1101"] > (_salesmax + _salesmin) / 2 * 1 / 3 && (double)g.Attributes["D1101"] <= (_salesmax + _salesmin) / 2 * 2 / 3)
93: size = (double)SymbolSize.middle;
94: else
95: size = (double)SymbolSize.large;
96:
97: //change Businesslayer symbol to custom symbols and display in _GLayerSymbol for each store
98: Graphic gsymbol = new Graphic()
99: {
100: Geometry = g.Geometry,
101: Symbol = new PictureMarkerSymbol()
102: {
103: Source = new BitmapImage(new Uri("../Images/Dollar.png", UriKind.Relative)),
104: }
105: };
106:
107: (gsymbol.Symbol as PictureMarkerSymbol).Height = (gsymbol.Symbol as PictureMarkerSymbol).Width = size;
108: (gsymbol.Symbol as PictureMarkerSymbol).OffsetX = (gsymbol.Symbol as PictureMarkerSymbol).OffsetY = size / 2;
109: g.Attributes.Add("symbol", gsymbol);
110:
111: //add a graphic with textsymbol, which display sales, to _GLayerText for each store
112: Graphic gtext = new Graphic()
113: {
114: Geometry = g.Geometry,
115: Symbol = new TextSymbol()
116: {
117: Foreground = new SolidColorBrush(Color.FromArgb(225,255,255,255)),
118: Text = double.Parse(g.Attributes["D1101"].ToString()).ToString("###,###"),
119: OffsetX = -size / 2+15,
120: OffsetY = -size / 2+15,
121: FontSize=30
122: }
123: };
124: gtext.Symbol.ControlTemplate = (App.Current.Resources["LegendTextSymbol"] as TextSymbol).ControlTemplate;
125: g.Attributes.Add("text", gtext);
126:
127: _GLayerText.Graphics.Add(gtext);
128: _GLayerSymbol.Graphics.Add(gsymbol);
129: }
130: _GLayerText.Visible = false;
131: }