Hello,
I am trying to create a feature layer from a MapImageLayer sublayer and it's not working.
Using the code snippet from the API (4.11) doc:
var sublayer = mapImageLayer.findSublayerById(0); // here it is finding the sublayer
sublayer.createFeatureLayer().then(function(featureLayer){ return featureLayer.load(); })
The error I am getting is :
Uncaught (in promise) TypeError: sublayer.createFeatureLayer(...).then is not a function
Any idea ?
Matthieu,
And you are sure the mapImageLayer.findSublayerById(0) did return a Sublayer class?
Yes I checked. I am able to turn the visibility on/off etc.
Is it from a dynamic workspace or just a normal MapService layer?
I tried with a dynamic workspace and a normal MapService, and they both seem to work. Here's a simple sample using the same code snippet from the API Reference:
https://codepen.io/noash/pen/JVWVzZ
It sounds like there is something going on with the value of sublayer (perhaps it is being overwritten? typo somewhere?) as this is a valid method as of 4.7.
Right, I must be doing something wrong.
I tried that method:
export const test = () => {
return esriPromise(['esri/layers/MapImageLayer']).then(([ MapImageLayer ]) => {
var layer = new MapImageLayer({
url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer",
sublayers: [ {id: 2,visible: false},{id: 1,visible: false},{id: 0,visible: false}]});
map.layers.add(layer);
var sublayer= layer.findSublayerById(0);
console.log("sublayer: ", sublayer);
// when the createFeatureLayer() promise resolves, load the FeatureLayer
// and pass it to the createFeatureLayer function
sublayer.createFeatureLayer()
.then((featureLayer) => {
console.log("blah")
return featureLayer.load();
})
.then(createFeatureLayer);
function createFeatureLayer (featureLayer) {
featureLayer.visible = true;
map.add(featureLayer);
console.log("featureLayer: ", featureLayer);
}})
}
and now if I do that it works:
var x = new Promise((resolve) => {
resolve(sublayer.createFeatureLayer())
})
.then((featureLayer) => {
console.log("blah")
return featureLayer.load();
})
My bad.
Are you able to share the URL of the map service for testing?