GreatMaps.Net 修改LQT——20101127
1、GPSData中可添加车辆数据并标注于MainMap中,ListView同步显示该车辆信息;
代码
double vehilceID = double.Parse(txtID.Text, CultureInfo.InvariantCulture);
double lat = double.Parse(txtLat.Text, CultureInfo.InvariantCulture);
double lng = double.Parse(txtLng.Text, CultureInfo.InvariantCulture);
GMapMarkerRect car = new GMapMarkerRect(new PointLatLng(lat, lng));
MainMap.Position = car.Position;
GMapMarkerGoogleGreen carMarker = new GMapMarkerGoogleGreen(car.Position);
{
carMarker.Tag = -1;
carMarker.VehicleID = vehilceID;
carMarker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
}
Placemark p = null;
if (checkBoxPlacemarkInfo.Checked)
{
p = GMaps.Instance.GetPlacemarkFromGeocoder(car.Position);
}
if (p != null)
{
carMarker.ToolTipText = p.Address;
}
else
{
carMarker.ToolTipText = car.Position.ToString();
}
objects.Markers.Add(carMarker);
ListViewItem lstview = new ListViewItem(carMarker.VehicleID.ToString());
listView1.Items.Add(lstview);
lstview.SubItems.Add(carMarker.Position.Lat.ToString());
lstview.SubItems.Add(carMarker.Position.Lng.ToString());
2、点击地图中车辆图标:车辆图标居中并显示该点位置信息、ListView选中相应项;
代码
if (item.Tag != null)
{
if (currentTransport != null)
{
currentTransport.ToolTipMode = MarkerTooltipMode.OnMouseOver;
currentTransport = null;
}
if (item.Tag.Equals(-1))
{
//车辆图标点击事件
MainMap.Position = item.Position;
foreach (ListViewItem i in this.listView1.Items)
{
if(double.Parse(i.Text).Equals(item.VehicleID))
{
i.Selected = true;
listView1.Focus();
}
}
//MessageBox.Show(string.Format("ID:{0}, 纬度: {1}, 经度: {2}", item.VehicleID, item.Position.Lat.ToString(), item.Position.Lng.ToString()));
}
currentTransport = item;
currentTransport.ToolTipMode = MarkerTooltipMode.Always;
}
3、ListView选择车辆信息:地图中相应车辆图标居中并显示该点位置信息;
代码
foreach(GMapMarker gmarker in objects.Markers)
{
if (gmarker.VehicleID.Equals(double.Parse(listView1.SelectedItems[0].Text)))
{
MainMap_OnMarkerClick(gmarker, e);
//MainMap.Position=gmarker.Position;
//gmarker.ToolTipMode = MarkerTooltipMode.Always;
}
}
if (e.Button == MouseButtons.Right && this.listView1.SelectedItems.Count > 0)
{
this.contextMenuStrip1.Show(this.listView1, e.Location);
}