Loading FeatureLayer with Treeview.OnClick

4004
4
Jump to solution
01-28-2015 12:53 PM
KeithAnderson
New Contributor III

Friends

I want to create and display a single FeatureLayer from a different endpoint each time a tree node is clicked on.

The FeatureLayer should include symbology.

I pass in the Item.url with onClick and it works on the first pass.

The next .onClick is a different item.url and it bombs because it cannot create a new FeatureLayer.

TypeError: FeatureLayer is not a constructor

Suggestion on how to structure this.

Thanks

Keith

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Change the name of your FeatureLayer variable to see if that makes any difference. It could be getting confused with the variable name assigned to the module "esri/layers/FeatureLayer",

  featureLayer = new FeatureLayer(item.endpointurl,
    {
        mode: FeatureLayer.MODE_ONDEMAND,
        infoTemplate: infoTemplate,
        outFields: ["*"]
    });

  featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
  map.addLayer(featureLayer);

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

Change the name of your FeatureLayer variable to see if that makes any difference. It could be getting confused with the variable name assigned to the module "esri/layers/FeatureLayer",

  featureLayer = new FeatureLayer(item.endpointurl,
    {
        mode: FeatureLayer.MODE_ONDEMAND,
        infoTemplate: infoTemplate,
        outFields: ["*"]
    });

  featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
  map.addLayer(featureLayer);
0 Kudos
KeithAnderson
New Contributor III

Thank you Ken!

Don’t I feel like a dope.

I was thinking this would destroy the previous FeatureLayer and display only the new one.

Now I have two FeatureLayers displaying.

If I put an id: on it would that overwrite it?

Suggestions?

Thanks again.

K

0 Kudos
KenBuja
MVP Esteemed Contributor

If you only want to show one layer at a time, then you could simply remove the old one "map.removeLayer(featureLayer)" and add in the new one. You'll get an error if you put in the same id for two different items.

0 Kudos
KeithAnderson
New Contributor III

K

Thank you so much for your services.

K

0 Kudos