離線谷歌地圖的開發筆記(一)


      最近做一個項目,用到離線谷歌地圖的開發, 而現在谷歌地圖在中國的發展不是很完美,導致項目的定項遲遲不能決定。

后來使用了一個地圖插件mymapw.ocx,完美地解決了Winform窗體里非要加載webbrowse寫JScript的弊端。

     目前,項目已經實施,特將里面的地圖開發部分概要摘錄下來,供大家參考:

1.1 加載Mymap.ocx 地圖控件到c#的窗體上

二、先增加地圖的基本功能操作: 放大、縮小、移動、測量距離、測量面積

 

增加放大、縮小、移動地圖的代碼

private void tsbMax_Click(object sender, EventArgs e)
{
  MyMap1.SetMapOperateMode(30);//放大
}
private void tsbMin_Click(object sender, EventArgs e)
{
  MyMap1.SetMapOperateMode(20);//縮小
}
private void tsbMove_Click(object sender, EventArgs e)
{
  MyMap1.SetMapOperateMode(40);//移動
}
 
 
1.3 增加測量距離的代碼
private void tsbDistance_Click(object sender, EventArgs e)
{
  MyMap1.SetMapOperateMode(50);//測量距離
}
 增加測量面積的代碼
private void tsbArea_Click(object sender, EventArgs e)
{
  MyMap1.SetMapOperateMode(90);//測量面積
}
 
保存或修改標注點
private void btnPointSave_Click(object sender, EventArgs e)
{
  string strResult = null;
  string strPoiName = txtPoiName.Text;//名稱
  string strLongitude = txtJD.Text;   //經度
  string strLatitude = txtWD.Text;    //緯度
  string strCity = ComboCity.Text;    //所屬城市
  string strMinScale = cmbMin.Text;   //最小顯示級別
  string strMaxScale = cmbMax.Text;   //最大顯示級別
  string strFontName = ComboFont.Text;      //宋體
  string strFontSize = ComboFontSize.Text ; //字體大小
  string strFrontColor = m_Color.ToString();//字體顏色
  string strBmpFileName = "3.bmp";          //標記圖標所屬的文件名
  string strBmpIndex = txtBMPindex.Text;    //在圖標文件里的索引
  string strObjectID = txtInfo.Text;        //氣泡里顯示的文字
  string strID = "";
  int nID = 0;
  if( m_PointADDorEDITtype == 1)
  {//增加新標注
      m_PointAddID++;
      nID = m_PointAddID;
      strID = nID.ToString();
      strResult = strResult + strID + "," + strPoiName + "," + strCity + "," + strFontName + "," + strFontSize + ","
          + strFrontColor + "," + strMinScale + "," + strMaxScale + "," + strBmpFileName + "," + strBmpIndex + ","
          + strLongitude + "," + strLatitude + "," + strObjectID + "," + ";";
  }
  else if(m_PointADDorEDITtype == 2)
  {//修改標注
       nID = m_PointEditID;
      strID = nID.ToString();
      strResult = strResult + strID + "," + strPoiName + "," + strCity + "," + strFontName + "," + strFontSize + ","
          + strFrontColor + "," + strMinScale + "," + strMaxScale + "," + strBmpFileName + "," + strBmpIndex + ","
          + strLongitude + "," + strLatitude + "," + strObjectID + "," + ";";
  }

 

  //''標准的''{"116,lim,青島市,宋體,12,0,0,500,2.bmp,4,41896957,13454163,,;"}
  MyMap1.AddMyPoi(nID, strResult);
  MyMap1.DrawMap();
}
 
在標注點的單擊觸發事件OnSelectPoi函數里處理自己想要做的事情(例如單擊后彈出一個窗體,顯示該標注點的一些信息)
private void MyMap1_OnSelectPoi(object sender, AxMYMAPLib._DMyMapEvents_OnSelectPoiEvent e)
{
  int nID = e.nID;
  if(!m_bEditPointState)
  {
    FrmPic form = new FrmPic(nID);
    form.ShowDialog();
    MyMap1.SetMapOperateMode(40);// '''運動狀態
  }
}
 
另外,還有添加道路、透明圓形、透明多邊形、透明矩形、箭頭等函數, 第一次發表文章,先寫這么多吧,留着以后再整理。
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM