From e58978572f60d10d8c2da6b56c5fa47cf1920b05 Mon Sep 17 00:00:00 2001 From: jcfranco Date: Fri, 1 Mar 2013 12:59:56 -0800 Subject: [PATCH 1/3] Update SingleLineSearch to use new Geocoder properties. --- .../viewer/components/SingleLineSearch.mxml | 213 ++++++++---------- 1 file changed, 90 insertions(+), 123 deletions(-) diff --git a/src/com/esri/viewer/components/SingleLineSearch.mxml b/src/com/esri/viewer/components/SingleLineSearch.mxml index b080669..7da7dd3 100644 --- a/src/com/esri/viewer/components/SingleLineSearch.mxml +++ b/src/com/esri/viewer/components/SingleLineSearch.mxml @@ -24,7 +24,7 @@ 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 +155,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; } - - var urlVars:URLVariables = new URLVariables(); - urlVars.f = "json"; - - locatorInfoRequest.execute(urlVars, - new AsyncResponder(locatorInfoRequest_resultHandler, - locatorInfoRequest_faultHandler, - locatorService)); - - function locatorInfoRequest_resultHandler(locatorInfo:Object, locatorService:GeocoderLocatorService):void + else { - if (locatorInfo.singleLineAddressField) - { - locatorService.singleLineAddressFieldName = locatorInfo.singleLineAddressField.name; - } - else - { - showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH); - } - - locatorServices.push(locatorService); - locatorProcessed(); + showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH); } - 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(); - } + locatorServicesConfigured = true; } - function locatorProcessed():void + function locatorInfoRequest_faultHandler(fault:Fault, token:Object = null):void { - locatorsToConfigure--; - if (locatorsToConfigure == 0) - { - geocoder.locatorServices = locatorServices; - locatorServicesConfigured = true; - } + 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; + } } - private function configureMapServices():void + private function parseLocatorOptions(locatorOptionsXML:XML):GeocoderLocatorOptions { - var mapServicesEnabled:Boolean = - configXML.searchlayers.@enabled[0] != "false" && configXML.searchlayers[0] != null; + var locatorOptions:GeocoderLocatorOptions = new GeocoderLocatorOptions(); - if (mapServicesEnabled) + if (locatorOptionsXML) { - if (configXML.searchlayers.length() > 0) + locatorOptions.name = locatorOptionsXML.name.toString(); + locatorOptions.sourceCountry = locatorOptionsXML.sourcecountry.toString(); + locatorOptions.prefix = locatorOptionsXML.prefix.toString(); + locatorOptions.suffix = locatorOptionsXML.suffix.toString(); + + var configOutFields:String = locatorOptionsXML.outfields.toString(); + if (configOutFields) { - var mapService:GeocoderMapService; - var mapServices:Array = []; - var useMapServiceProxy:Boolean; - var mapServiceProxyURL:String; + locatorOptions.outFields = configOutFields.split(','); + } - for each (var searchLayerXML:XML in configXML.searchlayers.searchlayer) + var singleLineAddressField:String = locatorOptionsXML.singlelineaddressfield.toString(); + if (singleLineAddressField) + { + locatorOptions.singleLineAddressFieldName = singleLineAddressField; + } + } + + return locatorOptions; + } + + private function configureMapServices():void + { + if (configXML.mapservices.length() > 0) + { + var mapService:GeocoderMapService; + var mapServices:Array = []; + var useMapServiceProxy:Boolean; + var mapServiceProxyURL:String; + + 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 +704,5 @@ fault="geocoder_faultHandler(event)" map="{map}" resultAutoSelected="geocoder_resultSelectedHandler(event)" - resultSelected="geocoder_resultSelectedHandler(event)" - useDefaultLocator="false"/> + resultSelected="geocoder_resultSelectedHandler(event)"/> From c7b835d1825f570e3df8bbf98818b391f7ff6708 Mon Sep 17 00:00:00 2001 From: jcfranco Date: Fri, 1 Mar 2013 13:19:00 -0800 Subject: [PATCH 2/3] Add method for migrating SingleLineSearch config. --- .../viewer/components/SingleLineSearch.mxml | 61 ++++++++++++++++++- .../HeaderControllerWidget.mxml | 6 +- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/com/esri/viewer/components/SingleLineSearch.mxml b/src/com/esri/viewer/components/SingleLineSearch.mxml index 7da7dd3..bf0cbfa 100644 --- a/src/com/esri/viewer/components/SingleLineSearch.mxml +++ b/src/com/esri/viewer/components/SingleLineSearch.mxml @@ -108,13 +108,72 @@ _hostBaseWidget = value; if (_hostBaseWidget) { - configXML = _hostBaseWidget.configXML.search[0]; + configXML = ensureLatestConfig(_hostBaseWidget.configXML.search[0] + || _hostBaseWidget.configXML.geocoder[0]); configData = _hostBaseWidget.configData; map = _hostBaseWidget.map; init(); } } + private function ensureLatestConfig(configXML:XML):XML + { + if (configXML.name() == "search") + { + configXML.setName("geocoder"); + + var geocodingXML:XML = configXML.geocoding[0]; + if (geocodingXML) + { + var geocoderEnabled:Boolean = geocodingXML.@enabled != "false"; + if (geocoderEnabled) + { + var locatorURL:String = geocodingXML.locator[0]; + if (locatorURL) + { + configXML.appendChild({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) diff --git a/src/widgets/HeaderController/HeaderControllerWidget.mxml b/src/widgets/HeaderController/HeaderControllerWidget.mxml index 572f610..138b991 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; From 150ec1488ee71c30211c4c33019c3d212fc03c7a Mon Sep 17 00:00:00 2001 From: jcfranco Date: Fri, 1 Mar 2013 13:48:08 -0800 Subject: [PATCH 3/3] Rename SingleLineSearch to GeocoderComponent. --- .../{SingleLineSearch.mxml => GeocoderComponent.mxml} | 0 src/widgets/HeaderController/HeaderControllerWidget.mxml | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/com/esri/viewer/components/{SingleLineSearch.mxml => GeocoderComponent.mxml} (100%) diff --git a/src/com/esri/viewer/components/SingleLineSearch.mxml b/src/com/esri/viewer/components/GeocoderComponent.mxml similarity index 100% rename from src/com/esri/viewer/components/SingleLineSearch.mxml rename to src/com/esri/viewer/components/GeocoderComponent.mxml diff --git a/src/widgets/HeaderController/HeaderControllerWidget.mxml b/src/widgets/HeaderController/HeaderControllerWidget.mxml index 138b991..348776c 100644 --- a/src/widgets/HeaderController/HeaderControllerWidget.mxml +++ b/src/widgets/HeaderController/HeaderControllerWidget.mxml @@ -478,10 +478,10 @@ - +