tmcgee / cmv-widgets

Widgets for CMV, the Configurable Map Viewer.
https://cmv.io/
MIT License
38 stars 48 forks source link

Restrict Search widget to a country #122

Closed srinipalavalli closed 7 years ago

srinipalavalli commented 7 years ago

Hi,

How can I restrict the search widget results to one country?

tmcgee commented 7 years ago

For the Esri Search widget you can use the countryCode in localSearchOptions. See the documentation.

For my search widget, you can add any valid SQL where expression like this:

expression: 'country = \'US\'',

this expression can be added for the layer or a query within a layer.

srinipalavalli commented 7 years ago

Thanks Tim.

search: { include: true, type: 'domNode', path: 'esri/dijit/Search', srcNodeRef: 'geocoderButton', options: { map: true, visible: true, enableInfoWindow: true, enableButtonMode: true, expanded: false }, sources: [{ localSearchOptions: { countryCode: 'AUS' } }] } is this correct?

tmcgee commented 7 years ago

According to the documentation, I believe you need to use a sources array. This is the default:

sources: [
  {
    locator: new   Locator("//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"),
    singleLineFieldName: "SingleLine",
    outFields: ["Addr_type"],
    name: i18n.widgets.Search.main.esriLocatorName,
    localSearchOptions: {
      minScale: 300000,
      distance: 50000
    },
    placeholder: i18n.widgets.Search.main.placeholder,
    highlightSymbol: new PictureMarkerSymbol(this.basePath + "/images/search-pointer.png", 36, 36).setOffset(9, 18)
  }
]

And not sure if you need to use the two-character country code instead of the three-character code. The examples in the documentation use two-character codes. This repository is specific to my widgets for cmv. For general assistance with cmv, please post issues in the cmv-app repo.