Skip to content

Commit

Permalink
Merge branch 'Esri#64/update-geocoder-component-properties' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfranco committed Mar 1, 2013
2 parents 73affb3 + 150ec14 commit c7efc67
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.Map;
import com.esri.ags.components.supportClasses.GeocoderLocatorService;
import com.esri.ags.components.supportClasses.GeocoderLocatorOptions;
import com.esri.ags.components.supportClasses.GeocoderMapService;
import com.esri.ags.components.supportClasses.GeocoderSearchResult;
import com.esri.ags.events.GeocoderEvent;
Expand Down Expand Up @@ -59,7 +59,6 @@
private var resultSimpleMarkerSymbol:SimpleMarkerSymbol;
private var resultSimpleLineSymbol:SimpleLineSymbol;
private var resultSimpleFillSymbol:SimpleFillSymbol;
private var useProxy:Boolean;
private var configXML:XML;
private var configData:ConfigData;
private var popUpRenderer:PopUpRenderer = new PopUpRenderer();
Expand Down Expand Up @@ -109,27 +108,83 @@
_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(<url>{locatorURL}</url>);
}
}
else
{
configXML.appendChild(<usemapservicesonly>true</usemapservicesonly>);
}
var minScore:Number = parseFloat(geocodingXML.minscore[0]);
if (!isNaN(minScore))
{
configXML.appendChild(<minscore>{minScore}</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";
Expand Down Expand Up @@ -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(<locator><url>{url}</url></locator>);
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;
Expand Down Expand Up @@ -736,6 +763,5 @@
fault="geocoder_faultHandler(event)"
map="{map}"
resultAutoSelected="geocoder_resultSelectedHandler(event)"
resultSelected="geocoder_resultSelectedHandler(event)"
useDefaultLocator="false"/>
resultSelected="geocoder_resultSelectedHandler(event)"/>
</s:Group>
14 changes: 8 additions & 6 deletions src/widgets/HeaderController/HeaderControllerWidget.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -476,10 +478,10 @@
</HeaderController:WidgetItemDataGroup>
</s:HGroup>

<components:SingleLineSearch id="singleLineSearch"
width="230" height="28"
includeInLayout="false"
visible="false"/>
<components:GeocoderComponent id="singleLineSearch"
width="230" height="28"
includeInLayout="false"
visible="false"/>

<s:DataGroup id="linkGroup"
dataProvider="{linkList}"
Expand Down

0 comments on commit c7efc67

Please sign in to comment.