首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 呼叫 Google Earth COM API 開發(四):PlaceMarks 讀取與管理

     編輯:關於C語言

Google Earth COM API 提供 GetMyPlaces()(我的位置)與 GetTemporaryPlaces()(臨時位置)兩個方法。本文示範讀取並以樹狀結構顯示,支援勾選控制顯示/隱藏。

核心程式碼

protected void ShowPlaces() {
    Thread.Sleep(500);
    FeatureGE myPlace = GeApp.GetMyPlaces();
    FeatureGE tempPlace = GeApp.GetTemporaryPlaces();
    var places = new List<FeatureGE> { myPlace, tempPlace };
    GetToolPad().ShowPlaces(places);
}

public void ShowPlaces(List<FeatureGE> places) {
    if (this.InvokeRequired) this.Invoke(new Action(() => InternalShowPlaces(places)));
    else InternalShowPlaces(places);
}

protected void InternalShowPlaces(List<FeatureGE> places) {
    tvPlaces.Nodes.Clear();
    if (places == null || places.Count <= 0) return;
    foreach (FeatureGE place in places) {
        TreeNode node = new TreeNode(place.Name) { Checked = place.Visibility > 0, Tag = place };
        ShowChildrenPlaces(place, node);
        node.Expand();
        tvPlaces.Nodes.Add(node);
    }
}

protected void ShowChildrenPlaces(FeatureGE place, TreeNode node) {
    foreach (FeatureGE child in place.GetChildren()) {
        TreeNode tn = new TreeNode(child.Name) { Checked = child.Visibility > 0, Tag = child };
        ShowChildrenPlaces(child, tn);
        node.Nodes.Add(tn);
    }
}

結構與圖層顯示邏輯一致,複用性高。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved