GEOG 863
GIS Mashups for Geospatial Professionals

6.1.3 Searching in a FeatureLayer

PrintPrint

As mentioned earlier, the Search widget can also be configured to find features in a FeatureLayer. Have a look at this example, an app that allows for finding cities and counties in Jen & Barry’s world. The key difference as compared to the previous example is that a FeatureLayerSource (actually two) is used instead of a LocatorSource. The SDK shows that a FeatureLayerSource has many properties in common with a LocatorSource, though it obviously has others that are unique to it.

Here’s a quick rundown of what’s happening in this app:

  • The two FeatureLayers are created using their portalItem ids as we’ve done earlier in the course.
  • An appropriate PopupTemplate is defined for each FeatureLayer.
  • The searchFields property is set to the field that should be searched for the user’s text.
  • The exactMatch property is set to false, allowing for partial matches.
  • The outFields property is set to the array of fields used by the app. In this case, only the NAME field is needed in both layers.
  • When more than one source is specified for the widget, a drop-down arrow appears on the left side of the search box. The drop-down list contains a choice for each of the sources. Setting a FeatureLayerSource’s name property specifies how the source will appear in the drop-down list. (In this case, "Cities" and "Counties" is assigned to the name property.)
  • The allPlaceholder property (which is assigned to the Search object) controls the hint that appears in the search box when it has multiple sources.
  • The placeholder property (set at the source level) controls the hint that appears if that individual source is selected from the drop-down list discussed above.
  • The zoomScale property is set for the cities layer source. Unlike lines and polygons, points have no logical extent envelope to zoom to. Leaving this property unset on a point layer is likely to cause the app to zoom in closer than you would like. Leaving the property unset on the county layer makes sense since zooming to the polygon extent works nicely.