/
EntityMarker.cs
106 lines (95 loc) · 2.51 KB
/
EntityMarker.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Gms.Maps.Model;
using Android.Gms.Maps;
using System.Collections;
using Mappy.Common;
namespace Mappy
{
public class EntityMarker
{
static readonly Dictionary<BankEntity.Type, Dictionary<IconType, int>> Icons = new Dictionary<BankEntity.Type, Dictionary<IconType, int>> {
{BankEntity.Type.Atm,
new Dictionary<IconType, int> {
{ IconType.Micro, Resource.Drawable.atm_micro},
{ IconType.Small, Resource.Drawable.atm_small},
{ IconType.Medium, Resource.Drawable.atm_medium}
}
}, {BankEntity.Type.Branch,
new Dictionary<IconType, int> {
{ IconType.Micro, Resource.Drawable.branch_micro},
{ IconType.Small, Resource.Drawable.branch_small},
{ IconType.Medium, Resource.Drawable.branch_medium}
}
}
};
private MarkerOptions MarkerOptions;
private Marker Marker;
public BankEntity Entity {get; set;}
private MarkerType Type;
private IconType iconType;
public EntityMarker(BankEntity entity, IconType iconType)
{
this.Entity = entity;
this.MarkerOptions = new MarkerOptions ();
this.MarkerOptions.SetTitle (entity.Description());
this.MarkerOptions.SetPosition (new LatLng(entity.Latitude, entity.Longitude));
this.Type = MarkerType.Regular;
IconType = iconType;
}
public EntityMarker(BankEntity entity, IconType iconType, MarkerType markerType) : this(entity, iconType)
{
this.Type = markerType;
IconType = IconType.Closest;
}
public void AddMarkerTo(GoogleMap map)
{
Marker = map.AddMarker (this.MarkerOptions);
}
public IconType IconType {
get {
return iconType;
}
set {
iconType = value;
UpdateIconFromType();
}
}
void UpdateIconFromType ()
{
if (iconType == IconType.None) {
MarkerOptions.Visible (false);
if (Marker != null)
Marker.Visible = false;
} else {
var icon = EntityIconForIconType;
MarkerOptions.InvokeIcon (icon);
if (Marker != null) {
Marker.Visible = true;
Marker.SetIcon (icon);
}
}
}
public bool IsNearestToUser()
{
return this.Type == MarkerType.Nearest;
}
BitmapDescriptor EntityIconForIconType
{
get {
if (IconType == IconType.Closest)
return BitmapDescriptorFactory.DefaultMarker ();
else
return BitmapDescriptorFactory.FromResource(Icons [Entity.EntityType] [IconType]);
}
}
}
}