0

I'm trying to search features using the "esri/search" module. I'm passing the parameters to callback function (Search) to add a feature layer and search features, but i don't see any features added on map in first place. Please check below the function call:

var mysources = mySearch.get("mysources");
mySearch.on("load", function(){
 mySearch.Set("mysources",mysources);
 mysources.push({
 myfeatureLayer: new FeatureLayer("http://arcgis-serveruf-1981283418.us-east-1.elb.amazonaws.com/arcgis/rest/services/MyFiles/LandParcels/FeatureServer/0"),
 mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
 searchFields: ["ADDRESS"],
 suggestionTemplate: "Address : ${ADDRESS}",
 exactMatch: false,
 outFields: ["*"],
 name: "land parcels",
 labelSymbol: textSymbol,
 placeholder: "address of parcels",
 maxResults: 6,
 maxSuggestions: 6,
 enableSuggestions: true,
 minCharacters: 1
 });
 map.addLayer(myfeatureLayer);
});
Stephen Lead
21.3k18 gold badges117 silver badges245 bronze badges
asked Jan 13, 2016 at 20:19
2
  • "When using a Map with a SpatialReference other than Web Mercator or Geographic, be sure to set a default GeometryService". Commented Jan 14, 2016 at 0:23
  • I published a new feature service by changing the projection from NAD to Web Mercator. But i couldn't add the layer to map. I even declared the myfeatureLayer as separate variable as suggested by below, but still it remains un-added. Would you suggest were i had gone wrong ?. Thanks-Kirk Commented Jan 14, 2016 at 2:46

1 Answer 1

1

You haven't explicitly defined myfeatureLayer as a variable, so it's not available when you try to run map.addLayer(myfeatureLayer).

You could first declare myfeaturelayer as a variable, then add the variable to mysources, or you could get the last index of mysources and add that to the map.

answered Jan 14, 2016 at 0:02
3
  • I defined the myfeatureLayer as a variable before mysources, but still the layer did not show up on the basemap. Any reasons were i had gone wrong?. Commented Jan 14, 2016 at 2:50
  • Why does myfeatureLayer need to depend on the search function at all? Can you just create a feature layer and add it normally, as in this sample? You're over-complicating things in the above example Commented Jan 14, 2016 at 2:57
  • Thank you Stephen. I fixed the issue. The features are not highlighted when i click the search with a related value or suggested results. Commented Jan 15, 2016 at 4:13

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.