2014-03-12 48 views
0

將kml文件加載到Google地球后,我試圖讓用戶從kml中單擊某個多邊形以突出顯示該多邊形。突出顯示或加固kml多邊形的邊界

到目前爲止,我可以記錄點擊事件,獲取事件類型(KmlPlacemark)並獲取它的kml標記。 我試着做類似於這個example的東西,他們在kmlObject的getFeatures上添加地標,但是target和type都沒有'getFeatures'。看過周圍的文檔,我想我可能要麼從Kml Polystyle類的setOutline或從KmlLineStyle類的setWidth(),但我不確定。另外當我嘗試像target.setOutline(true);它不起作用。

任何人都可以告訴我,如果我在正確的軌道上,暗示我做錯了什麼,以及是否有更好的方法來做到這一點?

function recordEvent(event) { 
      var target = event.getTarget(); 
      var type = target.getType(); 


      if(type == "KmlPolygon") { 
       alert("KMLPolygon "); 
      }else if(type == "KmlPlacemark") { 
       // // get the data you want from the target. 
       var description = target.getDescription(); 
       var balloon = target.getBalloonHtml(); 
       var outputKml = target.getKml(); 

       if ('getFeatures' in event) { 
        console.log("test"); 
        event.getFeatures().appendChild(placemark); 
       } 

       console.log("hello?") 
       // target.setOutline(true); 
       console.log(outputKml); 
      } 
     }; 

     google.earth.addEventListener(ge.getGlobe(), 'click', recordEvent); 

謝謝!

回答

0

我找到的最好的方式做你問是:

  1. 檢測點擊的事件,如你現在做

  2. 如果點擊,創建一個新的樣式,然後將其分配到目標

    var newStyle = ge.createStyle(''); 
    // Assign your Style's attributes such as LabelStyle and IconStyle 
    // eg to set the scale of your label 
    newStyle.getLabelStyle().setScale(2.5); 
    // Set the Style 
    target.setStyleSelector(newStyle); 
    

編輯在谷歌的例子此鏈接添加顯示它更深入 https://code.google.com/apis/ajax/playground/#styling_placemarks_using_style_maps