-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVariableLayerCollection.cs
More file actions
154 lines (133 loc) · 4.89 KB
/
VariableLayerCollection.cs
File metadata and controls
154 lines (133 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.Timers;
namespace SharpMap.Layers
{
/// <summary>
/// Types of layer collections
/// </summary>
public enum LayerCollectionType
{
/// <summary>
/// Layer collection for layers with datasources that are more or less static (e.g ShapeFiles)
/// </summary>
Static,
/// <summary>
/// Layer collection for layers with datasources that update frequently (e.g. moving vehicle)
/// </summary>
Variable,
/// <summary>
/// Layer collection for layers are completely opaque and use as Background (e.g. WMS, OSM)
/// </summary>
Background,
}
/// <summary>
/// Signature of function to handle VariableLayerCollectionRequery event
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">The arguments, <c>EventArgs.Empty</c> in all cases</param>
public delegate void VariableLayerCollectionRequeryHandler(object sender, EventArgs e);
/// <summary>
/// Layer collection
/// </summary>
/// TODO:REEVALUEATE
[Serializable]
public class VariableLayerCollection : LayerCollection
{
private readonly LayerCollection _staticLayers;
private static Timer _timer = null;
private static bool touchTest = false;
/// <summary>
/// Method to restart the internal Timer
/// </summary>
public static void TouchTimer()
{
if (touchTest == true)
{
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(OnRequery));
_timer.Start();
}
else
{
touchTest = true;
}
}
/// <summary>
/// Event fired every <see cref="Interval"/> to force requery;
/// </summary>
public static event VariableLayerCollectionRequeryHandler VariableLayerCollectionRequery;
/// <summary>
/// Creates an instance of this class
/// </summary>
/// <param name="staticLayers">Layer collection that holds static layers</param>
public VariableLayerCollection(LayerCollection staticLayers)
{
_staticLayers = staticLayers;
if (_timer == null)
{
_timer = new Timer();
_timer.Interval = 500;
_timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
}
}
static void TimerElapsed(object sender, ElapsedEventArgs e)
{
touchTest = false;
OnRequery(null);
if (touchTest == false)
{
_timer.Stop();
touchTest = true;
}
}
/// <inheritdoc/>
protected override void InsertItem(int index, ILayer layer)
{
if (layer == null)
throw new ArgumentNullException("layer", "The passed argument is null or not an ILayer");
TestLayerPresent(_staticLayers, layer);
base.InsertItem(index, layer);
}
/*
protected override void OnAddingNew(System.ComponentModel.AddingNewEventArgs e)
{
ILayer newLayer = (e.NewObject as ILayer);
if (newLayer == null) throw new ArgumentNullException("value", "The passed argument is null or not an ILayer");
TestLayerPresent(_staticLayers, newLayer);
base.OnAddingNew(e);
}
*/
private static void TestLayerPresent(IEnumerable<ILayer> layers, ILayer newLayer)
{
foreach (var layer in layers)
{
var comparison = String.Compare(layer.LayerName,
newLayer.LayerName, StringComparison.CurrentCultureIgnoreCase);
if (comparison == 0) throw new DuplicateLayerException(newLayer.LayerName);
}
}
private static void OnRequery(object obj)
{
if (Pause) return;
if (VariableLayerCollectionRequery != null)
VariableLayerCollectionRequery(null, EventArgs.Empty);
}
/// <summary>
/// Gets/sets the interval in which to update layers
/// </summary>
public static double Interval
{
get { return _timer.Interval; }
set { _timer.Interval = value; }
}
private static bool _pause;
/// <summary>
/// Gets/Sets whether this collection should currently be updated or not
/// </summary>
public static bool Pause
{
get { return _pause; }
set { _pause = value; }
}
}
}