當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。