arcgis
I have added FeatureLayer as below into the map,
var map = new Map("map", {
basemap: "streets-navigation-vector",
showLabels:false,
showAttribution: false,
slider: false,
center: [-122.45, 37.75],
zoom: 10,
minZoom: 2,
});
var selectedBoundaryServiceUrl = "https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3";
var stateLayer = new esri.layers.FeatureLayer(selectedBoundaryServiceUrl, {
id: "Selected_Layer",
opacity: 0.7,
mode: esri.layers.FeatureLayer.MODE_AUTO,
outFields: ["*"],
infoTemplate: infoTemplate
});
g_esri.map.addLayer(stateLayer);
I tried below line of code to get array of graphics in the layer.
var listOfGraphics = map.getLayer("Selected_Layer").graphics
But the output I'm getting as "Zero"
Here I'm adding the console output for reference.
Solved! Go to Solution.
You have to wait until the map is loaded before attempting to access its graphics. If you use "map.addLayer", then you'll have to use syntax to check when the specific layer is loaded (since the event fires each time a layer is loaded, including basemap layers)
map.addLayer(featureLayer);
map.on('layer-add-result', function(addLayer){
if (addLayer.layer === featureLayer){
console.log(featureLayer.graphics);
}
});
Or you could use "map.addLayers", which fires when all layers are loaded.
map.addLayers([featureLayer]);
map.on('layers-add-result', function (){
console.log(featureLayer.graphics);
});
You have to wait until the map is loaded before attempting to access its graphics. If you use "map.addLayer", then you'll have to use syntax to check when the specific layer is loaded (since the event fires each time a layer is loaded, including basemap layers)
map.addLayer(featureLayer);
map.on('layer-add-result', function(addLayer){
if (addLayer.layer === featureLayer){
console.log(featureLayer.graphics);
}
});
Or you could use "map.addLayers", which fires when all layers are loaded.
map.addLayers([featureLayer]);
map.on('layers-add-result', function (){
console.log(featureLayer.graphics);
});
Is it possible to get the list of features before adding it on Map?
By using some AJAX or something.
Valgen,
Use esriRequest to make a service call to the rest endpoint for the MapService or FeatureService, with a query where of 1=1.
Here is a sample that shows that: