This sample shows how to access a KML file using KMLLayer.
This sample shows how to access a KML file using KMLLayer.
<!doctype html><html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <title>KMLLayer | Sample | ArcGIS Maps SDK for JavaScript</title>
<!-- Load the ArcGIS Maps SDK for JavaScript from CDN --> <script type="module" src="https://js.arcgis.com/5.0/"></script>
<style> html, body { height: 100%; margin: 0; } </style> </head>
<body> <arcgis-map basemap="dark-gray-vector"></arcgis-map> <script type="module"> // Import layer class. const KMLLayer = await $arcgis.import("@arcgis/core/layers/KMLLayer.js");
const layer = new KMLLayer({ // major earthquakes for latest 30 days from USGS url: "https://earthquake.usgs.gov/fdsnws/event/1/query?format=kml&minmagnitude=5.8", });
// Get a reference to the Map component element. const viewElement = document.querySelector("arcgis-map");
await viewElement.viewOnReady();
viewElement.map.add(layer);
// Wait for the layer to be ready for use. await viewElement.whenLayerView(layer);
// Use the component's goTo method to zoom to the layer. viewElement.goTo(layer.fullExtent); </script> </body></html>