当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JavaScript ArcGIS Search.sources用法及代码示例


基本信息

以下是所在类或对象的基本信息。

AMD: require(["esri/widgets/Search"], (Search) => { /* code goes here */ });

ESM: import Search from "@arcgis/core/widgets/Search";

类: esri/widgets/Search

继承: Search > Widget > Accessor

自从:用于 JavaScript 4.0 的 ArcGIS API

用法说明

Search.sources函数(或属性)的定义如下:


搜索微件可用于搜索 map /feature 服务要素图层、SceneLayers 与关联要素图层、BuildingComponentSublayer 与关联要素图层、GeoJSONLayerCSVLayer 中的要素。或 OGCFeatureLayertable 或带有 locator 的地理编码位置。 sources 属性定义搜索“搜索”小部件实例指定的视图的源。有两种类型的来源:

这些来源的任何组合都可以在 Search 小部件的同一实例中一起使用。

不支持从客户端图形创建的要素图层。

例子:

// Default sources[] when sources is not specified
[
  {
    url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer",
    singleLineFieldName: "SingleLine",
    outFields: ["Addr_type"],
    name: "ArcGIS World Geocoding Service",
    placeholder: "Address",
    resultSymbol: {
       type: "picture-marker",  // autocasts as new PictureMarkerSymbol()
       url: this.basePath + "/images/search/search-symbol-32.png",
       size: 24,
       width: 24,
       height: 24,
       xoffset: 0,
       yoffset: 0
   }
  }
]
// Example of multiple sources[]
const sources = [
{
  url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer",
  singleLineFieldName: "SingleLine",
  name: "Custom Geocoding Service",
  placeholder: "Search Geocoder",
  maxResults: 3,
  maxSuggestions: 6,
  suggestionsEnabled: false,
  minSuggestCharacters: 0
}, {
  layer: new FeatureLayer({
    url: "https://services.arcgis.com/DO4gTjwJVIJ7O9Ca/arcgis/rest/services/GeoForm_Survey_v11_live/FeatureServer/0",
    outFields: ["*"]
  }),
  searchFields: ["Email", "URL"],
  displayField: "Email",
  exactMatch: false,
  outFields: ["*"],
  name: "Point FS",
  placeholder: "example: esri",
  maxResults: 6,
  maxSuggestions: 6,
  suggestionsEnabled: true,
  minSuggestCharacters: 0
},
{
  layer: new FeatureLayer({
    outFields: ["*"]
  }),
  placeholder: "esri",
  name: "A FeatureLayer",
  prefix: "",
  suffix: "",
  maxResults: 1,
  maxSuggestions: 6,
  exactMatch: false,
  searchFields: [], // defaults to FeatureLayer.displayField
  displayField: "", // defaults to FeatureLayer.displayField
  minSuggestCharacters: 0
}
];
// Set source(s) on creation
const searchWidget = new Search({
  sources: []
});
// Set source(s)
const searchWidget = new Search();
const sources = [{ ... }, { ... }, { ... }]; //array of sources
searchWidget.sources = sources;
// Add to source(s)
const searchWidget = new Search();
searchWidget.sources.push({ ... });  //new source

相关用法


注:本文由纯净天空筛选整理自arcgis.com大神的英文原创作品 Search.sources。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。