adding the fields from a feature set to a new layer

939
3
Jump to solution
11-20-2019 01:52 PM
deleted-user-wcpelUUf_XXx
New Contributor III

this is the sample I am working on https://codepen.io/segev-salman/pen/xxxjpaX?editors=1000 

this demo finds a feature by input id creates a new layer with only that feature and zooms in on it. 

i want to add a popup with the features details(i want them all but I am using 2 for the demo). when creating the feature  set I am using outFields = ["*"]  to get all the fields for use in the popup but I am failing on the part of inserting them into the layer and maybe to the popup graphic.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

Hi there, 

I have looked at your codepen. I updated a few things in your codepen to make your current workflow work. Mainly, you should not set outFields instead you have to set the fields property for the new FeatureLayer. See below:

layer = new FeatureLayer({
 objectIdField: "OBJECTID", 
 source: featureSet.features,
 fields: featureSet.fields,
 popupTemplate: {
   content: "{name1} in {city} has {OBJECTID}"
 },
 renderer: newRend
});

Here is the updated codepen.

However, I am not sure why you are creating a new FeatureLayer every time users enter a new input. This can lead to sluggish and slow performing app. You should be able to set all of what you are setting on a new featurelayer on your pointservice featurelayer. When user enters an input, call queryFeatures, zoom to that feature all without have to create a new featurelayer everytime! 

View solution in original post

3 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

I have looked at your codepen. I updated a few things in your codepen to make your current workflow work. Mainly, you should not set outFields instead you have to set the fields property for the new FeatureLayer. See below:

layer = new FeatureLayer({
 objectIdField: "OBJECTID", 
 source: featureSet.features,
 fields: featureSet.fields,
 popupTemplate: {
   content: "{name1} in {city} has {OBJECTID}"
 },
 renderer: newRend
});

Here is the updated codepen.

However, I am not sure why you are creating a new FeatureLayer every time users enter a new input. This can lead to sluggish and slow performing app. You should be able to set all of what you are setting on a new featurelayer on your pointservice featurelayer. When user enters an input, call queryFeatures, zoom to that feature all without have to create a new featurelayer everytime! 

deleted-user-wcpelUUf_XXx
New Contributor III

thank you! the new layer was a bad call on my parts o Im trying to call queryFeatures and zoom on the pointservice without creating a new featurelayer.
I am not entirely sure how to do it, I transfered the popup to the pointservice featurelayer, and now trying to applyedits to .
the layer

heres the edited pen if you can take a look : https://codepen.io/segev-salman/pen/povoyoQ?editors=1010 

thank you again!

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

Please do not use applyEdits. FeatureLayer.applyEdits() method is used to created, update or delete features in a FeatureLayer. You are physically changing features in your service. You can, query your features as you are doing, once the query results are returned you can simply zoom to the query result features by calling MapView.goTo passing the array of features, then display the popupTemplate by calling popup.open.

I also updated your app to use FeatureLayerView.queryFeatures method as this method queries the features on the client side without having to make a network trip to the server like FeatureLayer.queryFeatures does. However, this method will  query features that are available on the client at the time of query. If you need to make sure that you are querying all features available in the service then use FeatureLayer.queryFeatures.

Here is the updated test app.

Hope this helps,

-Undral

0 Kudos