I can't get any value from featurelayer. This is the code:

function testarvin1() {
             function (FeatureLayer) {

                var layerName = $('#ClassifyLayer').val().replace(LAYER_PREFIX, '');

                var fl = new esri.layers.FeatureLayer("", {
                    id: 3,
                    mode: FeatureLayer.MODE_SNAPSHOT,
                    outFields: ["*"],


                console.log("fl is " + fl);
                var g = fl.minScale;
                var h = fl.name;

                console.log("the minscale is =  " + g);
                console.log("the name  is =  " + h);



I get "the fl is [object object]", "the minscale is = 0" and "the name is undefined" in console.

What am i doing wrong? I changed the featurelayer mode but didn't help.

  • Maybe try removing the port from the REST endpoint URL? – crmackey Mar 30 '15 at 14:45
  • when I remove that I get " [HTTP/1.1 404 Not Found 859ms] " And with the port I get " [HTTP/1.1 304 Not Modified 20ms] " which I think is not an Error. but could it be the problem ? – Arvin Sanaei Mar 31 '15 at 3:32
  • I should mention that i can't enable the "Feature Access" in my Map service, and when I want to publish a service(With the feature access capability) from scratch I get bunch of Errors and it wont be published. Could this be the Problem? – Arvin Sanaei Mar 31 '15 at 5:04
  • Ah, yes. I think that sounds more like the culprit. It probably is not correctly initiating as a feature layer without the Feature Access Capability. We constantly get errors when publishing services as well, but sometimes it gets published correctly even when there are errors so we always verify by checking the REST endpoints after we publish a service. – crmackey Mar 31 '15 at 13:28

you have to add the layer to the map before you call applyEdits() and you have to wait for the onLoad event before all properties will be appropriately hydrated.

var fl = new FeatureLayer(..);
fl.on("load", function(evt){
  //inspect evt.layer properties and/or call fl.applyEdits()

this is because adding the layer to the map triggers a web request to the service itself to gather metadata that is asynchronous.

  • Thanks, i wasn't editing yet, so i didn't care about that so much, but your answer was informative. – Arvin Sanaei Apr 3 '15 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.