<< Click to Display Table of Contents >> Navigation: 3D API 說明範例 > 功能 > 查詢 > 點環域查詢 |
<說明>
在本範例中,我們將示範如何執行點環域查詢,說明如下:
<範例>
var earth_ = null; var VLayer = null;
function documentLoad() { document.body.style.overflow = "hidden"; SuperGIS.Initialize("/ServerGate/", function () { SuperGIS.ServerEarth.Initialize(InitEarth); }); }
function InitEarth() { var pBody = new SuperGIS.Windows.HTMLContainer(document.getElementById("example"));
var sHost = location.href; var idx = sHost.indexOf("/", 8); if (idx >= 0) sHost = sHost.substring(0, idx); CreateHTML5Earth(pBody, function (pEarth) { EarthLoaded(pEarth); });
function EarthLoaded(pEarth) { earth_ = pEarth; pEarth.Scene.BackgroundColor = pEarth.CreateColor(0, 0, 0, 1); pEarth.SetupSystem(true, s_WGS84); pEarth.SetupSkin(pEarth.CreateEnvelope(-180, 180, -90, 90, s_WGS84), sHost + "/ServerGate/Skin1.jpg"); pEarth.MajorGraticule.Visible = false; pEarth.MinorGraticule.Visible = false;
// 指定向量磚服務的 WMTS 網址, 欲加入的圖層名稱, 及 callback function 名稱 VLayer = new SuperGIS.VectorLayer(getDataServicePath() + 'project_block/SimpleWMTS.aspx', pEarth, { layer: '土地使用分區' }, LanduseFinish);
pEarth.SetViewpoint(120.656, 24.160, 500, 0, 50, true);
var pTObj = pEarth.GetObject(); pTObj.addEventListener("mousedown", QueryAttribute, false, true); // 引入 mousedown 事件 pTObj.addEventListener("mousemove", MouseMove, false); var pCam = pEarth.GetCamera(); pCam.addEventListener("changed", CameraChanged, false); // Camera 狀態改變時觸發 }
// 在 callback 中設定每個 feature 的符號樣式 function LanduseFinish(array) { var rv = 128, gv = 255, bv = 128; for (var i = 0; i < array.length; i++) { var mark = array[i]; var fc = earth_.CreateColor(rv / 255.0, gv / 255.0, bv / 255.0, 128 / 255.0); mark.ReplaceZ = 0.5; // 設定高程 (公尺) mark.DDDSymbol = earth_.CreateSimpleDDDFillSymbol(earth_.CreateModelMaterial(0, fc), null); } }
var pInfoWindow = null; function QueryAttribute(tEvent) {
if (pInfoWindow != null) { pInfoWindow.close(); pInfoWindow = null; }
if (tEvent.button != 2) // 使按左鍵無作用 return;
var pScene = earth_.GetScene(); var pCamera = earth_.GetCamera(); var pGlobe = earth_.GetGlobe();
var CurPosition = earth_.GetCurrentPosition(); var CurLocation = pGlobe.RayTest(pCamera.EyeAt, pCamera.Ray(CurPosition), 1, true); if (!CurLocation) return;
var pt = pGlobe.GeodeticFromCartesian(CurLocation); array = VLayer.BufferQuery(pt, 100); // 對此向量磚圖層進行環域查詢, 回傳查詢到的結果陣列 // BufferQuery 傳入中心坐標, 及 range (公尺)
if (array.length == 0) return;
var infoStr = '<table border="1">'; for (var i = 0; i < array.length; i++) { var pm = array[i]; var feaData = pm.GetFieldValues(); var text = ""; for (f in feaData) { text += f + ": "; text += feaData[f] + "; "; }
infoStr += "<tr><td>"; infoStr += "#" + parseInt(i + 1); infoStr += "</td><td>"; infoStr += text; infoStr += "</td></tr>"; } infoStr += '</table>';
pInfoWindow = new SuperGIS.InfoWindow(infoStr, pt, { maxWidth: 250, pixelOffsetX: 100, pixelOffsetY: 0 }); // 建立屬性視窗 pInfoWindow.open(earth_, document.getElementById("example")); }
function CameraChanged(tEvent) { // Camera 狀態改變就關掉視窗 if (pInfoWindow != null) { pInfoWindow.close(); pInfoWindow = null; } }
function MouseMove(tEvent) { var pScene = earth_.GetScene(); var pG = pScene.GetGraphics(2); pG.drawText("以滑鼠右鍵進行地面點選, 搜尋 100 公尺環域內的指定向量磚 feature", 20, 20, "black", "white", "18", "Consolas"); } } |
© 2017 Supergeo Technologies Inc.