-
Notifications
You must be signed in to change notification settings - Fork 2
/
Form1.cs
78 lines (65 loc) · 2.88 KB
/
Form1.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
using System;
using System.Windows.Forms;
using DevExpress.XtraMap;
using System.IO;
using System.Drawing;
using System.Diagnostics;
namespace CustomProvider {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
// Create a map control, set its dock style and add it to the form.
MapControl map = new MapControl();
map.Dock = DockStyle.Fill;
this.Controls.Add(map);
// Create a layer to load image tiles from a local map data provider.
ImageLayer imageTilesLayer = new ImageLayer();
map.Layers.Add(imageTilesLayer);
imageTilesLayer.DataProvider = new LocalProvider();
}
public class LocalProvider : MapDataProviderBase {
readonly SphericalMercatorProjection projection = new SphericalMercatorProjection();
public LocalProvider() {
TileSource = new LocalTileSource(this);
}
public override ProjectionBase Projection {
get {
return projection;
}
}
public override MapSize GetMapSizeInPixels(double zoomLevel) {
double imageSize;
imageSize = LocalTileSource.CalculateTotalImageSize(zoomLevel);
return new MapSize(imageSize, imageSize);
}
protected override Size BaseSizeInPixels {
get { return new Size(Convert.ToInt32(LocalTileSource.tileSize * 2), Convert.ToInt32(LocalTileSource.tileSize * 2)); }
}
}
public class LocalTileSource : MapTileSourceBase {
public const int tileSize = 256;
public const int maxZoomLevel = 2;
string directoryPath;
internal static double CalculateTotalImageSize(double zoomLevel) {
if (zoomLevel < 1.0)
return zoomLevel * tileSize * 2;
return Math.Pow(2.0, zoomLevel) * tileSize;
}
public LocalTileSource(ICacheOptionsProvider cacheOptionsProvider) :
base((int)CalculateTotalImageSize(maxZoomLevel), (int)CalculateTotalImageSize(maxZoomLevel), tileSize, tileSize, cacheOptionsProvider) {
DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory());
directoryPath = dir.Parent.Parent.FullName;
}
public override Uri GetTileByZoomLevel(int zoomLevel, int tilePositionX, int tilePositionY) {
if (zoomLevel <= maxZoomLevel) {
Uri u = new Uri(string.Format("file://" + directoryPath + "\\openstreetmap.org\\Hybrid_{0}_{1}_{2}.png", zoomLevel, tilePositionX, tilePositionY));
return u;
}
return null;
}
}
}
}