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);
});
  • "When using a Map with a SpatialReference other than Web Mercator or Geographic, be sure to set a default GeometryService". – Kirk Kuykendall Jan 14 '16 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 – user65031 Jan 14 '16 at 2:46
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.

  • 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?. – user65031 Jan 14 '16 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 – Stephen Lead Jan 14 '16 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. – user65031 Jan 15 '16 at 4:13

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.