Files
@ 65c134a3d619
Branch filter:
Location: seniordesign-ui/GMap.NET.Core/GMap.NET.Internals/Tile.cs
65c134a3d619
3.2 KiB
text/x-csharp
Initial import of mapping source (huge commit)
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 |
namespace GMap.NET.Internals
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
/// <summary>
/// represent tile
/// </summary>
public struct Tile : IDisposable
{
public static readonly Tile Empty = new Tile();
GPoint pos;
int zoom;
PureImage[] overlays;
long OverlaysCount;
public readonly bool NotEmpty;
public Tile(int zoom, GPoint pos)
{
this.NotEmpty = true;
this.zoom = zoom;
this.pos = pos;
this.overlays = null;
this.OverlaysCount = 0;
}
public IEnumerable<PureImage> Overlays
{
get
{
#if PocketPC
for (long i = 0, size = OverlaysCount; i < size; i++)
#else
for (long i = 0, size = Interlocked.Read(ref OverlaysCount); i < size; i++)
#endif
{
yield return overlays[i];
}
}
}
internal void AddOverlay(PureImage i)
{
if (overlays == null)
{
overlays = new PureImage[4];
}
#if !PocketPC
overlays[Interlocked.Increment(ref OverlaysCount) - 1] = i;
#else
overlays[++OverlaysCount - 1] = i;
#endif
}
internal bool HasAnyOverlays
{
get
{
#if PocketPC
return OverlaysCount > 0;
#else
return Interlocked.Read(ref OverlaysCount) > 0;
#endif
}
}
public int Zoom
{
get
{
return zoom;
}
private set
{
zoom = value;
}
}
public GPoint Pos
{
get
{
return pos;
}
private set
{
pos = value;
}
}
#region IDisposable Members
public void Dispose()
{
if (overlays != null)
{
#if PocketPC
for (long i = OverlaysCount - 1; i >= 0; i--)
#else
for (long i = Interlocked.Read(ref OverlaysCount) - 1; i >= 0; i--)
#endif
{
#if !PocketPC
Interlocked.Decrement(ref OverlaysCount);
#else
OverlaysCount--;
#endif
overlays[i].Dispose();
overlays[i] = null;
}
overlays = null;
}
}
#endregion
public static bool operator ==(Tile m1, Tile m2)
{
return m1.pos == m2.pos && m1.zoom == m2.zoom;
}
public static bool operator !=(Tile m1, Tile m2)
{
return !(m1 == m2);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
|