實驗報告-4地圖圖形繪制_第1頁
實驗報告-4地圖圖形繪制_第2頁
實驗報告-4地圖圖形繪制_第3頁
實驗報告-4地圖圖形繪制_第4頁
實驗報告-4地圖圖形繪制_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、南京工程學(xué)院實 驗 報 告課程名稱 地理信息系統(tǒng) 實驗項目名稱 圖形繪制實驗 實驗學(xué)生班級 多媒體111 實驗學(xué)生姓名 梁同輝 學(xué)號 202110124 同組學(xué)生姓名 無 實驗時間 實驗地點 信息樓A213 實驗成績評定 指導(dǎo)教師簽字 年月日一、實驗?zāi)康暮鸵?理解地圖疊加層的概念并使用。包括:從數(shù)據(jù)庫動態(tài)獲取地圖的點,線,面數(shù)據(jù)并將數(shù)據(jù)傳到頁面中。將這些點組織成marker,polyline,polygon,要動態(tài)設(shè)置樣式。2上機調(diào)試之前必須攜帶已經(jīng)編寫完畢的程序源代碼,實驗過程中主要是進(jìn)行調(diào)試。3上機時間不足以完成實驗項目的同學(xué)利用課外時間做完所有項目。4根據(jù)所選實驗內(nèi)容完成實驗報告。二、

2、實驗主要儀器和設(shè)備計算機,操作系統(tǒng) Windows7,Visual Studio 2010 集成開發(fā)環(huán)境,BaiduMap API三、實驗方法與步驟(需求分析、算法設(shè)計思路、流程圖等) 1.設(shè)計思路 a.編寫 HTML 文件 b.引入Baidu Map API,實例并顯示地圖 c.創(chuàng)建數(shù)據(jù)庫表,插入覆蓋物的坐標(biāo)數(shù)據(jù) d.添加后臺代碼,操作數(shù)據(jù)庫,獲取數(shù)據(jù)庫的數(shù)據(jù) e.對數(shù)據(jù)庫數(shù)據(jù)進(jìn)行處理,格式化為一個字符串,存入Session 中,以提供給前臺使用 f.根據(jù) Session 中的數(shù)據(jù),添加對應(yīng)的覆蓋物到地圖上 2.開發(fā)步驟: a.打開 Visual Studio 2010,創(chuàng)建一個 Web 應(yīng)

3、用程序的工程, 并添加一個Web窗體,如下圖(圖一)所示:圖一:添加Web窗體 b.在 HTML 中,引入 Baidu Map API,添加 div 塊,設(shè)置頁面的樣 式,實例化地圖對象,代碼如下: <script type="text/javascript" src="http:/api.map.bai <style type="text/css"> body, html,#allmap width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"

4、微軟雅黑" #allmapheight: 600px; </style><div id="allmap"></div>var map = new BMap.Map("allmap");var point = new BMap.Point(118.886575, 31.927937); map.centerAndZoom(point, 15); c.創(chuàng)建數(shù)據(jù)庫OverlayDB)(圖二),添加Overlays和Position 表(圖三),插入覆蓋物的坐標(biāo)數(shù)據(jù),如下圖所示:圖二:創(chuàng)建OverlayDB數(shù)據(jù)庫圖三

5、:添加Overlays表和Position表 d.編寫MapOverlayDB.aspx.cs后臺代碼,在Page_Load函數(shù)中,連接數(shù)據(jù)庫,獲取數(shù)據(jù)庫的數(shù)據(jù),代碼如下: /獲取連接數(shù)據(jù)庫的字符串 string connectionString = WebConfigurationManager.Conn ectionStrings"ConnectionString".ConnectionString; /創(chuàng)建數(shù)據(jù)庫連接 SqlConnection connection = new SqlConnection(connection String); /判斷數(shù)據(jù)庫庫的狀態(tài)

6、if (connection.State = ConnectionState.Closed | connection.State = ConnectionState.Broken) /打開數(shù)據(jù)庫 connection.Open(); /創(chuàng)建命令對象 SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; /執(zhí)行數(shù)據(jù)查詢的 SQL 語句 cmd.CommandText = "select longitude, latitude fromPosTable" /查詢數(shù)據(jù) SqlDataAdapter sda

7、= new SqlDataAdapter(cmd); /創(chuàng)建數(shù)據(jù)集對象 DataSet ds = new DataSet(); /使用數(shù)據(jù)適配器查到的數(shù)據(jù)結(jié)果,填充數(shù)據(jù)集對象 sda.Fill(ds); /獲取數(shù)據(jù)集中的第一張數(shù)據(jù)表 DataTable dt = ds.Tables0; e.對數(shù)據(jù)庫數(shù)據(jù)進(jìn)行處理,格式化為一個字符串,存入Session中,以提供給前臺使用,代碼如下: /字符串清空 string posMsg = "" bool isFirst = true; string number = "" /遍歷數(shù)據(jù)表,將數(shù)據(jù)存入到 posMsg

8、字符串中 for (int i = 0; i < dt.Rows.Count; +i) if (isFirst) number = markerData.Rowsi"NO".ToString(); isFirst = !isFirst; if (number != markerData.Rowsi"NO".ToString() if (posMsg.Length > 0) posMsg = posMsg.Substring(0, posMsg.Length - 1); posMsg += ")" number = mark

9、erData.Rowsi"NO".ToString(); posMsg += markerData.Rowsi"longitude" + "," + markerData.Rowsi"latitude" + "|" if(posMsg.Length > 0) /判斷字符串中是否存有數(shù)據(jù) /將字符串中的最后一個逗號截掉 posMsg = posMsg.Substring(0, posMsg.Length - 1); /將獲取的數(shù)據(jù)存入 Session 中,便于前臺的使用 Session.Ad

10、d(keyName, posMsg); connection.Close(); /關(guān)閉數(shù)據(jù)口連接 f.根據(jù) Session 中的數(shù)據(jù),添加對應(yīng)的覆蓋物到地圖上,關(guān)鍵代碼如下: var markerPos = "<%=(Session"markerPos")%>" if (markerPos.length > 0) addMarkers(markerPos); /添加Marker覆蓋物 var polylinePos = "<%=(Session"polylinePos")%>" if

11、(polylinePos.length > 0) addPoly(polylinePos, "polyline"); /添加polyline覆蓋物 var polygonPos = "<%=(Session"polygonPos")%>" if (polygonPos.length > 0) addPoly(polygonPos, "polygon"); /添加polygon覆蓋物 /添加覆蓋物函數(shù) function addMarkers(positions) var posList = p

12、ositions.split(")"); /獲得坐標(biāo)值 for (var i = 0; i < posList.length; +i) /根據(jù)坐標(biāo),創(chuàng)建標(biāo)記 var pt = posListi.split(","); if (pt.length = 2) var marker = new BMap.Marker(new BMap.Point( pt0, pt1); / 創(chuàng)建點 marker.addEventListener("click", showMsg); map.addOverlay(marker); /增加點 4、 實驗

13、原始紀(jì)錄(源程序、數(shù)據(jù)結(jié)構(gòu)等)源代碼:/MapOverlayDB.aspx文件(前臺)<html xmlns="/1999/xhtml"><head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="initial-scale=1.0

14、, user-scalable=no" /><style type="text/css">body, html,#allmap width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微軟雅黑"#allmapheight: 600px;</style><script type="text/javascript" src="/api?v=2.0&ak=NOr

15、e0dKA9pG7pNwrnfdL6Uc2"></script> <title>圖形繪制實驗</title></head><body> <div id="allmap"></div></body></html><script type="text/javascript"> var map = new BMap.Map("allmap"); var point = new BMap.Point(118.

16、886575, 31.927937); map.centerAndZoom(point, 17); map.enableScrollWheelZoom(true); /獲取Session中的數(shù)據(jù) var markerPos = "<%=(Session"markerPos")%>" /如果數(shù)據(jù)不為空,調(diào)用添加marker的函數(shù) if (markerPos.length > 0) addMarkers(markerPos); var polylinePos= "<%=(Session"polylinePos&qu

17、ot;)%>" /如果數(shù)據(jù)不為空,調(diào)用添加polyline的函數(shù) if (polylinePos.length > 0) addPoly(polylinePos, “polyline”); /獲取Session中的數(shù)據(jù) var polygonPos = "<%=(Session"polygonPos ")%>" /如果數(shù)據(jù)不為空,調(diào)用添加polygon的函數(shù) if (polygonPos .length > 0) addPoly(polygonPos, “polygon” ); /定義添加marker的函數(shù) fun

18、ction addMarks(positions) var posList = positions.split(")"); /獲得坐標(biāo)值 for (var i = 0; i < posList.length; +i) /根據(jù)坐標(biāo),創(chuàng)建標(biāo)記 var pt = posListi.split(","); if (pt.length = 2) var marker = new BMap.Marker(new BMap.Point( pt0, pt1); / 創(chuàng)建點 map.addOverlay(marker); /增加點 /添加折線,多邊形覆蓋物函數(shù) fu

19、nction addPoly(positions, typeName) if (positions.length > 0) /符號”)”將每個折線,多邊形點集分開 var polys = positions.split(")"); for (var len=0; len<polys.length; +len) /符號”)”將坐標(biāo)點分開 var pList = positions.split("|"); var points = new Array(); var pt= null; for (var i=0; i<pList.length

20、; +i) /將點的經(jīng)度和緯度分開 pt= pListi.split(","); /將點存入points的點的集合中 points.push(new BMap.Point(pt0, pt1); /根據(jù)覆蓋物的類型,添加相應(yīng)的覆蓋物 if (typeName = "polyline") /創(chuàng)建折線覆蓋物 var polyline = new BMap.Polyline(points); polyline.enableEditing(); /將覆蓋物添加到地圖上 map.addOverlay(polyline); else if (typeName = &q

21、uot;polygon") /創(chuàng)建多邊形覆蓋物 var polygon = new BMap.Polygon(points); polygon.enableEditing(); /將覆蓋物添加到地圖上 map.addOverlay(polygon); </script>/MapDatabase.aspx.cs文件(后臺)protected void Page_Load(object sender, EventArgs e) /查詢marker覆蓋物的信息 string sqlString = "SELECT p.pid as NO, longitude, lat

22、itude FROM Overlays o, Position p WHERE o.typename='marker' and p.pid = o.id" SelectDB(sqlString, "markerPos"); /查詢polyline覆蓋物的信息 sqlString = "SELECT p.pid as NO, longitude, latitude FROM Overlays o, Position p WHERE o.typename='polyline' and p.pid = o.id" Se

23、lectDB(sqlString, "polylinePos"); /查詢polygon覆蓋物的信息 sqlString = "SELECT p.pid as NO, longitude, latitude FROM Overlays o, Position p WHERE o.typename='polygon' and p.pid = o.id" SelectDB(sqlString, "polygonPos"); /查詢數(shù)據(jù)庫數(shù)據(jù),并將數(shù)據(jù)格式化,存入Session中 private void SelectDB(

24、string sqlString, string keyName) /獲取連接數(shù)據(jù)庫的字符串 string connectionString = WebConfigurationManager.Conn ectionStrings"ConnectionString".ConnectionString; /創(chuàng)建數(shù)據(jù)庫連接 SqlConnection connection = new SqlConnection(connection String); /判斷數(shù)據(jù)庫庫的狀態(tài) if (connection.State = ConnectionState.Closed | conne

25、ction.State = ConnectionState.Broken) /打開數(shù)據(jù)庫 connection.Open(); /創(chuàng)建命令對象 SqlCommand cmd = new SqlCommand(); cmd.Connection = connection; /執(zhí)行數(shù)據(jù)查詢的SQL語句 cmd.CommandText = "select longitude, latitude from PosTable" /查詢數(shù)據(jù) SqlDataAdapter sda = new SqlDataAdapter(cmd); /創(chuàng)建數(shù)據(jù)集對象 DataSet ds = new D

26、ataSet(); /使用數(shù)據(jù)適配器查到的數(shù)據(jù)結(jié)果,填充數(shù)據(jù)集對象 sda.Fill(ds); /獲取數(shù)據(jù)集中的第一張數(shù)據(jù)表 DataTable dt = ds.Tables0; /字符串清空 string posMsg = "" bool isFirst = true; string number = "" /遍歷數(shù)據(jù)表,將數(shù)據(jù)存入到 posMsg 字符串中 for (int i = 0; i < dt.Rows.Count; +i) if (isFirst) number = markerData.Rowsi"NO".ToS

27、tring(); isFirst = !isFirst; if (number != markerData.Rowsi"NO".ToString() if (posMsg.Length > 0) posMsg = posMsg.Substring(0, posMsg.Length - 1); posMsg += ")" number = markerData.Rowsi"NO".ToString(); posMsg += markerData.Rowsi"longitude" + "," + mark

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論