-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheMapLayers.fs
More file actions
142 lines (125 loc) · 6.59 KB
/
CacheMapLayers.fs
File metadata and controls
142 lines (125 loc) · 6.59 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
module CacheMapLayers
open GMap.NET
open GMap.NET.WindowsForms
open GMap.NET.WindowsForms.Markers
open CachesModel
open CachesImages
type Marker = {
cache: Cache
position: PointLatLng
marker: GMapMarker}
let getPositionFromCoords (cache:Cache) =
match cache.CoordsToShow with | (a,b) -> PointLatLng(a,b)
let addLayer mapControl name =
let l = new GMapOverlay(mapControl, name)
mapControl.Overlays.Add(l)
l
let addToLayer point (cache:Cache) (layer:GMapOverlay) =
let cacheType = cache.Type
let found = cache.Found
let m = match cacheType with
| CacheType.Traditional -> new TraditionalCacheMarker(point) :> GeocachingImageMarker
| CacheType.MultiCache -> new MultiCacheMarker(point) :> GeocachingImageMarker
| CacheType.Mystery -> new MysteryCacheMarker(point) :> GeocachingImageMarker
| CacheType.Event -> new EventCacheMarker(point) :> GeocachingImageMarker
| CacheType.Whereigo -> new WhereigoCacheMarker(point) :> GeocachingImageMarker
| CacheType.Letter -> new LetterCacheMarker(point) :> GeocachingImageMarker
| CacheType.Earth -> new EarthCacheMarker(point) :> GeocachingImageMarker
| CacheType.Other -> new UnknownCacheMarker(point) :> GeocachingImageMarker
m.Found <- found
m.Id <- cache.Id
let coords = cache.CoordsToShow
let coordsOrig = cache.CoordsToShowOrig
m.ToolTipText <- cache.Id + " " + cache.Name + "\n" +
(cacheSizeToXString cache.Size) + " " + (cacheTypeToString cache.Type) + "\n" +
(fst coords).ToString("f6") + " " + (snd coords).ToString("f4") + "\n" +
coordsOrig +
(if cache.Notes <> null && cache.Notes.Length > 0 then "\n" + cache.Notes else "") +
(if not (System.String.IsNullOrEmpty(cache.Hint)) then "\nHint: " + cache.Hint else "")
m.ToolTip <- new CacheTooltip(m)
layer.Markers.Add(m)
{ marker = m; position = point; cache = cache }
let addCachesToLayer mapControl caches =
let layer = new GMapOverlay(mapControl, "caches")
let markers = caches
|> Array.filter (fun (cache:Cache) -> cache.HasValidCoords)
|> Array.map (fun (cache:Cache) -> (cache, getPositionFromCoords cache))
|> Array.map (fun cacheInfo -> match cacheInfo with | (cache, point) -> (addToLayer point cache layer))
mapControl.Overlays.Add(layer)
(layer, markers)
type ViewPort = {
left: float
right: float
top: float
bottom: float
}
let getMapControlSizes (mapControl:GMapControl) =
let left = mapControl.CurrentViewArea.Left
let right = left + mapControl.CurrentViewArea.WidthLng
let top = mapControl.CurrentViewArea.Top
let bottom = top - mapControl.CurrentViewArea.HeightLat
{ left = left; right = right; top = top; bottom = bottom }
let cacheIsInside viewPort (point:PointLatLng) =
viewPort.left <= point.Lng && point.Lng <= viewPort.right &&
viewPort.bottom <= point.Lat && point.Lat <= viewPort.top
let getVisibleObjects markers mapControl =
let viewPort = getMapControlSizes mapControl
markers |> Array.filter (fun m -> m.marker.IsVisible && (cacheIsInside viewPort m.position))
let getVisibleObjectsCount markers mapControl =
let viewPort = getMapControlSizes mapControl
markers
|> Array.fold (fun count m ->
match (cacheIsInside viewPort m.position) && m.marker.IsVisible with
| true -> count + 1
| _ -> count
)
0
(*let addCachesToLayers mapControl caches =
let getPositionFromCoords (cache:Cache) =
match cache.CoordsToShow with | (a,b) -> PointLatLng(a,b)
let addLayer mapControl name =
let l = new GMapOverlay(mapControl, name)
mapControl.Overlays.Add(l)
l
let layers = dict[
CacheType.Other, addLayer mapControl "oth"
CacheType.Whereigo, addLayer mapControl "whereigo"
CacheType.Letter, addLayer mapControl "letter"
CacheType.Earth, addLayer mapControl "earth"
CacheType.Event, addLayer mapControl "event"
CacheType.Mystery, addLayer mapControl "mystery"
CacheType.MultiCache, addLayer mapControl "multi"
CacheType.Traditional, addLayer mapControl "traditional"]
/// temporary
let addToLayer point (cache:Cache) =
let cacheType = cache.Type
let found = cache.Found
let m = match cacheType with
| CacheType.Traditional -> new TraditionalCacheMarker(point) :> GeocachingImageMarker
| CacheType.MultiCache -> new MultiCacheMarker(point) :> GeocachingImageMarker
| CacheType.Mystery -> new MysteryCacheMarker(point) :> GeocachingImageMarker
| CacheType.Event -> new EventCacheMarker(point) :> GeocachingImageMarker
| CacheType.Whereigo -> new WhereigoCacheMarker(point) :> GeocachingImageMarker
| CacheType.Letter -> new LetterCacheMarker(point) :> GeocachingImageMarker
| CacheType.Earth -> new EarthCacheMarker(point) :> GeocachingImageMarker
| CacheType.Other -> new UnknownCacheMarker(point) :> GeocachingImageMarker
m.Found <- found
m.Id <- cache.Id
let coords = cache.CoordsToShow
let coordsOrig = cache.CoordsToShowOrig
m.ToolTipText <- cache.Id + " " + cache.Name + "\n" +
(cacheSizeToXString cache.Size) + " " + (cacheTypeToString cache.Type) + "\n" +
(fst coords).ToString("f6") + " " + (snd coords).ToString("f4") + "\n" +
coordsOrig +
(if cache.Notes <> null && cache.Notes.Length > 0 then "\n" + cache.Notes else "") +
(if not (System.String.IsNullOrEmpty(cache.Hint)) then "\nHint: " + cache.Hint else "")
m.ToolTip <- new CacheTooltip(m)
layers.[cacheType].Markers.Add(m)
{ marker = m; cache = cache }
//let mutable markers = []
let markers = caches
|> Array.filter (fun (cache:Cache) -> cache.HasValidCoords)
|> Array.map (fun (cache:Cache) -> (cache, getPositionFromCoords cache))
|> Array.map (fun cacheInfo -> match cacheInfo with | (cache, point) -> (addToLayer point cache))
(layers, markers)
*)