1

I want to restrict my search results to a specific country (NZ) with ArcGIS Javascript/Angular API. I am using Angular for this project:

mygis.component.ts

async ngOnInit() {
await loadCss('https://js.arcgis.com/4.9/esri/css/main.css');
const [WebMap, MapView, _, Search, Locator] = await loadModules([
  'esri/Map',
  'esri/views/MapView',
  'esri/WebMap',
  'esri/widgets/Search',
  'esri/tasks/Locator'
])
// create a Map loaded from a webmap
const webMap = new WebMap({
  basemap: 'hybrid',
  portalItem: { // autocasts as new PortalItem()
    id: "f2e9b762544945f390ca4ac3671cfa72"
  }
});

const search = new Search({
  mapView: MapView,
  includeDefaultSources: false,
  sources: [{
    locator: new Locator({ url:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"}),
    CountryCode: "NZ"}],
    name: "Geocode",
});

const mapView = new MapView({
      container: this.mapView,
      center: [175.1278, -36.7074],
      zoom: 9,
      map: webMap,
    });

mapView.ui.add(search, "top-right");
  
  }
}

I have created a stackblitz sample here but I get world wide results. Very similar to Limiting the search widget results to a country in ArcGIS JS API 4.9.

1 Answer 1

1

You just have a small typo in your code - you have CountryCode (first capital C), instead of countryCode

const search = new Search({
  mapView: MapView,
  includeDefaultSources: false,
  sources: [{
    locator: new Locator({ url:"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"}),
    countryCode: "NZ"}],
    name: "Geocode",
});
1
  • Thanks - I will test this out. Aug 14, 2020 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.