Issue using NetworkLinkControl for updates in GE plugin

南楼画角 提交于 2019-12-24 10:07:24

问题


I'm using KML to load an image overlay, and then I'm trying to change camera view values such as altitude using NetworkLinkControl. None of my NetworkLinkControl updates are reflected in the GE plugin. I've done quite a bit of research on this issue to no avail. Any help would be appreciated.

Here are the details:

The process starts with loading a NetworkLink KML file:

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

inside which the .appendChild() is done like this:

    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
            }
        }
    });

The .fetchKml() above loads the following 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>

Each of the two NetworkLink loads it's own KML file through URLs defined in <Link>.

First one is My Photo (overlay) 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>

The second one is Updater 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>

The GE plugin now has the KMLs loaded, the placemark is placed at the specified coordinates, and double clicking the placemark enters the photo view mode.

To change the photo's altitude, javascript API requests the update:

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

The server responds (indicated in server log) with 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>

This should work because:

  1. <refreshMode>onChange</refreshMode> is set for the Updater <NetworkLink> in KML 1, and networkLinkControl.getLink().setHref() is making the change.
  2. <PhotoOverlay targetId="image_10000244"> in KML 4 is correctly targeting <PhotoOverlay id="image_10000244"> in KML 2
  3. <targetHref> in KML 4 is targeting the correct <href> in KML 1

GE plugin however doesn't display the altitude change. I've tried changing this value through javascript API, which works. But why isn't the KML method working? Any ideas would be appreciated.


回答1:


Try targetting the Camera element itself, not the PhotoOverlay parent. KML Updates in Google Earth don't see to work so well when you are trying to make changes a couple levels down from the targeted parent.

In other words, I would try this:

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>

and then in your 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>

In general, it's best to target the immediate parent of the simple element you want to change. Cascading updates don't work so well.

I would also recommend that you try this in pure KML in Google Earth itself to see if it works. Then, after the NLC update is performed, you can copy out the PhotoOverlay and paste the code into your editor and see if the change was applied correctly.

Let me know if that works...



来源:https://stackoverflow.com/questions/8496426/issue-using-networklinkcontrol-for-updates-in-ge-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!