3

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

function testarvin1() {
    require([
        "esri/Map",
        "esri/layers/FeatureLayer"],
             function (FeatureLayer) {

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

                var fl = new esri.layers.FeatureLayer("http://192.168.0.205:6080/arcgis/rest/services/SAMA/MapServer/3", {
                    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);

                fl.applyEdits();
                map.addLayer(fl);

        });}

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.

4
  • Maybe try removing the port from the REST endpoint URL?
    – crmackey
    Commented Mar 30, 2015 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 ? Commented Mar 31, 2015 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? Commented Mar 31, 2015 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
    Commented Mar 31, 2015 at 13:28

1 Answer 1

2

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(..);
map.addLayer(fl);
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.

1
  • Thanks, i wasn't editing yet, so i didn't care about that so much, but your answer was informative. Commented Apr 3, 2015 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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