Select to view content in your preferred language

Accessing Features in a KML layer

400
0
02-22-2023 01:02 PM
Michael0345
New Contributor

I am in the process of converting 3.x Esri Map code to the new 4.x format without dojo/dijit. I am working with a KML Layer for tracking weather storms such as hurricanes. Here is the original 3.x code. 

-----------------------

storms[s].track = new KMLLayer("https://www.nhc.noaa.gov/storm_graphics/api/"+s+"_"+storms[s]['advnum']+"adv_TRACK.kmz",{id:"KML_"+s+"_track"});

if (storms[s].track != null) {
storms[s].track.visible = false;
storms[s].track.on('load',function(loaded) {
array.forEach(loaded.layer.folders,function(folder) {
if (folder.name == "Forecast Track") {
var featureInfos = folder.featureInfos;
array.forEach(featureInfos,function(info){
var feature = loaded.layer.getFeature(info);
if (feature.attributes.styleUrl == "120_line" ||
feature.attributes.styleUrl == "72_line") {
feature.hide();
}
});
}
});
var layer = loaded.layer;
array.forEach(layer._fLayers, function (featureLayer) {
array.forEach(featureLayer.renderer.infos, function (info) {
info.symbol.setOffset(0, 0);
});
featureLayer.redraw();
});
reorderGraphicsLayers();
});
storms[s].track.on('error',function(evt) { KMLLoadError(evt); });
map.addLayer(storms[s].track);
}

------------------------------

 

Essentially trying to iterate through the KML layer and hide any features that meet a certain criteria for feature.attributes.styleUrl, as well as correct the offset of the symbols. How would one achieve this in 4.x?

I can access that same sublayer as before with the following:

-------------------------

if (storm.track != null) {
storm.track.visible = false;
storm.track.load().then(function() {
storm.track.allSublayers.forEach(function(sublayer) {
if (sublayer.title == "Forecast Track") {

//how do I access the features?
}
}
}

---------------------------------------

The problem is that folders were changed to sublayers, and the featureInfos property is no longer available on the found sublayer, and when console.logging the sublayer with the desired title, none of the logged properties seem helpful. (i.e no features, graphics, symbols, etc)

Any help with this problem would be greatly appreciated. 

0 Kudos
0 Replies