開發中整理的。不足之處還請諒解!
----------------------------------------------- Class:Search 調用方式:require(["esri/dijit/Search",function(Search){......}]); /*描述:搜索小工具提供一種基於位置服務和地圖、要素服務圖層的搜索。這些指定的數據源在搜索框中搜索的內容。 如果用定位或地理服務時使用 findAddressCandidates方法。 搜索工具類似地理編輯工具。主要的不同時搜索工具提供附加的允許搜索和建議多種數據的功能。 注意:當使用一個空間參考的地圖或其他的web墨卡托或者地理,要確保建立一個默認集合服務。 這將確保用戶的位置返回相同的空間參考地圖。*/ ---------------------- requrie(["esri/config"],function(esriConfig){ esriConfig.defaults.geometryService="http://www.example.com/arcgis/rest/services/Utilities/Geometry/GeometryServer"; }); ---------------------- 構造函數: new Search(options,srcNode) //使用給定DOM節點新建一個搜索工具 --------------------------------------- CSS Name 描述 active 類用於描述的風格活躍的“搜索”按鈕,生成的菜單項。 arcgisSearch 代表節點搜索的實例小部件呈現。這是默認主題獨特風格的小部件。 hasButtonMode 類指示是否顯示模式按鈕 hasMultipleSources 類指示是否正在使用多個來源 menuHeader 類用於樣式標題搜索結果的頂部菜單。 moreResults 類用於指示是否顯示額外的結果在生成的搜索彈出。 noResultsBody Class used to style the body of how "No results" is displayed.類用於樣式的身體如何顯示“沒有結果”。 noResultsHeader Class used to style the header of how "No results" displays.類用於樣式的標題顯示“沒有結果”。 noResultsMenu Class used to style the menu if there are "No results".類用於樣式菜單如果有“沒有結果”。 noResultsText The class used to style the "No results" text.類用於風格“沒有結果”文本。 noValueIcon This class is used used if wanting to display a warning icon when no value is entered into the search box.使用這個類使用時如果想顯示一個警告圖標沒有值輸入到搜索框。 noValueText Class used to style the resulting dialog when no value is entered in the search box.類用於樣式結果對話框時不搜索框中輸入的值。 popupHeader Class used to style the popupHeader in the search popup's "More results". resultsList Class used to style the popup's search results list. searchAnimate Class used to style how the search animation displays. searchBtn Class used to style the Search button. searchButtonText The class used to style how the "Search" button displays its text. searchClear The class used to style the "Clear search" (x) area of the widget. searchClearFloat Used to clear floats in the Search widget. searchClearIcon | esriIconCancel Class used to style the clear icon. searchCollapsed Class used to indicate whether the search is collapsed. searchExpandContainer Containing class for when the widget is expanded. searchExpanded Class used to indicate whether the search is expanded. searchGroup Class used to style the elements used for the input text and search. searchIcon | esriIconZoom Class used to style the search icon. .arcgisSearch .searchIcon { color:orange; font-size:20px; } searchInput Class used to style the search input box. searchInputGroup Class used to style the grouping of input elements. searchLoading Class used to indicate that the search is loading. searchMenu Class used to style the resulting search results menu. searchSubmit Class used to style the Search's submit button when collapsed. searchToggle Class used to style how the toggle button displays. searchToggleIcon | esriIconDownDir Class used to style the toggle icon. .arcgisSearch .esriIconDownDir{ color: #ccc; } showMoreResults Class used to indicate if showing more results in the search result popup. showNoResults Class indicating whether to display "No results". showSources Class indicating whether to display sources. showSuggestions Class indicating whether to show suggestions for text input. sourceName Class used to style how the source name is displayed. sourcesMenu Class used to style the drop-down menu listing all available sources. suggestionsMenu Class used to style the drop-down menu for suggestions. -------------------------------------------------------------------------------------------------------------------------- 屬性 name type Summary activeSourse object 只讀屬性的當前選中的源對象 activeSourseIndex Number 當前選擇的來源 addLayersFromMap Boolean 指示是否自動添加層從地圖上的所有功能。 allPlaceholder String 這個默認的值用來在搜索多個值時提示輸入文本信息 autoNavigate Boolean 指示是否自動導航到所選擇的結果。 autoSelect Boolean Indicates whether to automatically select the first geocoded result. defaultSource Object (Read-only), the default source used for the Search widget. enableButtonMode Boolean Indicates whether to enable an option to collapse/expand the search into a button. enableHighlight Boolean Show the selected feature on the map using a default symbol determined by the source's geometry type. enableInfoWindow Boolean Indicates whether to display the infoWindow on feature click. enableLabel Boolean Indicates whether to enable showing a label for the geometry. enableSearchingAll Boolean Indicates whether to display the option to search "All" sources. enableSourcesMenu Boolean Indicates whether to enable the menu for selecting different sources. enableSuggestions Boolean Enable suggestions for the widget. enableSuggestionsMenu Boolean Indicates whether to display suggest results. expanded Boolean Indicates whether to set the state of the enableButtonMode to expanded (true) or collapsed (false). graphicsLayer Layer This is the specified graphicsLayer to use for the highlightGraphic and labelGraphic instead of map.graphics. highlightGraphic Graphic Read-only property indicating the highlighted location graphic. infoTemplate InfoTemplate A customized infoTemplate for the selected feature. labelGraphic Graphic Read-only graphic property for the text label. labelSymbol TextSymbol The text symbol for the label graphic. loaded Boolean Read-only property indicating whether the widget is loaded. locationToAddressDistance Number The default distance specified in meters used to reverse geocode (if not specified by source). map Map Reference to the map. maxResults Number The default maximum number of results returned by the widget if not specified by source. maxSuggestions Number The default maximum number of suggestions returned by the widget if not specified by source. minCharacters Number The default minimum number of characters needed for the search if not specified by source. searchResults Object[] Read-only property that returns an array of current results from the search. showInfoWindowOnSelect Boolean Indicates whether to show the infoWindow when a result is selected. sources Object[] An array of source objects used to find search results. suggestResults Object[] Read-only property that returns an array of current results from the suggest. suggestionDelay Number The millisecond delay after keyup and before making a suggest network request. theme String The CSS class selector used to uniquely style the widget. value String The current value of the search box input text string. visible Boolean Indicate whether to show the widget. zoomScale Number If the result does not have an associated extent, specify this number to use as the zoom scale for the result. --------------------------------------------------------------------- ------------------------------------------------------------------------ 方法: Name 返回類型 簡述 blur() None 滑動塊工具的文本輸入 clear() None 清除當前的值,搜索結果,顯示結果,幾何圖形或者幾何圖層 collaspe() None 從按鈕模式關閉小部件 destory() None 清除搜索小部件 expand() None 從按鈕模式打開小部件 get(name) Object|B 從搜索小部件獲取屬性的值。 hide() None 隱藏搜索部件 search(value?) Promise 根據指定的來源,search()查詢功能層(s)和/或執行地址匹配使用Locator(s),並返回指定任何任何適用的結果。 select(value) None 選擇一個結果 set(name,value) None 設置一個非只讀屬性值的部件 show() 顯示部件 startup() 結束搜索的小部件 suggest(value?) Promise 執行一個活動定位器上的suggest()請求或功能層。 =================================================================== 事件 blur Fired when the widget's text input loses focus. clear-search Fired when a result is cleared from the input box or a new result is selected. focus Fired when the widget's text input sets focus. load Fired when the search widget has fully loaded. search-results { activeSourceIndex: <Number>, errors: <Error[]>, numErrors: <Number>, numResults: <Number>, results: <Object[]>, value: <String> } Fires when the search method is called and returns its results. select-result { result: <Object>, source: <Object>, sourceIndex: <Number> } Fired when a search result is selected. suggest-results { activeSourceIndex: <Number>, errors: <Error[]>, numErrors: <Number>, numResults: <Number>, results: <Object[]>, value: <String> } Fired when the suggest method is called and returns its results. Constructor Details new Search(options, srcNode) Create a new Search widget using the given DOM node. Parameters: <Object> options Required Set of options used to specify Search options. This parameter is required but can be null or an empty object. See the options properties below for details. <Node | String> srcNode Required Reference or id of the HTML element where the widget should be rendered. options properties: <Number | String> activeSourceIndex Optional The currently selected source. The default is "all". <Boolean> addLayersFromMap Optional Indicates whether to automatically add all the feature layers from the map. The default value is false. <String> allPlaceholder Optional This is the default value used as a hint for input text when searching on multiple sources. The default value is "Find address or place". <Boolean> autoNavigate Optional Indicates whether to automatically navigate to the selected result. The default value is true. <Boolean> autoSelect Optional Indicates whether to automatically select the first geocoded result (not the first suggestion). The default value is true. <Boolean> enableButtonMode Optional Indicates whether to enable an option to collapse/expand the search into a button. The default value is false. <Boolean> enableHighlight Optional Indicates whether to show the selected feature on the map using the highlight symbol property. The default value is true. <Boolean> enableInfoWindow Optional Indicates whether to display the infoWindow on feature click. The default value is true. See the enableInfoWindow property for additional information on this. <Boolean> enableLabel Optional Indicates whether to enable showing a label for the geometry.The default value is false. <Boolean> enableSearchingAll Optional Indicates whether to display the option to search "All" sources. Default is true. <Boolean> enableSourcesMenu Optional Indicates whether to enable the menu for selecting different sources. The default value is true. <Boolean> enableSuggestions Optional Indicates whether or not to enable suggest on the widget. The default value is true. NOTE: This is available if working with a 10.3 geocoding service that has suggest capability loaded or a 10.3 feature layer that supports pagination, i.e. supportsPagination = true. <Boolean> enableSuggestionsMenu Optional Indicates whether to display suggest results. The default value is true. <Boolean> expanded Optional Indicates whether to set the state of the enableButtonMode to expanded (true) or collapsed (false). The default value is false. <Layer> graphicsLayer Optional This the specified graphicsLayer to use for the highlightGraphic and labelGraphic instead of map.graphics. <Symbol> highlightSymbol Optional The symbol used for highlightGraphic. Defaults to PictureMarkerSymbol. <InfoTemplate> infoTemplate Optional A customized infoTemplate for the selected feature. NOTE: Do not specify a wildcard "${*}" for this specific infoTemplate as it will return all fields in addition to search-specific fields. <TextSymbol> labelSymbol Optional The text symbol for the label graphic. <Number> locationToAddressDistance Optional The default distance specified in meters used to reverse geocode, (if not specified by source). The default value is 1500. <Map> map Optional Reference to the map. If no map is specified, the value is null. <Number> maxResults Optional The default maximum number of results returned by the widget if not specified by source. The default value is 6. <Number> maxSuggestions Optional The default maximum number of suggestions returned by the widget if not specified by source. The default value is 6. NOTE: If working with the default ArcGIS Online Geocoding service, the default remains at 5. <Number> minCharacters Optional The default minimum amount of characters needed for the search if not specified by source. The default value is 1. <Boolean> showInfoWindowOnSelect Optional Indicates whether to show the infoWindow when a result is selected. The default value is true. See the showInfoWindowOnSelect property for additional information on this. <Object[]> sources Optional An array of source objects used to find search results. Refer to the sources property for additional information on this. <Number> suggestionDelay Optional The millisecond delay after keyup and before making a suggest network request. The default value is 150. <String> theme Optional The CSS class selector used to uniquely style the widget. The default value is arcgisSearch. <String> value Optional Current value of the search box input text string. The default value is "". <Boolean> visible Optional Indicates whether to show the Search widget. Default value is true. <Number> zoomScale Optional If the result does not have an associated extent, specify this number to use as the zoom scale for the result. The default value is 1000. ================================================================================ Sample: require([ "esri/map","esri/dijit/Search",....],function(Map,Search,....){ var map=new Map(....); var s=new Search({ map:map },"search"); )}; ============================================================= 具體的方法簡介 <object[]>sources 源對象數組用於查找搜索結果。 支持多種地理編碼服務除了搜索功能層。參見下面對象規格表結構的源對象。 默認的源對象 Default sourses[] [ { locator:new Locator("//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"), singleLineFieldName:"SingleLine", outFields:["Addr_type"], name:i18n.widgets.Search.main.esriLocationName, localSearchOptions:{ minScale:300000, maxScale:500000 }, placeholder:i18n,widget.Search.main.placeholder, highlighSymbol:new PictureMarkerSymbol(this.basePath+"/images/search-pointer.png",36,36).setOffset(9,18) } ] -------------------------------------------------- 具體的示例 var sourse=[ { locator:, singleLineFieldName:"SingleLine", name:"Custom Geocoding Service", localSearchOptions:{ minScale:300000, distance:50000 }, placeholder:"Search Geocoder", maxResults:3, maxSuggestions:6, enableSuggestions:false, minCharacters:0 },{ featureLayer:new FeatureLayer("http://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/US_Senators/FeatureServer/0"), searchFisds:["Name","Party"], suggestionTemplate:"${Name},Party:${Party}", exactMatch:false, outFields:["*"], name:"Senators", lableSymbol:textSymbol, placeholder:"Senator Nmae", maxResults:6, maxSuggestions:true, minCharacters:0, searchQuaryParams:{distance:5000}, }, { featureLayer:new FeatureLayer(),{ outFields:["*"] }); placeholder:"esri", name:"A FeatureLayer", prefix:"", suffix:"", maxResults:1, maxSuggestions:6, searchExtent:null, exactMath:fasle, searchFields:[],//默認為 FeatureLayer.displayField displayField:"",//默認為 FeatureLayer.displayField labelSymbol:new TextSymbol(), minCharacters:0 } ]; =========================================== 設置源的一些方法 1. Set source(s) on creation var s=new Search({ sources:[] }); s.startup(); 2.Add to sources var s=new Search(); var sources=s.get("sources"); sources.push({//new sources}) ; s.set("sources",sources); s.startup(); 3.set sources var s=new Search(); var sources=[my sources]; s.set("sources",sources); s.startup(); ----------------------------------------------------------- 規范: 1、local Search Options distance //指定一個搜索位置的距離,默認值為12000 minScale //位置搜索時指定比例尺至小於指定值。默認為15000 2.sources autoNavigate //同時適用於定位器和功能層。這表明是否自動導航到選定的結果一旦選中。默認是正確的。 categories //一個字符串數組限制到一個或多個類別的結果。例如“密集的地方”或“機場”。只適用於當使用世界地理編碼服務。查看世界地理編碼服務文檔了解更多信息。 countryCode //只用於使用定位器的來源。這個會對搜索結果到指定的國家代碼。例如,“US”美國和瑞典“SE”。只適用於世界地理服務。 displayField //只適用於要素圖層源。結果顯示正在使用的字段。默認的顯示圖層的第一個字段。 enableHighlight //同時適用於定位器和功能層。這表明是否在地圖上顯示一個圖形使用highlightSymbol選中的源。默認值是正確的。 enableInfoWindow //同時適用於定位器和功能層。它顯示一個信息窗口,單擊選擇的結果。默認是正確的。 enableLabel //同時適用於定位器和功能層。這表明是否在地圖上顯示一個文本標簽使用labelSymbol選中的源。默認值是錯誤的。 enableSuggestions//同時適用於定位器和功能層。這表明是否啟用建議小部件的用戶輸入。默認值是正確的。 注意:這是可用的,如果使用10.3地理編碼服務,建議功能層,支持分頁加載或10.3特性,即supportsPagination = true。 exactMathch //只適用於功能層源。這只搜索值完全匹配的返回結果。默認是假的。 featureLayer //這只適用於地圖服務功能層。功能層是在搜索查詢。如果搜索功能層,這是必需的。 infoTemplate //用於選擇結果。同時適用於定位和功能層。 labelSymbol //TextSymbol用於標簽所選擇的結果。這同時適用於定位器和功能層。 localSearchOptions//只適用於在使用定位器的來源。這是用於設置為當地的距離和minScale搜索來源。有關詳細信息,請參閱下面的localSearchOptions表。 locationToAddressDistance//默認的距離米為反向地理編碼。 locator //這只適用於定位器的來源。這是用於搜索定位任務。這是必需的,默認為世界地理編碼服務。 maxResualts //同時適用於定位器和功能層。這個數字顯示返回結果的最大數目。默認值是6。 maxSuggestions //同時適用於定位器和功能層。這個數字表示建議的最大數量換取小部件的輸入。默認值為15。 minCharacters //同時適用於定位器和功能層。這個數字顯示所需的最小字符數在查詢一個建議。默認值是1。 name //同時適用於定位器和功能層。這是來源顯示的名稱。 outFields //這個字符串數組同時適用於定位器和功能層。它指定的字段返回搜索結果。 placeholder //同時適用於定位器和功能層。這是用來提示源輸入文本。不支持的IE9和下面。 prefix //同時適用於定位器和功能層。指定該前綴的輸入搜索文本。 searchExtent //程度上對象的數組,同時適用於定位器和功能層。設置這個如果要限制搜索結果在某種程度上 searchFields //只適用於功能層。它是一個字符串值數組搜索結果在這些領域的功能層 searchQueryParams//定義了一個查詢的默認選項,當搜索功能層。有些選項可能會覆蓋搜索部件包括以下幾點: outSpatialReference returnGeometry num outFields where maxAllowableOffset objectIds suggestionTemplate //一個模板字符串用於顯示多個字段順序定義。這僅適用於功能層和優先於displayField來源。 useMapExtent //指示是否限制搜索結果在地圖的程度上。 zoomScale //適用於指定的源。如果結果沒有一個關聯的程度,指定要使用這個號碼的縮放尺度結果。