Announcement

Collapse
No announcement yet.

Automatically center on loaded KML Layer

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatically center on loaded KML Layer

    When loading an KML, I want the globe centered to it.

    In the KML Example there is a layer tree. When clicking on the KML layer, it will move and center to the KML.
    We do not have the layer tree in our application, nor do we want to. So we need to do this automatically.

    I have taken some code from the KML Example for loading the KML.
    I have not implemented any of the controllers in the example: KMLApplicationController, HotSpotController BalloonController, KMLOrbitViewController, KMLFlyViewController.

    I have a worker thread that is loading the KML from an URL (just as in the KML Example). There is no user interaction, as the URL is to come from a service. I have copied the addKMLLayer() from KMLApplicationController.

    Code:
    public void addKMLLayer(final KMLRoot kmlRoot) {
        final KMLController kmlController = new KMLController(kmlRoot);
        final RenderableLayer layer = new RenderableLayer();
        layer.setName((String) kmlRoot.getField(AVKey.DISPLAY_NAME));
        layer.addRenderable(kmlController);
        wwd.getModel().getLayers().add(layer);
    }
    I tried to move to the KML Feature/View after adding it:
    Code:
    final KMLViewController viewController = KMLViewController.create(this.wwd);
    viewController.goTo(kmlRoot.getFeature().getView());
    wwd.redraw();
    This causes an NullPointerException. I guess it is because the KML Layer is not really added yet?

    Any suggestion how to make this work?


    I tried to implement the KMLApplicationController (As from the KML Example).
    In there is an onNetworkLinkRefreshed that should move to the KML Feature/View. It is supposedly called from the propertyChange, but it is never called.
    Called from <code>propertyChange</code> when a <code>KMLNetworkLink</code> sends a
    <code>{@link gov.nasa.worldwind.avlist.AVKey#RETRIEVA L_STATE_SUCCESSFUL}</code> property
    change event. This attempts to fly to a view associated with the link's KML resource.

    Edit:
    Does NASA WorldWind support KML Placemarks to automatically move the globe to the mentioned longitude/latitude/altitude ?
    I tried adding the following Placemark, but the globe did not move to the Pin I place at these coordinates.
    Code:
      <Placemark>
        <name>Office</name>
        <Camera>
          <longitude>18.9831740870744</longitude>
          <latitude>69.6733605620846</latitude>
          <altitude>859.40073428617</altitude>
          <heading>-5.895643440795316</heading>
          <tilt>16.25689583383909</tilt>
          <roll>4.164452826100321</roll>
          <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
        </Camera>
        <styleUrl>#m_ylw-pushpin</styleUrl>
        <Point>
          <gx:drawOrder>1</gx:drawOrder>
          <coordinates>18.98219841358436,69.67664216665221,0</coordinates>
        </Point>
      </Placemark>
    Last edited by DJViking; 10-15-2020, 12:43 PM.
Working...
X