2011-12-13 80 views
1

我正在使用KML加載圖像疊加層,然後我試圖使用NetworkLinkControl更改相機視圖值(如高度)。我的NetworkLinkControl更新沒有反映在GE插件中。我在這個問題上做了很多研究,但沒有成功。任何幫助,將不勝感激。使用NetworkLinkControl進行GE插件更新的問題

下面是詳細信息:

google.earth.fetchKml(ge, href, function(kmlObject) { ... 

其內部.appendChild()像這樣做:

walkKmlDom(kmlObject, function() { 
     if(this.getType().match('KmlNetworkLink')) { 
      ge.getFeatures().appendChild(this); 

      //There are 2 NetworkLinks 
      if(this.getLink().getHref().match('nodesc')) { 
       networkLinkPhoto = this; 
      } 
      else if(this.getLink().getHref().match('control')){ 
       networkLinkControl = this; //will use this for updates later 
      } 
     } 
    }); 

.fetchKml()上述載荷

的過程與加載網絡鏈接KML文件開始以下KML 1:

<kml xmlns="http://www.opengis.net/kml/2.2"> 
     <Document> 
      <name>Photos</name> 
      <open>1</open> 
      <Style id="photoStyle"> 
       <IconStyle> 
        <Icon> 
         <href>http://hostname/images/ge_icon.png</href> 
        </Icon> 
       </IconStyle> 
       <BalloonStyle> 
        <text>$[description]</text> 
       </BalloonStyle> 
      </Style> 
      <Folder> 
       <name>My Photo</name> 
       <open>1</open> 
       <visibility>1</visibility> 
       <NetworkLink> 
        <name>My Photo</name> 
        <open>1</open> 
        <Link> 
         <href>http://hostname/images/10000244.kml?auth_key=e34962fce2df4829b0e86870c9e834da&amp;nodesc=1</href> 
        </Link> 
       </NetworkLink> 
       <NetworkLink> 
        <name>Updater</name> 
        <Link> 
         <href>http://hostname/placements/10000244/control?auth_key=e34962fce2df4829b0e86870c9e834da</href> 
         <refreshMode>onChange</refreshMode> 
        </Link> 
       </NetworkLink> 
      </Folder> 
     </Document> 
    </kml> 

兩個NetworkLink都通過<Link>中定義的URL加載它自己的KML文件。

第一個是我的照片(覆蓋)KML 2:

<kml xmlns="http://www.opengis.net/kml/2.2"> 
     <Document> 
      <name>Photos</name> 
      <open>1</open> 
      <Style id="photoStyle"> 
       <IconStyle> 
        <Icon> 
         <href>http://hostname/images/ge_icon.png</href> 
        </Icon> 
       </IconStyle> 
       <BalloonStyle> 
        <text>$[description]</text> 
       </BalloonStyle> 
      </Style> 
      <PhotoOverlay id="image_10000244"> 
       <name>My Photo</name> 
       <Snippet maxLines="1"> 
        <![CDATA[<a href="#image_10000244">Enter Photo</a>]]> 
       </Snippet> 
       <Camera> 
        <longitude>-122.668</longitude> 
        <latitude>45.5069</latitude> 
        <altitude>1.0</altitude> 
        <heading>66.0</heading> 
        <tilt>90.0</tilt> 
        <roll>0.0</roll> 
       </Camera> 
       <styleUrl>#photoStyle</styleUrl> 
       <color>feffffff</color> 
       <Icon> 
        <href>http://hostname/get_ge_tile/10000244/$[level]/$[y]/$[x]?auth_key=e34962fce2df4829b0e86870c9e834da</href> 
       </Icon> 
       <rotation>0.0</rotation> 
       <ViewVolume> 
        <leftFov>-17.5</leftFov> 
        <rightFov>17.5</rightFov> 
        <bottomFov>0.0</bottomFov> 
        <topFov>17.5</topFov> 
        <near>550.0</near> 
       </ViewVolume> 
       <ImagePyramid> 
        <tileSize>256</tileSize> 
        <maxWidth>16000</maxWidth> 
        <maxHeight>8000</maxHeight> 
        <gridOrigin>upperLeft</gridOrigin> 
       </ImagePyramid> 
       <Point> 
        <coordinates>-122.668,45.5069</coordinates> 
       </Point> 
       <shape>sphere</shape> 
      </PhotoOverlay> 
     </Document> 
    </kml> 

第二個是更新KML 3:

<kml xmlns="http://www.opengis.net/kml/2.2"> 
     <Document> 
      <name>Photos</name> 
      <open>1</open> 
      <Style id="photoStyle"> 
       <IconStyle> 
        <Icon> 
         <href>http://hostname/images/ge_icon.png</href> 
        </Icon> 
       </IconStyle> 
       <BalloonStyle> 
        <text>$[description]</text> 
       </BalloonStyle> 
      </Style> 
      <NetworkLinkControl> 
       <Update> 
        <targetHref>http://hostname/images/10000244.kml?auth_key=e34962fce2df4829b0e86870c9e834da&amp;nodesc=1</targetHref> 
        <Change> 
         <PhotoOverlay targetId="image_10000244"> 

          <Camera></Camera> 
          <ViewVolume></ViewVolume> 
          <Point></Point> 
         </PhotoOverlay> 
        </Change> 
       </Update> 
      </NetworkLinkControl> 
     </Document> 
    </kml> 

GE的插件現在已加載的KML,地標放置在指定座標的 處,然後雙擊地標進入照片 查看模式。

要改變照片的高度,JavaScript的API請求更新:

var updateHref='http://http://hostname/netlinkcontrol/10000244?&altitude=55&auth_key=e34962fce2df4829b0e86870c9e834da' 
networkLinkControl.getLink().setHref(updateHref); 

服務器響應以KML 4(在服務器日誌所示):

<kml xmlns="http://www.opengis.net/kml/2.2"> 
     <Document> 
      <name>Photos</name> 
      <open>1</open> 
      <Style id="photoStyle"> 
       <IconStyle> 
        <Icon> 
         <href>http://hostname/images/ge_icon.png</href> 
        </Icon> 
       </IconStyle> 
       <BalloonStyle> 
        <text>$[description]</text> 
       </BalloonStyle> 
      </Style> 
      <NetworkLinkControl> 
       <Update> 
        <targetHref>http://hostname/images/10000244.kml?auth_key=e34962fce2df4829b0e86870c9e834da&amp;nodesc=1</targetHref> 
        <Change> 
         <PhotoOverlay targetId="image_10000244"> 

          <Camera> 

           <altitude>55</altitude> 
          </Camera> 
          <ViewVolume></ViewVolume> 
          <Point></Point> 
         </PhotoOverlay> 
        </Change> 
       </Update> 
      </NetworkLinkControl> 
     </Document> 
    </kml> 

這應該工作,因爲:

  1. <refreshMode>onChange</refreshMode>設置爲更新器<NetworkLink>在KML 1中,networkLinkControl.getLink().setHref()正在進行更改。
  2. 在KML 4
  3. <PhotoOverlay targetId="image_10000244">正確在KML 2
  4. <targetHref>在KML 4靶向<PhotoOverlay id="image_10000244">在KML 1

GE插件定位到正確<href>但是不顯示海拔高度變化。我試着通過JavaScript API改變 這個值,它可以工作。但爲什麼KML 方法不起作用?任何想法,將不勝感激。

回答

1

嘗試定位相機元素本身,而不是PhotoOverlay父項。當您嘗試對目標父級進行幾個級別的更改時,Google地球中的KML更新看起來效果不佳。

換句話說,我想試試這個:

KML 1

<PhotoOverlay id="image_10000244"> 
    <name>My Photo</name> 
    <Snippet maxLines="1"> 
     <![CDATA[<a href="#image_10000244">Enter Photo</a>]]> 
    </Snippet> 
    <Camera id="image_10000244_camera"> 
     <longitude>-122.668</longitude> 
     <latitude>45.5069</latitude> 
     <altitude>1.0</altitude> 
     <heading>66.0</heading> 
     <tilt>90.0</tilt> 
     <roll>0.0</roll> 
    </Camera> 
    <ViewVolume id="image_10000244_viewvol" /> 
</PhotoOverlay> 

,然後在networklinkupdate:

<NetworkLinkControl> 
    <Update> 
    <targetHref>http://hostname/images/10000244.kml?auth_key=e34962fce2df4829b0e86870c9e834da&amp;nodesc=1</targetHref> 
    <Change> 
     <Camera targetId="image_10000244"> 
     <altitude>55</altitude> 
     </Camera> 
    </Change> 
    <Change> 
     <ViewVolume targetId="image_10000244_viewvol"> 
     <!-- new values --> 
     </ViewVolume> 
    </Change> 
    </Update> 
</NetworkLinkControl> 

在一般情況下,這是最好的目標的直接父你想改變的簡單元素。級聯更新不能很好地工作。

我也建議您在Google地球本身中使用純KML來試試這個功能是否有效。然後,在執行NLC更新後,您可以複製PhotoOverlay並將代碼粘貼到您的編輯器中,然後查看是否正確應用了更改。

讓我知道這是否有效...