Does the arcgis map component only works with WebMap? How can I add a feature layer service to a map-component?
The map and scene components have a map property that you can reference to add layers.
https://developers.arcgis.com/javascript/latest/components/storybook/?path=/docs/map-components_component-reference-map--docs
In the "next" version, which will be in 4.30, we added a method on the elements for addLayer and addLayers.
async function load() { const Layer = await $arcgis.import("esri/layers/Layer"); const url = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2"; const layer = await Layer.fromArcGISServerUrl({ url }); // Reference the map component const mapElem = document.querySelector("arcgis-map"); mapElem.addEventListener("arcgisViewReadyChange", () => { // works today // mapElem.map.add(layer); }, { once: true }); // available in next, will be in 4.30 mapElem.addLayer(layer); } load();
Here is a codepen.
https://codepen.io/odoe/pen/NWowrmo?editors=0010
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.