ArcGIS Server 开发实践之Search类

Posted 东腾的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArcGIS Server 开发实践之Search类相关的知识,希望对你有一定的参考价值。

开发中整理的。不足之处还请谅解!




----------------------------------------------- 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 popups 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 Searchs 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 sources 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 widgets 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 widgets 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 //适用于指定的源。如果结果没有一个关联的程度,指定要使用这个号码的缩放尺度结果。

 

以上是关于ArcGIS Server 开发实践之Search类的主要内容,如果未能解决你的问题,请参考以下文章

ArcGIS Maritime Server 开发教程Maritime Service 开发实践

ArcGIS Server SOE开发之奇怪异常:

ArcMap AddIn之下载ArcGIS Server地图服务中的数据

ArcGIS10.1之crossdomain文件

ArcGIS Maritime Server 开发教程了解 ArcGIS Maritime Server

ArcGIS Maritime Server 开发教程了解 ArcGIS Maritime Server