FeatureSet in Search widget does not have geometry after setDefinitionExpression applied to the feature layer

1056
4
Jump to solution
12-07-2016 03:08 PM
PitersonPaulgek
New Contributor III

Hi,

We have an issue with geometry.

Case 1 - no issue

We use search widget and features from FeatureSet have geometry

Case 2 - issue

We use search widget, apply setDefinitionExpression and features from FeatureSet have NO geometry.

0 Kudos
1 Solution

Accepted Solutions
PitersonPaulgek
New Contributor III

As usual, data issue !!

Some feature with shape is NULL.

Robert, thank you for the example code.

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Piterson,


  Can you share some code?

0 Kudos
PitersonPaulgek
New Contributor III

Robert,

Here you are:

///////////////////////////////////////////////////////////////////////////

app.searchWidget = new Search({
enableLabel: false,
enableInfoWindow: false,
map: app.map,
autoSelect: false
}, "");

initialiseSearchWidget();

function initialiseSearchWidget() {

var sources = app.searchWidget.get("sources");

sources.push({
featureLayer: app.featureLayer2,
searchFields: ["Field1", "Field2"],
displayField: "Field1",
exactMatch: false,
name: "featureLayer2",
placeholder: "Some name here",
maxResults: (app.setting.maxSearchResults+1),
maxSuggestions: 5,
infoTemplate: new InfoTemplate("featureLayer2", "featureLayer2 name: ${Field1}</br>Name: ${NAME}"),
enableSuggestions: true,
minCharacters: 0
});

app.searchWidget.startup();

// Function to handle the actual search.
app.search = function (activeSourceIndex, searchValue) { //0-address,1-layer1,2-layer2,3-layer3, 'all'-all
app.searchWidget.activeSourceIndex = activeSourceIndex;
var deferredSearch = app.searchWidget.search(searchValue);
return deferredSearch;
};

app.handleSearchResult = function (response) {

...

HERE :  to do zoom to the features based on extent/geometry 

Case 1 - no issue

We use search widget and features from FeatureSet have geometry

 

Case 2 - issue

We use search widget, apply featureLayer2.setDefinitionExpression some place BEFORE app.searchWidget.search(searchValue) and features from FeatureSet have NO geometry.

};

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Piterson,

   Hmm. When I apply a definition expression to a source layer before the search I don't seem to have any issue, as seen in this sample: (search for "a" and you will only get democrat senators that have a in their names and clicking on the suggestion takes you to the geometry)

<!DOCTYPE html>
<html dir="ltr">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
   <title>ArcGIS API for JavaScript | Search widget with multiple sources</title>
   <link rel="stylesheet" href="https://js.arcgis.com/3.18/dijit/themes/claro/claro.css">
   <link rel="stylesheet" href="https://js.arcgis.com/3.18/esri/css/esri.css">
   <style>
      html,
      body,
      #map {
         height: 100%;
         width: 100%;
         margin: 0;
         padding: 0;
      }
      #search {
         display: block;
         position: absolute;
         z-index: 2;
         top: 20px;
         left: 74px;
      }
   </style>

   </script>
<script src="https://js.arcgis.com/3.18/"></script>
   <script>
      require([
        "esri/map", "esri/dijit/Search", "esri/layers/FeatureLayer", "esri/InfoTemplate", "dojo/domReady!"
      ], function (Map, Search, FeatureLayer, InfoTemplate) {
         var map = new Map("map", {
            basemap: "gray",
            center: [-97, 38], // lon, lat
            zoom: 5
         });

         var search = new Search({
            enableButtonMode: true, //this enables the search widget to display as a single button
            enableLabel: false,
            enableInfoWindow: true,
            showInfoWindowOnSelect: false,
            map: map
         }, "search");
         

         var sources = [];//search.get("sources");

         //Push the sources used to search, by default the ArcGIS Online World geocoder is included. In addition there is a feature layer of US congressional districts. The districts search is set up to find the "DISTRICTID". Also, a feature layer of senator information is set up to find based on the senator name. 

         sources.push({
            featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/CongressionalDistricts/FeatureServ..."),
            searchFields: ["NAME"],
            displayField: "NAME",
            exactMatch: false,
            outFields: ["DISTRICTID", "NAME", "PARTY"],
            name: "Congressional Districts",
            placeholder: "Congress Member Name",
            maxResults: 6,
            maxSuggestions: 6,

            //Create an InfoTemplate and include three fields
            infoTemplate: new InfoTemplate("Congressional District", "District ID: ${DISTRICTID}</br>Name: ${NAME}</br>Party Affiliation: ${PARTY}"),
            enableSuggestions: true,
            minCharacters: 0
         });

         sources.push({
            featureLayer: new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/US_Senators/FeatureServer/0"),
            searchFields: ["Name"],
            displayField: "Name",
            exactMatch: false,
            name: "Senator",
            outFields: ["*"],
            placeholder: "Senator name",
            maxResults: 6,
            maxSuggestions: 6,

            //Create an InfoTemplate

            infoTemplate: new InfoTemplate("Senator information", "Name: ${Name}</br>State: ${State}</br>Party Affiliation: ${Party}</br>Phone No: ${Phone_Number}<br><a href=${Web_Page} target=_blank ;'>Website</a>"),
            
            enableSuggestions: true,
            minCharacters: 0
         });

         //Set the sources above to the search widget
         search.set("sources", sources);
         
         search.startup();
         search.on('focus', function(){
           search.get("sources")[1].featureLayer.setDefinitionExpression("Party = 'D'");
         });
         

      });
   </script>
</head>

<body>
   <div id="search"></div>
   <div id="map"></div>
</body>

</html>
PitersonPaulgek
New Contributor III

As usual, data issue !!

Some feature with shape is NULL.

Robert, thank you for the example code.

0 Kudos