Does the arcgis map component only works with WebMap? How can I add a feature layer service to a map-component?
Solved! Go to Solution.
The map and scene components have a map property that you can reference to add layers.
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.
The map and scene components have a map property that you can reference to add layers.
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.