I managed to download all the data from ArcGis REST Service, from FeatureServer service, using JavaScript.
I have all the data, featureserver json data, feature layers data, queried features data.
The problem I am facing is I can't create a FeatureLayer. I have featureSet, featureCollection, renderer and even array of features Graphic made from JSON.
I've read something of creating FeatureLayer from featureCollection, but the only result is an error: "Feature layer must be created with either a url or a source".
I tried to create a FeatureLayer from source, renderer, but nothing appears in on the map.
The JSON data is fetched in Javascript via fetch(). I saw somewhere a esriRequest method, but I am not sure if it will help since the json in response is exactly the same.
I am working with this data currently:
https://services1.arcgis.com/RbMX0mRVOFNTdLzd/ArcGIS/rest/services/2020_Electric_Service_Area_web/FeatureServer
Fetch FeatureServer data:
async function getFeatureServerJSON(featureServerUrlString) {
const downloadedFeatureService = await getArcGisData(
featureServerUrlString + "?f=json"
);
const downloadedFeatureLayers = [];
for (let i = 0; i < downloadedFeatureService.layers.length; i++) {
downloadedFeatureLayers.push({
structure: await getArcGisData(featureServerUrlString + i + "?f=json"),
featureSet: await getArcGisData(
featureServerUrlString + i + "/query?f=json&where=1=1"
),
});
}
return {
featureService: downloadedFeatureService,
featureLayers: downloadedFeatureLayers,
};
}
Creating FeatureLayer:
const graphicFirstLayerArray = [];
for (const feature of cachedFeatureServer.featureLayers[0].featureSet
.features) {
graphicFirstLayerArray.push(Graphic.fromJSON(feature));
}
// console.log(graphicFirstLayerArray);
const { renderer } = cachedFeatureServer.featureLayers[0].structure.drawingInfo;
const fset = FeatureSet.fromJSON(cachedFeatureServer.featureLayers[0].featureSet);
const featureCollection = {
layerDefinition: cachedFeatureServer.featureLayers[0].structure,
featureSet: fset,
};
const fl = new FeatureLayer(featureCollection);
map.layers.add(fl); Please help 🙂