DIY KML in ArcGIS JS API 4 Beta
Rene Rubalcava | December 14, 2015
People have a lot of KML files sitting around out there.
Note - this only really works with 2D KML, 3D doesn't get extruded
So the ArcGIS JS API 4.0 beta doesn't have a KMLLayer yet. You're a developer. Are you going to whine about it or do something about it. Use the tools you have at your disposal.
If you check out the 3.x sample and look at the network traffic, you'll see it's actually using an online service to parse the URL. Specifically it's using this one. The docs show you can change this if you want.
Let's use this to our advantage here. We'll just pass the KML url to the KML parse service and voila, magic.
The response from the KML service is FeatureCollection of layers that make up the KML file. We're going to use the GroupLayer in the 4.0beta to load the FeatureCollections into FeatureLayers.
This gets us close.
But, if you have some basic KML you want to use in the ArcGIS JS 4.0beta, these are the basic steps you can use to do it yourself until KML support comes to the 4.0beta.
Don't let something like official support hold you back. If you think there's a way to implement a feature you need that isn't supported yet, try it out and see if you can make it work. Sometimes, you need to get your hands dirty to get the job done.