GMap.NET开发技巧(十)-地图功能

2012年12月21日 By admin 分类: GPS系统

本章主要描述实现鹰眼功能,并需要控件哪些事件及设置方法。

介绍如何根据开发应用GMap.NET地图控件,实现鹰眼功能和具体代码展示。

实现步骤及代码介绍:

鹰眼需要一个大地图和小地图,这样就需要两个gMapControl控件,在根据个人需要增加panel控件作为填充地图控件框。

需要控件为:

    gMapControl1

    gMapControl2

    panel1

将gMapControl2添加到panel1并设置panel1边线样式BorderStyle=FixedSingle

gMapControl1 需要事件为:

    OnPositionChanged

    OnMapZoomChanged

    MouseDown

    MouseUp

gMapControl2 需要事件为:

    OnPositionChanged

    MouseDown

    MouseMove

    MouseUp

gMapControl1 事件设置代码:

private bool Mapleft1 = false;
private void gMapControl1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        Mapleft1 = true;
    }
}

private void gMapControl1_MouseUp(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        Mapleft1 = false;
    }
}

private void gMapControl1_OnPositionChanged(PointLatLng point)
{
    if (Mapleft1)
    {
        this.gMapControl2.Position = point; //设置小地图中心点
    }
}
private void gMapControl1_OnMapZoomChanged()
{
    double zoom = this.gMapControl1.Zoom - Convert.ToDouble(5);
    this.gMapControl2.Zoom = zoom; //设置地图缩放大小
}

gMapControl2  事件设置代码:

private bool Mapleft2 = false;
private void gMapControl2_MouseMove(object sender, MouseEventArgs e)
{
    lastPosition1 = this.gMapControl1.FromLocalToLatLng(e.X, e.Y);
}

private void gMapControl2_MouseUp(object sender, MouseEventArgs e)
{
    if (e.Button==MouseButtons.Left)
    {
        Mapleft2 = false;
    }
}

private void gMapControl2_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        this.gMapControl1.Position = lastPosition1; //鼠标单击设置gMapControl1.中心点
        Mapleft2 = true;
    }
}

private void gMapControl2_OnPositionChanged(PointLatLng point)
{
    if (Mapleft2)
    {
        this.gMapControl1.Position = point; //设置gMapControl1中心点
    }
}

 上述是根据本人项目实现介绍并利用事件来实现鹰眼功能,设置开始地图中心点和加载地图类型没有介绍。

标签:

4 条评论

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注