diff --git a/src/com/esri/viewer/components/SingleLineSearch.mxml b/src/com/esri/viewer/components/SingleLineSearch.mxml
new file mode 100644
index 0000000..7398438
--- /dev/null
+++ b/src/com/esri/viewer/components/SingleLineSearch.mxml
@@ -0,0 +1,739 @@
+
+
+
+
+ 0)
+ {
+ useProxy = configXML.useproxy == "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]);
+ geocoder.minScore = (configMinScore > 0) ? configMinScore : 40;
+
+ geocoder.autoComplete = configXML.autocomplete != "false";
+
+ const configMaxLocations:int = parseInt(configXML.maxlocations[0])
+ if (!isNaN(configMaxLocations) && configMaxLocations > 0)
+ {
+ geocoder.maxLocations = configMaxLocations;
+ }
+
+ const configMinChars:int = parseInt(configXML.minchars[0])
+ if (configMinChars && configMinChars > 0)
+ {
+ geocoder.minCharacters = configMinChars;
+ }
+
+ const configSearchDelay:int = parseInt(configXML.searchdelay[0])
+ if (configSearchDelay && configSearchDelay > 0)
+ {
+ geocoder.searchDelay = configSearchDelay;
+ }
+
+ geocoder.prompt = configXML.labels.searchprompt[0] || hostBaseWidget.getDefaultString("searchPrompt");
+ geocoder.noResultsText = configXML.labels.noresults[0] || hostBaseWidget.getDefaultString("noResultsFoundLabel");
+ searchResultTitleLabel = configXML.labels.searchresulttitle[0] || hostBaseWidget.getDefaultString("searchResultTitleLabel");
+
+ configureResultSymbols();
+ configureResultGraphic();
+
+ configureLocatorServices();
+ configureMapServices();
+ }
+ }
+
+ private function configureLocatorServices():void
+ {
+ var locatorServicesEnabled:Boolean = (configXML.geocoding.@enabled[0] != "false");
+ if (!locatorServicesEnabled)
+ {
+ locatorServicesConfigured = true;
+ return;
+ }
+
+ if (configXML.geocoding.@usedefaultlocator[0] != "false")
+ {
+ geocoder.useDefaultLocator = true;
+ }
+
+ //backwards compatibility
+ if (configXML.geocoding.locator[0]
+ && configXML.geocoding.locator.hasSimpleContent())
+ {
+ //convert URL to locator XML
+ var url:String = configXML.geocoding.locator[0];
+ delete configXML.geocoding.locator[0];
+ configXML.geocoding.appendChild({url});
+ }
+
+ var locatorsToConfigure:int = configXML.geocoding.locator.length();
+ if (locatorsToConfigure == 0)
+ {
+ locatorServicesConfigured = true;
+ return;
+ }
+
+ var locatorServices:Array = [];
+ var locatorService:GeocoderLocatorService;
+
+ for each (var locatorXML:XML in configXML.geocoding.locator)
+ {
+ 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)
+ {
+ locatorService.outFields = configOutFields.split(',');
+ }
+
+ var locatorServiceProxyURL:String = locatorXML.proxyurl.toString() || configData.proxyUrl;
+ if (useProxy && locatorServiceProxyURL)
+ {
+ locatorService.proxyURL = locatorServiceProxyURL;
+ }
+
+ var singleLineAddressField:String = locatorXML.singlelineaddressfield.toString();
+ if (singleLineAddressField)
+ {
+ locatorService.singleLineAddressFieldName = singleLineAddressField;
+ locatorServices.push(locatorService);
+ locatorProcessed();
+ }
+ else
+ {
+ const locatorInfoRequest:JSONTask = new JSONTask();
+ locatorInfoRequest.url = locatorService.url;
+ if (useProxy && locatorServiceProxyURL)
+ {
+ locatorInfoRequest.proxyURL = locatorService.proxyURL;
+ }
+
+ 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
+ {
+ if (locatorInfo.singleLineAddressField)
+ {
+ locatorService.singleLineAddressFieldName = locatorInfo.singleLineAddressField.name;
+ }
+ else
+ {
+ showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH);
+ }
+
+ locatorServices.push(locatorService);
+ locatorProcessed();
+ }
+
+ 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();
+ }
+ }
+
+ function locatorProcessed():void
+ {
+ locatorsToConfigure--;
+ if (locatorsToConfigure == 0)
+ {
+ geocoder.locatorServices = locatorServices;
+ locatorServicesConfigured = true;
+ }
+ }
+ }
+ }
+
+ private function configureMapServices():void
+ {
+ var mapServicesEnabled:Boolean =
+ configXML.searchlayers.@enabled[0] != "false" && configXML.searchlayers[0] != null;
+
+ if (mapServicesEnabled)
+ {
+ if (configXML.searchlayers.length() > 0)
+ {
+ var mapService:GeocoderMapService;
+ var mapServices:Array = [];
+ var mapServiceProxyURL:String;
+
+ for each (var searchLayerXML:XML in configXML.searchlayers.searchlayer)
+ {
+ 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();
+ mapServiceProxyURL = searchLayerXML.proxyurl.toString() || configData.proxyUrl;
+
+ if (useProxy && mapServiceProxyURL)
+ {
+ mapService.proxyURL = mapServiceProxyURL;
+ }
+
+ mapServices.push(mapService);
+ }
+
+ geocoder.mapServices = mapServices;
+ }
+ }
+
+ mapServicesConfigured = true;
+ }
+
+ private function configureResultSymbols():void
+ {
+ if (configXML.symbols[0])
+ {
+ const smsColor:uint = configXML.symbols.simplemarkersymbol.@color || 0xFF0000;
+ const smsAlpha:Number = (configXML.symbols.simplemarkersymbol.@alpha[0] != null) ? configXML.symbols.simplemarkersymbol.@alpha : 0.8;
+ const smsSize:Number = (configXML.symbols.simplemarkersymbol.@size[0] != null) ? configXML.symbols.simplemarkersymbol.@size : 15;
+ const smsOutlineColor:uint = configXML.symbols.simplefillsymbol.outline.@color || 0xFF0000;
+ const smsOutlineAlpha:Number = (configXML.symbols.simplefillsymbol.outline.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.outline.@alpha : 0.8;
+ const smsOutlineWidth:Number = (configXML.symbols.simplefillsymbol.outline.@width[0] != null) ? configXML.symbols.simplefillsymbol.outline.@width : 2;
+
+ resultSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, smsSize, smsColor, smsAlpha, 0, 0, 0,
+ new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
+ smsOutlineColor,
+ smsOutlineAlpha,
+ smsOutlineWidth));
+
+ const slsColor:uint = configXML.symbols.simplelinesymbol.@color || 0xFF0000;
+ const slsAlpha:Number = (configXML.symbols.simplelinesymbol.@alpha[0] != null) ? configXML.symbols.simplelinesymbol.@alpha : 0.8;
+ const slsWidth:Number = (configXML.symbols.simplelinesymbol.@width[0] != null) ? configXML.symbols.simplelinesymbol.@width : 2;
+
+ resultSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, slsColor, slsAlpha, slsWidth);
+
+ const sfsColor:uint = configXML.symbols.simplefillsymbol.@color || 0xFF0000;
+ const sfsAlpha:Number = (configXML.symbols.simplefillsymbol.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.@alpha : 0.5;
+ const sfsOutlineColor:uint = configXML.symbols.simplefillsymbol.outline.@color || 0xFF0000;
+ const sfsOutlineAlpha:Number = (configXML.symbols.simplefillsymbol.outline.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.outline.@alpha : 0.8;
+ const sfsOutlineWidth:Number = (configXML.symbols.simplefillsymbol.outline.@width[0] != null) ? configXML.symbols.simplefillsymbol.outline.@width : 2;
+
+ resultSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, sfsColor, sfsAlpha,
+ new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
+ sfsOutlineColor,
+ sfsOutlineAlpha,
+ sfsOutlineWidth));
+ }
+ }
+
+ private function configureResultGraphic():void
+ {
+ searchResultGraphic = new com.esri.ags.Graphic()
+ const clearFeatureLabel:String = configXML.labels.clearfeaturelabel[0] || hostBaseWidget.getDefaultString("clearLabel");
+ const customContextMenu:ContextMenu = new ContextMenu();
+ customContextMenu.hideBuiltInItems();
+ const menuItem:ContextMenuItem = new ContextMenuItem(clearFeatureLabel);
+ menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItem_contextMenuDeleteHandler);
+ customContextMenu.customItems.push(menuItem);
+ searchResultGraphic.contextMenu = customContextMenu;
+ }
+
+ private function menuItem_contextMenuDeleteHandler(event:ContextMenuEvent):void
+ {
+ if (map.infoWindow.contentOwner == searchResultGraphic)
+ {
+ map.infoWindow.hide();
+ }
+ map.defaultGraphicsLayer.remove(searchResultGraphic);
+ }
+
+ override protected function commitProperties():void
+ {
+ super.commitProperties();
+
+ if (locatorServicesConfigured && mapServicesConfigured)
+ {
+ configureSearchInput();
+ }
+ }
+
+ private function configureSearchInput():void
+ {
+ const urlSearchTerm:String = ViewerContainer.urlConfigParams.search;
+ if (urlSearchTerm)
+ {
+ geocoder.text = urlSearchTerm;
+ geocoder.search();
+ }
+ }
+
+ //assumes search result SR compatible with map's
+ private function showSearchResultOnMap(searchResult:GeocoderSearchResult):void
+ {
+ if (!searchResult)
+ {
+ return;
+ }
+
+ searchResultGraphic.geometry = searchResult.geometry;
+ searchResultGraphic.symbol = getSymbolForGeometryType(searchResultGraphic.geometry.type);
+ var resultExtent:Extent = searchResult.extent;
+
+ const popUpInfo:PopUpInfo = new PopUpInfo();
+ popUpInfo.description = searchResult.label;
+ popUpInfo.title = searchResultTitleLabel;
+ popUpInfo.showZoomToButton = false; //hide the zoom to button as map would be zoomed-in
+
+ const infoWindowRenderer:ClassFactory = new ClassFactory(PopUpRenderer);
+ infoWindowRenderer.properties = { popUpInfo: popUpInfo };
+ searchResultGraphic.infoWindowRenderer = infoWindowRenderer;
+
+ popUpRenderer.popUpInfo = popUpInfo;
+ popUpRenderer.graphic = searchResultGraphic;
+
+ map.defaultGraphicsLayer.remove(searchResultGraphic);
+ if (searchResultGraphic.symbol)
+ {
+ map.defaultGraphicsLayer.add(searchResultGraphic);
+ }
+
+ const resultPoint:MapPoint = getGeometryCenter(searchResultGraphic.geometry);
+
+ if (resultExtent)
+ {
+ map.zoomTo(resultExtent);
+ }
+ else
+ {
+ if (searchResultGraphic.geometry.type == Geometry.MAPPOINT)
+ {
+ if (map.scale > zoomScale)
+ {
+ map.scale = zoomScale;
+ }
+ }
+
+ map.zoomTo(searchResultGraphic.geometry);
+ }
+
+ infoWindowShow(resultPoint);
+ }
+
+ private function getSymbolForGeometryType(geometryType:String):Symbol
+ {
+ var symbol:Symbol;
+
+ switch (geometryType)
+ {
+ case Geometry.POLYLINE:
+ {
+ symbol = resultSimpleLineSymbol;
+ break;
+ }
+ case Geometry.POLYGON:
+ {
+ symbol = resultSimpleFillSymbol;
+ break;
+ }
+ case Geometry.MAPPOINT:
+ default:
+ {
+ symbol = resultSimpleMarkerSymbol;
+ }
+ }
+
+ return symbol;
+ }
+
+ private function getGeometryCenter(geometry:Geometry):MapPoint
+ {
+ var center:MapPoint;
+
+ if (geometry is MapPoint)
+ {
+ center = geometry as MapPoint;
+ }
+ else if (geometry)
+ {
+ center = geometry.extent.center;
+ }
+
+ return center;
+ }
+
+ private function infoWindowShow(point:MapPoint):void
+ {
+ map.infoWindow.content = popUpRenderer;
+ map.infoWindow.contentOwner = popUpRenderer.graphic;
+ map.infoWindow.show(point);
+ }
+
+ protected function geocoder_searchCompleteHandler(event:GeocoderEvent):void
+ {
+ projectToMapSpatialReferenceAndShowResultOnMap(event.searchResult);
+ }
+
+ private function projectToMapSpatialReferenceAndShowResultOnMap(searchResult:GeocoderSearchResult):void
+ {
+ var needToProjectGeometryServerSide:Boolean;
+ if (map.spatialReference.isWebMercator()
+ && searchResult.geometry.spatialReference
+ && searchResult.geometry.spatialReference.wkid == 4326)
+ {
+ searchResult.geometry = WebMercatorUtil.geographicToWebMercator(searchResult.geometry);
+ }
+ else if (map.spatialReference.wkid == 4326
+ && searchResult.geometry.spatialReference
+ && searchResult.geometry.spatialReference.isWebMercator())
+ {
+ searchResult.geometry = WebMercatorUtil.webMercatorToGeographic(searchResult.geometry);
+ }
+ else if (!map.spatialReference.equals(searchResult.geometry.spatialReference))
+ {
+ needToProjectGeometryServerSide = true;
+ }
+
+ var needToProjectExtentServerSide:Boolean;
+ if (searchResult.extent)
+ {
+ if (map.spatialReference.isWebMercator()
+ && searchResult.extent.spatialReference.wkid == 4326)
+ {
+ searchResult.extent = WebMercatorUtil.geographicToWebMercator(searchResult.extent) as Extent;
+ }
+ else if (map.spatialReference.wkid == 4326
+ && searchResult.extent.spatialReference
+ && searchResult.extent.spatialReference.isWebMercator())
+ {
+ //do nothing since we're assuming the search result extent's SR is in Geographic
+ }
+ else if (!map.spatialReference.equals(searchResult.extent.spatialReference))
+ {
+ needToProjectExtentServerSide = true;
+ }
+ }
+
+ var previousShowBusyCursorValue:Boolean = GeometryServiceSingleton.instance.showBusyCursor;
+ if (needToProjectGeometryServerSide)
+ {
+ projectGeometryServerSide();
+ }
+ else if (needToProjectExtentServerSide)
+ {
+ projectExtentServerSide();
+ }
+ else
+ {
+ handleProjectionComplete();
+ }
+
+ function projectGeometryServerSide():void
+ {
+ var projectionParams:ProjectParameters = new ProjectParameters();
+ projectionParams.geometries = [ searchResult.geometry ];
+ projectionParams.outSpatialReference = map.spatialReference;
+ GeometryServiceSingleton.instance.showBusyCursor = true;
+ GeometryServiceSingleton.instance.project(
+ projectionParams, new AsyncResponder(projectGeometryResultHandler,
+ projectFaultHandler));
+ }
+
+ function projectGeometryResultHandler(geometry:Array, token:Object = null):void
+ {
+ searchResult.geometry = geometry[0];
+ if (needToProjectExtentServerSide)
+ {
+ projectExtentServerSide();
+ }
+ else
+ {
+ handleProjectionComplete();
+ }
+ }
+
+ function projectExtentServerSide():void
+ {
+ var projectionParams:ProjectParameters = new ProjectParameters();
+ projectionParams.geometries = [ searchResult.extent ];
+ projectionParams.outSpatialReference = map.spatialReference;
+ GeometryServiceSingleton.instance.showBusyCursor = true;
+ GeometryServiceSingleton.instance.project(
+ projectionParams, new AsyncResponder(projectExtentResultHandler,
+ projectFaultHandler));
+ }
+
+ function projectExtentResultHandler(extent:Array, token:Object = null):void
+ {
+ searchResult.extent = extent[0];
+ handleProjectionComplete();
+ }
+
+ function handleProjectionComplete():void
+ {
+ GeometryServiceSingleton.instance.showBusyCursor = previousShowBusyCursorValue;
+ var resultHasValidGeometry:Boolean = hasValidGeometry(searchResult.geometry);
+ var resultHasExtentAndIsValid:Boolean = searchResult.extent && hasValidGeometry(searchResult.extent);
+ if (resultHasExtentAndIsValid && resultHasValidGeometry
+ || resultHasValidGeometry)
+ {
+ showSearchResultOnMap(searchResult);
+ }
+ else
+ {
+ showError(hostBaseWidget.getDefaultString("cannotDisplayResult"), SINGLE_LINE_SEARCH);
+ }
+ }
+
+ function projectFaultHandler(fault:Fault, token:Object = null):void
+ {
+ showError(hostBaseWidget.getDefaultString("projectionError",
+ ErrorMessageUtil.makeHTMLSafe(fault.toString())), SINGLE_LINE_SEARCH);
+ }
+ }
+
+ private function hasValidGeometry(geometry:Geometry):Boolean
+ {
+ var isValid:Boolean;
+ if (geometry)
+ {
+ if (geometry.type == Geometry.MAPPOINT)
+ {
+ isValid = isValidMapPoint(geometry as MapPoint);
+ }
+ else if (geometry.type == Geometry.MULTIPOINT)
+ {
+ isValid = isValidMultiPoint(geometry as Multipoint);
+ }
+ else if (geometry.type == Geometry.EXTENT)
+ {
+ isValid = isValidPolygon((geometry as Extent).toPolygon());
+ }
+ else if (geometry.type == Geometry.POLYGON)
+ {
+ isValid = isValidPolygon(geometry as Polygon);
+ }
+ else if (geometry.type == Geometry.POLYLINE)
+ {
+ isValid = isValidPolyline(geometry as Polyline);
+ }
+ }
+ return isValid;
+ }
+
+ private function isValidMapPoint(point:MapPoint):Boolean
+ {
+ return point && !isNaN(point.x) && !isNaN(point.y);
+ }
+
+ private function isValidMultiPoint(multiPoint:Multipoint):Boolean
+ {
+ return hasValidMapPoints(multiPoint.points);
+ }
+
+ private function hasValidMapPoints(points:Array):Boolean
+ {
+ var isValid:Boolean;
+ if (points && points.length > 0)
+ {
+ isValid = true;
+ for each (var point:MapPoint in points)
+ {
+ if (!isValidMapPoint(point))
+ {
+ isValid = false;
+ break;
+ }
+ }
+ }
+ return isValid;
+ }
+
+ private function isValidPolyline(polyline:Polyline):Boolean
+ {
+ var isValid:Boolean;
+ if (polyline && polyline.paths && polyline.paths.length > 0)
+ {
+ isValid = true;
+ for each (var path:Array in polyline.paths)
+ {
+ if (!hasValidMapPoints(path))
+ {
+ isValid = false;
+ break;
+ }
+ }
+ }
+ return isValid;
+ }
+
+ private function isValidPolygon(polygon:Polygon):Boolean
+ {
+ var isValid:Boolean;
+ if (polygon && polygon.rings && polygon.rings.length > 0)
+ {
+ isValid = true;
+ for each (var ring:Array in polygon.rings)
+ {
+ if (!hasValidMapPoints(ring))
+ {
+ isValid = false;
+ break;
+ }
+ }
+ }
+ return isValid;
+ }
+
+ protected function geocoder_faultHandler(event:FaultEvent):void
+ {
+ showError(ErrorMessageUtil.buildFaultMessage(event.fault), SINGLE_LINE_SEARCH);
+ }
+
+ private function showError(message:String, title:String = null):void
+ {
+ _hostBaseWidget.showError(message, title);
+ }
+ ]]>
+
+
+
+
diff --git a/src/com/esri/viewer/components/singleLineSearch/ResultList.as b/src/com/esri/viewer/components/singleLineSearch/ResultList.as
deleted file mode 100644
index 527bacf..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/ResultList.as
+++ /dev/null
@@ -1,26 +0,0 @@
-///////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2010-2011 Esri. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-///////////////////////////////////////////////////////////////////////////
-package com.esri.viewer.components.singleLineSearch
-{
-
-import spark.components.List;
-
-public class ResultList extends List
-{
- [Bindable]
- public var searchText:String = "";
-}
-}
diff --git a/src/com/esri/viewer/components/singleLineSearch/ResultListItemRenderer.mxml b/src/com/esri/viewer/components/singleLineSearch/ResultListItemRenderer.mxml
deleted file mode 100644
index 064bdec..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/ResultListItemRenderer.mxml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
- $&");
- suggestionLabel.textFlow = TextConverter.importToFlow(suggestionText, TextConverter.TEXT_FIELD_HTML_FORMAT);
- }
- ]]>
-
-
-
-
diff --git a/src/com/esri/viewer/components/singleLineSearch/SearchInputSkin.mxml b/src/com/esri/viewer/components/singleLineSearch/SearchInputSkin.mxml
deleted file mode 100644
index 4cd2406..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/SearchInputSkin.mxml
+++ /dev/null
@@ -1,288 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/com/esri/viewer/components/singleLineSearch/SearchLayer.as b/src/com/esri/viewer/components/singleLineSearch/SearchLayer.as
deleted file mode 100644
index 56e8559..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/SearchLayer.as
+++ /dev/null
@@ -1,25 +0,0 @@
-///////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2010-2011 Esri. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-///////////////////////////////////////////////////////////////////////////
-package com.esri.viewer.components.singleLineSearch
-{
-
-public class SearchLayer
-{
- public var layerIds:Array;
- public var layerURL:String;
- public var searchFields:Array;
-}
-}
diff --git a/src/com/esri/viewer/components/singleLineSearch/SearchResultUtil.as b/src/com/esri/viewer/components/singleLineSearch/SearchResultUtil.as
deleted file mode 100644
index fe80fdd..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/SearchResultUtil.as
+++ /dev/null
@@ -1,55 +0,0 @@
-///////////////////////////////////////////////////////////////////////////
-// Copyright (c) 2010-2011 Esri. All Rights Reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-///////////////////////////////////////////////////////////////////////////
-package com.esri.viewer.components.singleLineSearch
-{
-
-import com.esri.ags.tasks.supportClasses.AddressCandidate;
-import com.esri.ags.tasks.supportClasses.FindResult;
-
-import mx.utils.StringUtil;
-
-public class SearchResultUtil
-{
- public static function searchResultToLabel(searchResult:Object):String
- {
- if (searchResult is FindResult)
- {
- return findResultToLabel(searchResult as FindResult);
- }
- else if (searchResult is AddressCandidate)
- {
- return (searchResult as AddressCandidate).address as String;
- }
- else if (searchResult == null)
- {
- return "";
- }
- else
- {
- return searchResult as String;
- }
- }
-
- private static function findResultToLabel(findResult:FindResult):String
- {
- return StringUtil.substitute('{0} - {1} - {2} ({3})',
- findResult.value,
- findResult.foundFieldName,
- findResult.layerName,
- findResult.layerId);
- }
-}
-}
diff --git a/src/com/esri/viewer/components/singleLineSearch/SingleLineSearch.mxml b/src/com/esri/viewer/components/singleLineSearch/SingleLineSearch.mxml
deleted file mode 100644
index c08c883..0000000
--- a/src/com/esri/viewer/components/singleLineSearch/SingleLineSearch.mxml
+++ /dev/null
@@ -1,1135 +0,0 @@
-
-
-
-
- 0)
- {
- zoomScale = configZoomScale;
- }
-
- const configMinScore:Number = parseFloat(configXML.geocoding.minscore[0]);
- if (configMinScore > 0)
- {
- minscore = configMinScore;
- }
-
- searchPrompt = configXML.labels.searchprompt[0] || hostBaseWidget.getDefaultString("searchPrompt");
- noResultsFoundLabel = configXML.labels.noresults[0] || hostBaseWidget.getDefaultString("noResultsFoundLabel");
- searchResultTitleLabel = configXML.labels.searchresulttitle[0] || hostBaseWidget.getDefaultString("searchResultTitleLabel");
-
- configureResultSymbols();
- configureResultGraphic();
-
- importSearchResultHistory();
-
- isGeocodeEnabled = (configXML.geocoding.@enabled[0] != "false");
- if (isGeocodeEnabled)
- {
- configureLocator();
- }
-
- isFindEnabled = (configXML.searchlayers.@enabled[0] != "false" && configXML.searchlayers[0] != null);
- if (isFindEnabled)
- {
- configureSearchLayers();
- }
- }
- }
-
- private function configureLocator():void
- {
- const url:String = configXML.geocoding.locator[0] || DEFAULT_LOCATOR_URL;
-
- if (configXML.useproxy.length() > 0)
- {
- useProxy = configXML.useproxy == "true";
- }
-
- const locatorService:JSONTask = new JSONTask();
- locatorService.url = url;
- locator.url = url;
-
- if (useProxy && configData.proxyUrl)
- {
- locatorService.proxyURL = configData.proxyUrl;
- locator.proxyURL = configData.proxyUrl;
- }
-
- var urlVars:URLVariables = new URLVariables();
- urlVars.f = "json";
-
- locatorService.execute(urlVars, new AsyncResponder(locatorService_resultHandler, locatorService_faultHandler));
- }
-
- private function locatorService_resultHandler(addressFieldData:Object, token:Object = null):void
- {
- if (addressFieldData.singleLineAddressField)
- {
- singleAddressFieldName = addressFieldData.singleLineAddressField.name;
- }
- else
- {
- showError(hostBaseWidget.getDefaultString("singleLineGeocodingNotSupportedError"), SINGLE_LINE_SEARCH);
- }
-
- locatorConfigured = true;
- invalidateProperties();
- }
-
- override protected function commitProperties():void
- {
- super.commitProperties();
-
- if (isGeocodeEnabled && locatorConfigured
- || (isFindEnabled && searchLayersConfigured))
- {
- configureSearchInput();
- }
- }
-
- private function locatorService_faultHandler(fault:Fault, token:Object = null):void
- {
- const errorMessage:String = hostBaseWidget.getDefaultString("locatorServiceConnectionError",
- locator.url,
- ErrorMessageUtil.getKnownErrorCauseMessage(fault),
- ErrorMessageUtil.makeHTMLSafe(fault.toString()));
- showError(errorMessage, SINGLE_LINE_SEARCH);
- locatorConfigured = true;
- invalidateProperties();
- }
-
- private function showError(message:String, title:String = null):void
- {
- _hostBaseWidget.showError(message, title);
- }
-
- private function configureSearchLayers():void
- {
- if (configXML.searchlayers.length() > 0)
- {
- var searchLayer:SearchLayer;
- for each (var layerInfo:XML in configXML.searchlayers.searchlayer)
- {
- searchLayer = new SearchLayer();
- searchLayer.layerIds = layerInfo.layerids.toString().split(",");
- searchLayer.layerURL = layerInfo.url.toString();
- searchLayer.searchFields = layerInfo.searchfields.toString().split(",");
-
- searchLayers.push(searchLayer);
- }
- }
-
- searchLayersConfigured = true;
- invalidateProperties();
- }
-
- private function configureResultSymbols():void
- {
- if (configXML.symbols[0])
- {
- const smsColor:uint = configXML.symbols.simplemarkersymbol.@color || 0xFF0000;
- const smsAlpha:Number = (configXML.symbols.simplemarkersymbol.@alpha[0] != null) ? configXML.symbols.simplemarkersymbol.@alpha : 0.8;
- const smsSize:Number = (configXML.symbols.simplemarkersymbol.@size[0] != null) ? configXML.symbols.simplemarkersymbol.@size : 15;
- const smsOutlineColor:uint = configXML.symbols.simplefillsymbol.outline.@color || 0xFF0000;
- const smsOutlineAlpha:Number = (configXML.symbols.simplefillsymbol.outline.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.outline.@alpha : 0.8;
- const smsOutlineWidth:Number = (configXML.symbols.simplefillsymbol.outline.@width[0] != null) ? configXML.symbols.simplefillsymbol.outline.@width : 2;
-
- resultSimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, smsSize, smsColor, smsAlpha, 0, 0, 0,
- new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
- smsOutlineColor,
- smsOutlineAlpha,
- smsOutlineWidth));
-
- const slsColor:uint = configXML.symbols.simplelinesymbol.@color || 0xFF0000;
- const slsAlpha:Number = (configXML.symbols.simplelinesymbol.@alpha[0] != null) ? configXML.symbols.simplelinesymbol.@alpha : 0.8;
- const slsWidth:Number = (configXML.symbols.simplelinesymbol.@width[0] != null) ? configXML.symbols.simplelinesymbol.@width : 2;
-
- resultSimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, slsColor, slsAlpha, slsWidth);
-
- const sfsColor:uint = configXML.symbols.simplefillsymbol.@color || 0xFF0000;
- const sfsAlpha:Number = (configXML.symbols.simplefillsymbol.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.@alpha : 0.5;
- const sfsOutlineColor:uint = configXML.symbols.simplefillsymbol.outline.@color || 0xFF0000;
- const sfsOutlineAlpha:Number = (configXML.symbols.simplefillsymbol.outline.@alpha[0] != null) ? configXML.symbols.simplefillsymbol.outline.@alpha : 0.8;
- const sfsOutlineWidth:Number = (configXML.symbols.simplefillsymbol.outline.@width[0] != null) ? configXML.symbols.simplefillsymbol.outline.@width : 2;
-
- resultSimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, sfsColor, sfsAlpha,
- new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
- sfsOutlineColor,
- sfsOutlineAlpha,
- sfsOutlineWidth));
- }
- }
-
- private function configureResultGraphic():void
- {
- searchResultGraphic = new com.esri.ags.Graphic()
- const clearFeatureLabel:String = configXML.labels.clearfeaturelabel[0] || hostBaseWidget.getDefaultString("clearLabel");
- const customContextMenu:ContextMenu = new ContextMenu();
- customContextMenu.hideBuiltInItems();
- const menuItem:ContextMenuItem = new ContextMenuItem(clearFeatureLabel);
- menuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItem_contextMenuDeleteHandler);
- customContextMenu.customItems.push(menuItem);
- searchResultGraphic.contextMenu = customContextMenu;
- }
-
- private function menuItem_contextMenuDeleteHandler(event:ContextMenuEvent):void
- {
- if (map.infoWindow.contentOwner == searchResultGraphic)
- {
- map.infoWindow.hide();
- }
- map.defaultGraphicsLayer.remove(searchResultGraphic);
- }
-
- private function importSearchResultHistory():void
- {
- try
- {
- searchResultHistory.importHistory
- (searchResultHistoryStorage.data.searchResultHistory as Array);
- }
- catch (err:Error)
- {
- //ignore
- }
- }
-
- private function configureSearchInput():void
- {
- const urlSearchTerm:String = getURLSearchTerm();
- if (urlSearchTerm)
- {
- searchTerm = urlSearchTerm;
- search();
- }
- }
-
- private function getURLSearchTerm():String
- {
- return ViewerContainer.urlConfigParams.search;
- }
-
- private function search():void
- {
- if (!searchTerm || (!isGeocodeEnabled && !isFindEnabled))
- {
- return;
- }
-
- currentState = "searching";
-
- const hasCurrentSearchInProgress:Boolean = totalResultsToProcess > 0;
- if (hasCurrentSearchInProgress)
- {
- cursorManager.removeBusyCursor();
- }
-
- cursorManager.setBusyCursor();
- map.infoWindow.hide();
- totalResultsToProcess = 0;
- searchResults.removeAll();
-
- lastSearchTimestamp = getTimer();
-
- if (isGeocodeEnabled)
- {
- totalResultsToProcess++;
-
- const addressData:Object = {};
- addressData[singleAddressFieldName] = searchTerm;
- var locatorParams:AddressToLocationsParameters = new AddressToLocationsParameters();
- locatorParams.address = addressData;
- locatorParams.outFields = [ "Ymax", "Ymin", "Xmax", "Xmin" ];
- locatorParams.location = map.extent.center;
- locatorParams.distance = calculateExtentRadius();
-
- locator.addressToLocations(locatorParams, new AsyncResponder(locator_resultHandler, locator_faultHandler, lastSearchTimestamp));
- }
-
- if (isFindEnabled)
- {
- totalResultsToProcess += searchLayers.length;
-
- var searchLayer:SearchLayer;
- for (var i1:Number = 0; i1 < searchLayers.length; i1++)
- {
- searchLayer = searchLayers[i1];
- findTask.url = searchLayer.layerURL;
- var findParams:FindParameters = new FindParameters();
- findParams.contains = true;
- findParams.layerIds = searchLayer.layerIds;
- findParams.searchFields = searchLayer.searchFields;
- findParams.searchText = searchTerm;
- findParams.outSpatialReference = map.spatialReference;
- findParams.returnGeometry = true;
-
- findTask.execute(findParams, new AsyncResponder(findTask_resultHandler, findTask_faultHandler, lastSearchTimestamp));
- }
- }
- }
-
- private function calculateExtentRadius():Number
- {
- var radius:Number;
-
- if (map.spatialReference.wkid == 4326
- || map.spatialReference.isWebMercator())
- {
- const currentExtent:Extent = map.extent;
- var diagonal:Polyline = new Polyline([[ new MapPoint(currentExtent.xmin, currentExtent.ymin),
- new MapPoint(currentExtent.xmax, currentExtent.ymax)]]);
-
- if (map.spatialReference.isWebMercator())
- {
- diagonal = WebMercatorUtil.webMercatorToGeographic(diagonal) as Polyline;
- }
-
- const diagonalLength:Number = GeometryUtil.geodesicLengths([ diagonal ], Units.METERS)[0];
-
- radius = Math.round(diagonalLength * 0.5);
- }
-
- return radius;
- }
-
- private function locator_resultHandler(results:Array, searchTimestamp:int):void
- {
- if (searchTimestamp != lastSearchTimestamp)
- {
- return;
- }
-
- for each (var addressCandidate:AddressCandidate in results)
- {
- if (addressCandidate.score >= minscore)
- {
- searchResults.addItem(addressCandidate);
- }
- }
-
- decreaseProcessedResultCount();
- }
-
- private function decreaseProcessedResultCount():void
- {
- totalResultsToProcess--;
-
- if (totalResultsToProcess == 0)
- {
- showSearchResults();
- }
- }
-
- private function showSearchResults():void
- {
- cursorManager.removeBusyCursor();
-
- if (searchResults.length > 1)
- {
- currentState = "showingSearchResults";
- resultList.selectedIndex = -1;
- }
- else if (searchResults.length == 1)
- {
- storeSearchResult(searchResults.getItemAt(0));
- var searchResult:Object = getSearchResult(searchResults.getItemAt(0));
- searchTerm = searchResult.label;
- projectToMapSpatialReferenceAndShowResultOnMap(searchResult);
- }
- else
- {
- currentState = "noResults";
- }
- }
-
- private function storeSearchResult(searchResult:Object):void
- {
- searchResultHistory.addItem(searchResult);
- exportSearchResultHistory();
- }
-
- private function exportSearchResultHistory():void
- {
- try
- {
- searchResultHistoryStorage.data.searchResultHistory =
- searchResultHistory.exportHistory();
- searchResultHistoryStorage.flush();
- }
- catch (err:Error)
- {
- //ignore
- }
- }
-
- private function getSearchResult(searchResult:Object):Object
- {
- var result:Object;
-
- if (searchResult is FindResult)
- {
- result = {};
- const findResult:FindResult = searchResult as FindResult;
- result.label = findResult.value;
- result.geometry = findResult.feature.geometry;
- result.extent = null;
- }
- else if (searchResult is AddressCandidate)
- {
- result = {};
- const addressCandidate:AddressCandidate = searchResult as AddressCandidate;
- result.label = addressCandidate.address;
- result.geometry = addressCandidate.location;
- result.extent = getGeographicResultExtent(addressCandidate);
- }
-
- return result;
- }
-
- private function getGeographicResultExtent(addressCandidate:AddressCandidate):Extent
- {
- const canCreateResultExtent:Boolean = addressCandidate
- && addressCandidate.attributes
- && Boolean(addressCandidate.attributes.Xmin) && Boolean(addressCandidate.attributes.Ymin)
- && Boolean(addressCandidate.attributes.Xmax) && Boolean(addressCandidate.attributes.Ymax)
- && !isNaN(addressCandidate.attributes.Xmin) && !isNaN(addressCandidate.attributes.Ymin)
- && !isNaN(addressCandidate.attributes.Xmax) && !isNaN(addressCandidate.attributes.Ymax);
-
- return canCreateResultExtent ? new Extent(addressCandidate.attributes.Xmin,
- addressCandidate.attributes.Ymin,
- addressCandidate.attributes.Xmax,
- addressCandidate.attributes.Ymax,
- new SpatialReference(4326)) : null;
- }
-
- private function projectToMapSpatialReferenceAndShowResultOnMap(searchResult:Object):void
- {
- var needToProjectGeometryServerSide:Boolean;
-
- if (map.spatialReference.isWebMercator()
- && searchResult.geometry.spatialReference
- && searchResult.geometry.spatialReference.wkid == 4326)
- {
- searchResult.geometry = WebMercatorUtil.geographicToWebMercator(searchResult.geometry);
- }
- else if (map.spatialReference.wkid == 4326
- && searchResult.geometry.spatialReference
- && searchResult.geometry.spatialReference.isWebMercator())
- {
- searchResult.geometry = WebMercatorUtil.webMercatorToGeographic(searchResult.geometry);
- }
- else if (!map.spatialReference.equals(searchResult.geometry.spatialReference))
- {
- needToProjectGeometryServerSide = true;
- }
-
- var needToProjectExtentServerSide:Boolean;
-
- if (searchResult.extent)
- {
- if (map.spatialReference.isWebMercator()
- && searchResult.extent.spatialReference.wkid == 4326)
- {
- searchResult.extent = WebMercatorUtil.geographicToWebMercator(searchResult.extent);
- }
- else if (map.spatialReference.wkid == 4326
- && searchResult.extent.spatialReference
- && searchResult.extent.spatialReference.isWebMercator())
- {
- //do nothing since we're assuming the search result extent's SR is in Geographic
- }
- else if (!map.spatialReference.equals(searchResult.extent.spatialReference))
- {
- needToProjectExtentServerSide = true;
- }
- }
-
- var previousShowBusyCursorValue:Boolean = GeometryServiceSingleton.instance.showBusyCursor;
-
- if (needToProjectGeometryServerSide)
- {
- projectGeometryServerSide();
- }
- else if (needToProjectExtentServerSide)
- {
- projectExtentServerSide();
- }
- else
- {
- handleProjectionComplete();
- }
-
- function projectGeometryServerSide():void
- {
- var projectionParams:ProjectParameters = new ProjectParameters();
- projectionParams.geometries = [ searchResult.geometry ];
- projectionParams.outSpatialReference = map.spatialReference;
-
- GeometryServiceSingleton.instance.showBusyCursor = true;
- GeometryServiceSingleton.instance.project(
- projectionParams, new AsyncResponder(projectGeometryResultHandler,
- projectFaultHandler));
- }
-
- function projectGeometryResultHandler(geometry:Array, token:Object = null):void
- {
- searchResult.geometry = geometry[0];
-
- if (needToProjectExtentServerSide)
- {
- projectExtentServerSide();
- }
- else
- {
- handleProjectionComplete();
- }
- }
-
- function projectExtentServerSide():void
- {
- var projectionParams:ProjectParameters = new ProjectParameters();
- projectionParams.geometries = [ searchResult.extent ];
- projectionParams.outSpatialReference = map.spatialReference;
-
- GeometryServiceSingleton.instance.showBusyCursor = true;
- GeometryServiceSingleton.instance.project(
- projectionParams, new AsyncResponder(projectExtentResultHandler,
- projectFaultHandler));
- }
-
- function projectExtentResultHandler(extent:Array, token:Object = null):void
- {
- searchResult.extent = extent[0];
- handleProjectionComplete();
- }
-
- function handleProjectionComplete():void
- {
- GeometryServiceSingleton.instance.showBusyCursor = previousShowBusyCursorValue;
-
- var resultHasValidGeometry:Boolean = hasValidGeometry(searchResult.geometry);
- var resultHasExtentAndIsValid:Boolean = searchResult.extent && hasValidGeometry(searchResult.extent);
-
- if (resultHasExtentAndIsValid && resultHasValidGeometry
- || resultHasValidGeometry)
- {
- showSearchResultOnMap(searchResult);
- }
- else
- {
- showError(hostBaseWidget.getDefaultString("cannotDisplayResult"), SINGLE_LINE_SEARCH);
- }
- }
-
- function projectFaultHandler(fault:Fault, token:Object = null):void
- {
- showError(hostBaseWidget.getDefaultString("projectionError",
- ErrorMessageUtil.makeHTMLSafe(fault.toString())), SINGLE_LINE_SEARCH);
- }
- }
-
- private function hasValidGeometry(geometry:Geometry):Boolean
- {
- var isValid:Boolean;
-
- if (geometry)
- {
- if (geometry.type == Geometry.MAPPOINT)
- {
- isValid = isValidMapPoint(geometry as MapPoint);
- }
- else if (geometry.type == Geometry.MULTIPOINT)
- {
- isValid = isValidMultiPoint(geometry as Multipoint);
- }
- else if (geometry.type == Geometry.EXTENT)
- {
- isValid = isValidPolygon((geometry as Extent).toPolygon());
- }
- else if (geometry.type == Geometry.POLYGON)
- {
- isValid = isValidPolygon(geometry as Polygon);
- }
- else if (geometry.type == Geometry.POLYLINE)
- {
- isValid = isValidPolyline(geometry as Polyline);
- }
- }
-
- return isValid;
- }
-
- private function isValidMapPoint(point:MapPoint):Boolean
- {
- return point && !isNaN(point.x) && !isNaN(point.y);
- }
-
- private function isValidMultiPoint(multiPoint:Multipoint):Boolean
- {
- return hasValidMapPoints(multiPoint.points);
- }
-
- private function hasValidMapPoints(points:Array):Boolean
- {
- var isValid:Boolean;
-
- if (points && points.length > 0)
- {
- isValid = true;
-
- for each (var point:MapPoint in points)
- {
- if (!isValidMapPoint(point))
- {
- isValid = false;
- break;
- }
- }
- }
-
- return isValid;
- }
-
- private function isValidPolyline(polyline:Polyline):Boolean
- {
- var isValid:Boolean;
-
- if (polyline && polyline.paths && polyline.paths.length > 0)
- {
- isValid = true;
-
- for each (var path:Array in polyline.paths)
- {
- if (!hasValidMapPoints(path))
- {
- isValid = false;
- break;
- }
- }
- }
-
- return isValid;
- }
-
- private function isValidPolygon(polygon:Polygon):Boolean
- {
- var isValid:Boolean;
-
- if (polygon && polygon.rings && polygon.rings.length > 0)
- {
- isValid = true;
-
- for each (var ring:Array in polygon.rings)
- {
- if (!hasValidMapPoints(ring))
- {
- isValid = false;
- break;
- }
- }
- }
-
- return isValid;
- }
-
- private function locator_faultHandler(info:Object, searchTimestamp:int):void
- {
- if (searchTimestamp != lastSearchTimestamp)
- {
- return;
- }
-
- showError(info.toString(), SINGLE_LINE_SEARCH);
- decreaseProcessedResultCount();
- }
-
- private function findTask_resultHandler(results:Array, searchTimestamp:int):void
- {
- if (searchTimestamp != lastSearchTimestamp)
- {
- return;
- }
-
- for each (var findResult:FindResult in results)
- {
- searchResults.addItem(findResult);
- }
-
- decreaseProcessedResultCount();
- }
-
- private function findTask_faultHandler(error:Fault, searchTimestamp:int):void
- {
- if (searchTimestamp != lastSearchTimestamp)
- {
- return;
- }
-
- decreaseProcessedResultCount();
- }
-
- private function processSelectedSearchResult():void
- {
- if (resultList.selectedItem)
- {
- storeSearchResult(resultList.selectedItem);
- var searchResult:Object = getSearchResult(resultList.selectedItem);
- searchTerm = searchResult.label;
- projectToMapSpatialReferenceAndShowResultOnMap(searchResult);
- resetSearchResultSelection();
- }
- }
-
- private function resetSearchResultSelection():void
- {
- resultList.dataProvider.removeAll();
- currentState = "normal";
- }
-
- //assumes search result SR compatible with map's
- private function showSearchResultOnMap(searchResult:Object):void
- {
- if (!searchResult)
- {
- return;
- }
-
- searchResultGraphic.geometry = searchResult.geometry;
- searchResultGraphic.symbol = getSymbolForGeometryType(searchResultGraphic.geometry.type);
- var resultExtent:Extent = searchResult.extent;
-
- const popUpInfo:PopUpInfo = new PopUpInfo();
- popUpInfo.description = searchResult.label;
- popUpInfo.title = searchResultTitleLabel;
- popUpInfo.showZoomToButton = false; //hide the zoom to button as map would be zoomed-in
-
- const infoWindowRenderer:ClassFactory = new ClassFactory(PopUpRenderer);
- infoWindowRenderer.properties = { popUpInfo: popUpInfo };
- searchResultGraphic.infoWindowRenderer = infoWindowRenderer;
-
- popUpRenderer.popUpInfo = popUpInfo;
- popUpRenderer.graphic = searchResultGraphic;
-
- map.defaultGraphicsLayer.remove(searchResultGraphic);
- if (searchResultGraphic.symbol)
- {
- map.defaultGraphicsLayer.add(searchResultGraphic);
- }
-
- const resultPoint:MapPoint = getGeometryCenter(searchResultGraphic.geometry);
-
- if (resultExtent)
- {
- map.zoomTo(resultExtent);
- }
- else
- {
- if (searchResultGraphic.geometry.type == Geometry.MAPPOINT)
- {
- if (map.scale > zoomScale)
- {
- map.scale = zoomScale;
- }
- }
-
- map.zoomTo(searchResultGraphic.geometry);
- }
-
- infoWindowShow(resultPoint);
- }
-
- private function getSymbolForGeometryType(geometryType:String):Symbol
- {
- var symbol:Symbol;
-
- switch (geometryType)
- {
- case Geometry.POLYLINE:
- {
- symbol = resultSimpleLineSymbol;
- break;
- }
- case Geometry.POLYGON:
- {
- symbol = resultSimpleFillSymbol;
- break;
- }
- case Geometry.MAPPOINT:
- default:
- {
- symbol = resultSimpleMarkerSymbol;
- }
- }
-
- return symbol;
- }
-
- private function getGeometryCenter(geometry:Geometry):MapPoint
- {
- var center:MapPoint;
-
- if (geometry is MapPoint)
- {
- center = geometry as MapPoint;
- }
- else if (geometry)
- {
- center = geometry.extent.center;
- }
-
- return center;
- }
-
- private function infoWindowShow(point:MapPoint):void
- {
- map.infoWindow.content = popUpRenderer;
- map.infoWindow.contentOwner = popUpRenderer.graphic;
- map.infoWindow.show(point);
- }
-
- protected function searchInput_focusInHandler(event:FocusEvent):void
- {
- if (currentState == "normal")
- {
- if (searchResults.length > 1)
- {
- currentState = "showingSearchResults";
- resultList.selectedIndex = -1;
- }
- else
- {
- processSearchResult();
- }
- }
- }
-
- protected function this_focusOutHandler(event:FocusEvent):void
- {
- if (event.relatedObject == resultList
- || event.relatedObject == searchInput)
- {
- return;
- }
-
- if (currentState != "searching")
- {
- currentState = "normal";
- }
- }
-
- protected function searchInput_changeHandler(event:TextOperationEvent):void
- {
- processSearchResult();
- }
-
- private function processSearchResult():void
- {
- if (searchResults.length > 0)
- {
- searchResults.removeAll();
- }
-
- const searchResultMatches:Array = searchInHistory(searchTerm);
- searchResultHistoryList.source = searchResultMatches;
- if (searchResultMatches.length > 0)
- {
- currentState = "showingPreviousSearchResults";
- resultList.selectedIndex = -1;
- }
- else
- {
- currentState = "normal";
- }
- }
-
- private function searchInHistory(input:String):Array
- {
- const matches:Array = [];
-
- if (input)
- {
- input = input.toLowerCase();
-
- const searchResultItems:Array = searchResultHistory.items;
- var searchResult:Object;
- for (var i:int = searchResultItems.length - 1; i >= 0; i--)
- {
- searchResult = searchResultItems[i];
-
- if (searchResult is FindResult && !isFindEnabled
- || searchResult is AddressCandidate && !isGeocodeEnabled)
- {
- continue;
- }
-
- if (SearchResultUtil.searchResultToLabel(searchResult).toLowerCase().indexOf(input) != -1)
- {
- matches.unshift(searchResult);
- if (matches.length >= 10)
- {
- break;
- }
- }
- }
- }
-
- return matches;
- }
-
- protected function searchInput_keyDownHandler(event:KeyboardEvent):void
- {
- if (event.keyCode == Keyboard.ESCAPE)
- {
- currentState = "normal";
- }
-
- if (event.keyCode == Keyboard.DOWN)
- {
- processDownKey();
- }
-
- if (event.keyCode == Keyboard.UP)
- {
- processUpKey();
- }
- }
-
- private function processUpKey():void
- {
- if (currentState == "showingPreviousSearchResults"
- || currentState == "showingSearchResults")
- {
- resultList.selectedIndex--;
- resultList.ensureIndexIsVisible(resultList.selectedIndex);
- }
- }
-
- private function processDownKey():void
- {
- if (currentState == "showingPreviousSearchResults"
- || currentState == "showingSearchResults")
- {
- resultList.selectedIndex++;
- resultList.ensureIndexIsVisible(resultList.selectedIndex);
- }
- }
-
- protected function resultList_changeHandler(event:IndexChangeEvent):void
- {
- if (resultList.selectedIndex > -1)
- {
- processSelectedSearchResult();
- }
- }
-
- protected function searchInput_enterHandler(event:FlexEvent):void
- {
- if (resultList.selectedIndex > -1)
- {
- processSelectedSearchResult();
- }
- else
- {
- search();
- }
- }
- ]]>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/widgets/HeaderController/HeaderControllerWidget.mxml b/src/widgets/HeaderController/HeaderControllerWidget.mxml
index 2a88653..572f610 100644
--- a/src/widgets/HeaderController/HeaderControllerWidget.mxml
+++ b/src/widgets/HeaderController/HeaderControllerWidget.mxml
@@ -22,7 +22,6 @@
xmlns:viewer="com.esri.viewer.*"
xmlns:components="com.esri.viewer.components.*"
xmlns:HeaderController="widgets.HeaderController.*"
- xmlns:singleLineSearch="com.esri.viewer.components.singleLineSearch.*"
width="100%"
borderSkin="{null}"
creationComplete="creationCompleteHandler(event)"
@@ -477,10 +476,10 @@
-
+