AnsweredAssumed Answered

Only the first placemark of KML files being rendered

Question asked by Lunaari on Apr 21, 2019
Latest reply on Apr 26, 2019 by cshi-esristaff

I've spent way too long on this to not seek help. I'm retrieving KML files from SPC Shapefile/KML Links. Every time I draw these files, only the geometry held within the first placemark of the file is added to the KML layer. For reference, these KML files have the following structure:

   Document / Folder (one or two) / Placemarks (multiple)

This is frustrating because through some exploration, I can find the geometry from each KML placemark at the android runtime, but I still can't plot it as a layer. It is also important to note that the first placemark of all the root folders will be drawn. So if there are 2 folders each containing 5 placemarks, I'll get 2 layers added, not 10 like I would prefer.

 

@Override
    protected void onCreate(Bundle savedInstanceState) {
        //SetLicense removed for privacy       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        mMapView = findViewById(R.id.mapView);
        setupMap();

        Button outlookButton = findViewById(R.id.otlkBtn);

        outlookButton.setOnClickListener(v -> {
            getKmlData("https://www.spc.noaa.gov/products/outlook/day1otlk_cat.kml");

        });
    }

    private void setupMap() {
        if (mMapView != null) {
            // Get Map Style
            String myLayerId = "9b7f5bb66660427eae788a0a9097c8a8";
            Portal portalService = new Portal("https://www.arcgis.com", false);
            PortalItem portalItemLayer = new PortalItem(portalService, myLayerId);

            ArcGISVectorTiledLayer myCustomTileLayer = new
            ArcGISVectorTiledLayer(portalItemLayer);
            ArcGISMap map = new ArcGISMap(new Basemap(myCustomTileLayer));
            mMapView.setMap(map);
            mMapView.setAttributionTextVisible(false);
            setupLocationDisplay();
        }
    }


    private void getKmlData(String url) {
        KmlDataset kmlDataset = new KmlDataset(url);
        KmlLayer kmlLayer = new KmlLayer(kmlDataset);
       
        //
        for (KmlNode node : kmlDataset.getRootNodes()) {
            for (KmlNode subnode : ((KmlDocument) node).getChildNodes()) {
                if(subnode instanceof KmlFolder) {
                    for (KmlNode subsubnode : ((KmlFolder) subnode).getChildNodes()) {
                        subsubnode.setVisible(true);
                        if (subsubnode instanceof KmlPlacemark) {
                            System.out.println(subsubnode.getSnippet());
                            System.out.println(subsubnode.getName());
                            subsubnode.setVisible(true);
                            mMapView.getMap().getOperationalLayers().add(KmlLayer);
                        }
                    }
                }
            }
        }
        mMapView.getMap().getOperationalLayers().add(kmlLayer);
    }
}

The result is this:

When the desired output should look like this:

As you can see, only the Marginal Risk layer is drawn. The data for the Marginal Risk layer is held in the first placemark in the following file. The General Thunderstorm data is the larger polygon and is contained in the second placemark.

Any help would be greatly appreciated. I've switched back and forth between several APIs regarding this anomaly.

Outcomes