diff --git a/src/com/esri/viewer/components/SingleLineSearch.mxml b/src/com/esri/viewer/components/GeocoderComponent.mxml similarity index 79% rename from src/com/esri/viewer/components/SingleLineSearch.mxml rename to src/com/esri/viewer/components/GeocoderComponent.mxml index b080669..bf0cbfa 100644 --- a/src/com/esri/viewer/components/SingleLineSearch.mxml +++ b/src/com/esri/viewer/components/GeocoderComponent.mxml @@ -24,7 +24,7 @@ {locatorURL}); + } + } + else + { + configXML.appendChild(true); + } + + var minScore:Number = parseFloat(geocodingXML.minscore[0]); + if (!isNaN(minScore)) + { + configXML.appendChild({minScore}); + } + + delete configXML.geocoding[0]; + } + + var searchLayersXML:XML = configXML.searchlayers[0]; + if (searchLayersXML) + { + var searchLayersEnabled:Boolean = searchLayersXML.@enabled != "false"; + + if (searchLayersEnabled) + { + searchLayersXML.setName("mapservices"); + + for each (var searchLayerXML:XML in searchLayersXML.searchlayer) + { + searchLayerXML.setName("mapservice"); + } + + delete searchLayersXML.@enabled; + } + else + { + delete configXML.searchlayers; + } + } + } + + return configXML; + } + private function init():void { if (configXML) { - useProxy = configXML.useproxy[0] == "true"; - const configZoomScale:Number = parseFloat(configXML.zoomscale[0]); if (configZoomScale > 0) { zoomScale = configZoomScale; } - //backwards compatibility - const configMinScore:Number = parseFloat(configXML.minscore[0]) || parseFloat(configXML.geocoding.minscore[0]); + const configMinScore:Number = parseFloat(configXML.minscore[0]); geocoder.minScore = (configMinScore > 0) ? configMinScore : 40; geocoder.autoComplete = configXML.autocomplete != "false"; @@ -159,166 +214,138 @@ configureResultSymbols(); configureResultGraphic(); - configureLocatorServices(); + configureLocator(); configureMapServices(); } } - private function configureLocatorServices():void + private function configureLocator():void { - var locatorServicesEnabled:Boolean = (configXML.geocoding.@enabled[0] != "false"); - if (!locatorServicesEnabled) + var locatorDisabled:Boolean = (configXML.usemapservicesonly[0] == "true"); + if (locatorDisabled) { + geocoder.url = null; locatorServicesConfigured = true; return; } - if (configXML.geocoding.@usedefaultlocator[0] != "false") + var locatorURL:String = configXML.url.toString(); + if (locatorURL) { - geocoder.useDefaultLocator = true; - - if (useProxy && configData.proxyUrl) - { - geocoder.defaultLocatorProxyURL = configData.proxyUrl; - } + geocoder.url = locatorURL; } - //backwards compatibility - if (configXML.geocoding.locator[0] - && configXML.geocoding.locator.hasSimpleContent()) + var useProxy:Boolean = configXML.useproxy[0] == "true"; + if (useProxy && configData.proxyUrl) { - //convert URL to locator XML - var url:String = configXML.geocoding.locator[0]; - delete configXML.geocoding.locator[0]; - configXML.geocoding.appendChild({url}); + geocoder.proxyURL = configData.proxyUrl; } - var locatorsToConfigure:int = configXML.geocoding.locator.length(); - if (locatorsToConfigure == 0) - { - locatorServicesConfigured = true; - return; - } + geocoder.locatorOptions = parseLocatorOptions(configXML.locatoroptions[0]); - var locatorServices:Array = []; - var locatorService:GeocoderLocatorService; + var hasUserDefinedLocatorWithMissingSingleLineAddressField:Boolean = + locatorURL && !geocoder.locatorOptions.singleLineAddressFieldName; - for each (var locatorXML:XML in configXML.geocoding.locator) + if (hasUserDefinedLocatorWithMissingSingleLineAddressField) { - locatorService = new GeocoderLocatorService(); - locatorService.url = locatorXML.url.toString(); - locatorService.name = locatorXML.name.toString(); - locatorService.sourceCountry = locatorXML.sourcecountry.toString(); - locatorService.prefix = locatorXML.prefix.toString(); - locatorService.suffix = locatorXML.suffix.toString(); - - var configOutFields:String = locatorXML.outfields.toString(); - if (configOutFields) + const locatorInfoRequest:JSONTask = new JSONTask(); + locatorInfoRequest.url = locatorURL; + if (useProxy && configData.proxyUrl) { - locatorService.outFields = configOutFields.split(','); + locatorInfoRequest.proxyURL = configData.proxyUrl; } - var useLocatorProxy:Boolean = locatorXML.useproxy[0] == "true"; - if (useLocatorProxy && configData.proxyUrl) - { - locatorService.proxyURL = configData.proxyUrl; - } + var urlVars:URLVariables = new URLVariables(); + urlVars.f = "json"; - var singleLineAddressField:String = locatorXML.singlelineaddressfield.toString(); - if (singleLineAddressField) - { - locatorService.singleLineAddressFieldName = singleLineAddressField; - locatorServices.push(locatorService); - locatorProcessed(); - } - else + locatorInfoRequest.execute(urlVars, + new AsyncResponder(locatorInfoRequest_resultHandler, + locatorInfoRequest_faultHandler)); + + function locatorInfoRequest_resultHandler(locatorInfo:Object, token:Object = null):void { - const locatorInfoRequest:JSONTask = new JSONTask(); - locatorInfoRequest.url = locatorService.url; - if (useLocatorProxy && configData.proxyUrl) + if (locatorInfo.singleLineAddressField) { - locatorInfoRequest.proxyURL = locatorService.proxyURL; + geocoder.locatorOptions.singleLineAddressFieldName = locatorInfo.singleLineAddressField.name; + } + else + { + showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH); } - var urlVars:URLVariables = new URLVariables(); - urlVars.f = "json"; + locatorServicesConfigured = true; + } - locatorInfoRequest.execute(urlVars, - new AsyncResponder(locatorInfoRequest_resultHandler, - locatorInfoRequest_faultHandler, - locatorService)); + function locatorInfoRequest_faultHandler(fault:Fault, token:Object = null):void + { + const errorMessage:String = hostBaseWidget.getDefaultString("locatorServiceConnectionError", + locatorInfoRequest.url, + ErrorMessageUtil.getKnownErrorCauseMessage(fault), + ErrorMessageUtil.makeHTMLSafe(fault.toString())); + showError(errorMessage, SINGLE_LINE_SEARCH); + locatorServicesConfigured = true; + } + } + else + { + locatorServicesConfigured = true; + } + } - function locatorInfoRequest_resultHandler(locatorInfo:Object, locatorService:GeocoderLocatorService):void - { - if (locatorInfo.singleLineAddressField) - { - locatorService.singleLineAddressFieldName = locatorInfo.singleLineAddressField.name; - } - else - { - showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH); - } + private function parseLocatorOptions(locatorOptionsXML:XML):GeocoderLocatorOptions + { + var locatorOptions:GeocoderLocatorOptions = new GeocoderLocatorOptions(); - locatorServices.push(locatorService); - locatorProcessed(); - } + if (locatorOptionsXML) + { + locatorOptions.name = locatorOptionsXML.name.toString(); + locatorOptions.sourceCountry = locatorOptionsXML.sourcecountry.toString(); + locatorOptions.prefix = locatorOptionsXML.prefix.toString(); + locatorOptions.suffix = locatorOptionsXML.suffix.toString(); - function locatorInfoRequest_faultHandler(fault:Fault, locatorService:GeocoderLocatorService):void - { - const errorMessage:String = hostBaseWidget.getDefaultString("locatorServiceConnectionError", - locatorService.url, - ErrorMessageUtil.getKnownErrorCauseMessage(fault), - ErrorMessageUtil.makeHTMLSafe(fault.toString())); - showError(errorMessage, SINGLE_LINE_SEARCH); - locatorProcessed(); - } + var configOutFields:String = locatorOptionsXML.outfields.toString(); + if (configOutFields) + { + locatorOptions.outFields = configOutFields.split(','); } - function locatorProcessed():void + var singleLineAddressField:String = locatorOptionsXML.singlelineaddressfield.toString(); + if (singleLineAddressField) { - locatorsToConfigure--; - if (locatorsToConfigure == 0) - { - geocoder.locatorServices = locatorServices; - locatorServicesConfigured = true; - } + locatorOptions.singleLineAddressFieldName = singleLineAddressField; } } + + return locatorOptions; } private function configureMapServices():void { - var mapServicesEnabled:Boolean = - configXML.searchlayers.@enabled[0] != "false" && configXML.searchlayers[0] != null; - - if (mapServicesEnabled) + if (configXML.mapservices.length() > 0) { - if (configXML.searchlayers.length() > 0) - { - var mapService:GeocoderMapService; - var mapServices:Array = []; - var useMapServiceProxy:Boolean; - var mapServiceProxyURL:String; + var mapService:GeocoderMapService; + var mapServices:Array = []; + var useMapServiceProxy:Boolean; + var mapServiceProxyURL:String; - for each (var searchLayerXML:XML in configXML.searchlayers.searchlayer) + for each (var mapServiceXML:XML in configXML.mapservices.mapservice) + { + mapService = new GeocoderMapService(); + mapService.layerIds = mapServiceXML.layerids.toString().split(","); + mapService.url = mapServiceXML.url.toString(); + mapService.searchFields = mapServiceXML.searchfields.toString().split(","); + mapService.name = mapServiceXML.name.toString(); + useMapServiceProxy = mapServiceXML.useproxy[0] == "true"; + + if (useMapServiceProxy && configData.proxyUrl) { - mapService = new GeocoderMapService(); - mapService.layerIds = searchLayerXML.layerids.toString().split(","); - mapService.url = searchLayerXML.url.toString(); - mapService.searchFields = searchLayerXML.searchfields.toString().split(","); - mapService.name = searchLayerXML.name.toString(); - useMapServiceProxy = searchLayerXML.useproxy[0] == "true"; - - if (useMapServiceProxy && configData.proxyUrl) - { - mapService.proxyURL = configData.proxyUrl; - } - - mapServices.push(mapService); + mapService.proxyURL = configData.proxyUrl; } - geocoder.mapServices = mapServices; + mapServices.push(mapService); } + + geocoder.mapServices = mapServices; } mapServicesConfigured = true; @@ -736,6 +763,5 @@ fault="geocoder_faultHandler(event)" map="{map}" resultAutoSelected="geocoder_resultSelectedHandler(event)" - resultSelected="geocoder_resultSelectedHandler(event)" - useDefaultLocator="false"/> + resultSelected="geocoder_resultSelectedHandler(event)"/> diff --git a/src/widgets/HeaderController/HeaderControllerWidget.mxml b/src/widgets/HeaderController/HeaderControllerWidget.mxml index 572f610..348776c 100644 --- a/src/widgets/HeaderController/HeaderControllerWidget.mxml +++ b/src/widgets/HeaderController/HeaderControllerWidget.mxml @@ -119,8 +119,10 @@ { if (configXML) { - const shouldEnableSearch:Boolean = (configXML.search.@visible[0] == "true") - || (configXML.search[0] && !configXML.search.@visible[0]); + var searchConfig:XML = configXML.geocoder[0] || configXML.search[0]; + + const shouldEnableSearch:Boolean = (searchConfig.@visible[0] == "true") + || (searchConfig[0] && !searchConfig.@visible[0]); if (shouldEnableSearch) { singleLineSearch.hostBaseWidget = this; @@ -476,10 +478,10 @@ - +