No announcement yet.

Automatically center on loaded KML Layer

  • 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.

    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));
    I tried to move to the KML Feature/View after adding it:
    final KMLViewController viewController = KMLViewController.create(this.wwd);
    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.

    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.
    Last edited by DJViking; 10-15-2020, 12:43 PM.