This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
Form1.cs
56 lines (49 loc) · 1.82 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraMap;
using DevExpress.Map;
namespace MoveMapItems {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
InitMap();
}
MapPushpin pin;
private void InitMap() {
VectorItemsLayer vlayer = (VectorItemsLayer)this.mapControl1.Layers["ShapefileLayer"];
ShapefileDataAdapter data = new ShapefileDataAdapter();
data.FileUri = new Uri(string.Format("file:///{0}/Countries.shp", Environment.CurrentDirectory));
vlayer.Data = data;
}
private void mapControl1_MouseDown(object sender, MouseEventArgs e) {
MapHitInfo info = this.mapControl1.CalcHitInfo(e.Location);
if (info.InMapPushpin) {
this.mapControl1.EnableScrolling = false;
foreach (object obj in info.HitObjects) {
if (obj.GetType() == typeof(MapPushpin))
pin = (MapPushpin)obj;
}
}
}
private void mapControl1_MouseMove(object sender, MouseEventArgs e) {
if (pin != null) {
CoordPoint point = this.mapControl1.ScreenPointToCoordPoint(new MapPoint(e.X, e.Y));
pin.Location = point;
}
}
private void mapControl1_MouseUp(object sender, MouseEventArgs e) {
if (pin != null) {
CoordPoint point = this.mapControl1.ScreenPointToCoordPoint(new MapPoint(e.X, e.Y));
pin.Location = point;
this.mapControl1.EnableScrolling = true;
pin = null;
}
}
}
}