preload = "true"
function timerComplete( event:TimerEvent ):void { timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete); var id:Number = SiteContainer.getInstance().getWidgetId("Búsqueda DM"); var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; if (bWidget){ var bWidg:BaseWidget = bWidget.getInstance(); var vSW:BuscarDerechoMinero = bWidg as BuscarDerechoMinero; vSW.buscarDerecho(id_Derecho); } else { var bWidget2:IBaseWidget; bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; var vSW2:BuscarDerechoMinero = bWidget2 as BuscarDerechoMinero; vSW2.buscarDerecho(id_Derecho); } }
<widget label="Búsqueda DM" icon="com/esri/solutions/flexviewer/assets/images/icons/i_derecho.png" menu="menuWidgets" config="com/esri/solutions/flexviewer/xml/BuscarDerechoMinero.xml">com/esri/solutions/flexviewer/widgets/BuscarDerechoMinero.swf</widget>
var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; ... bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget;
public function getWidget(id:Number):IBaseWidget { var widget:IBaseWidget; var label:String = configData.configWidgets[id].label; var icon:String = configData.configWidgets[id].icon; var config:String = configData.configWidgets[id].config; var url:String = configData.configWidgets[id].url; var preload:String = configData.configWidgets[id].preload; if (widgetTable.containsKey(id)) { widget = widgetTable.find(id) as IBaseWidget; widget.setState("maximized"); var wObj:DisplayObject = widget as DisplayObject; scrollToWidget(wObj); } else { //module loaded if (moduleTable.containsKey(url)) { var modInfo:IModuleInfo = moduleTable.find(url) as IModuleInfo; widget = modInfo.factory.create() as IBaseWidget; widget.setId(id); widget.setTitle(label); widget.setIcon(icon); widget.setConfig(config); widget.setConfigData(configData); widget.setMap(map); var widgetDO:DisplayObject = widget as DisplayObject; widgetBox.addChild(widgetDO); widgetTable.add(id, widget); } else { return null; loadWidget(id, url,preload); } } return widget; }
var id:Number = SiteContainer.getInstance().getWidgetId("My Widget Label");
function timerComplete( event:TimerEvent ):void { timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete); var id:Number = SiteContainer.getInstance().getWidgetId("My Widget Label"); var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; if (bWidget){ var bWidg:BaseWidget = bWidget.getInstance(); var vSW:myWidget= bWidg as myWidget; vSW.myQueryFunction(id); } else { var bWidget2:IBaseWidget; bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; var vSW2:BuscarDerechoMinero = bWidget2 as BuscarDerechoMinero; vSW2.buscarDerecho(id_Derecho); } }
Thank U so much Robert, I compiled and I built all my project....but nothing happen... 😞I know it's really hard to understand why it doesnt work...but if u have time please help me ... in attachment I send u my MapManager, SiteContainer and SearchWidget.Many thanks.Naty
Naty, I am not sure what you have the function in your SearchWidget called...Try adding this function to your SearchWidget.mxml if you don't have it.//Add to your SearchWiget.mxml //query parameter public function querybmpid(sParam:String):void { var i:Number = cboLayerText.selectedIndex; queryLayer = configSearchText.url; if(queryExpr){ }else{ queryExpr = configSearchText.expr; } queryFields = configSearchText.fields; queryTitleField = configSearchText.titlefield; queryLinkField = configSearchText.linkfield; if (queryLayer) { var queryTask:QueryTask = new QueryTask(queryLayer); var query:Query = new Query(); var pExpr:String = sParam.toUpperCase(); var expr:String = queryExpr.replace("[value]", pExpr); query.where = expr; query.outFields = queryFields.split(","); query.returnGeometry = true; query.outSpatialReference = map.spatialReference; queryTask.execute(query, new AsyncResponder(onResult, onFault)); showMessage(loadingLabel, true); showStateResults(null); // on result function onResult(featureSet:FeatureSet, token:Object = null):void { try { var recAC:ArrayCollection = createRecordData(featureSet); addSharedData(widgetTitle, recAC); wRepeater.dataProvider = recAC; showMessage(selectionLabel + " " + featureSet.features.length, false); onLoadDone(null); map.cursorManager.removeAllCursors(); } catch (error:Error) { showMessage(error.message, false); onLoadDone(null); } } //on fault function onFault(info:Object, token:Object = null) : void { onLoadDone(null); showMessage(info.toString(), false); } } }If you call it querybmpid like above it should match the MapManger.mxml of Sandra's that I told you to switch to.This is definitely not an easy piece of code to implement as there are many vital steps to the code that need to be in place and it helps if you try to understand the path that the code is taking.Basically the application loads and check is there is a URL Parameter for the search and if there is once the map is loaded then programatically launch the SearchWidget and pass that parameter to it and run the query. So the MapManager needs to check for the paramter, find the search widget and launch it and then when you have the reference to the searchwidget call the (what ever function i.e. queryPPIN) and execute the search. So the MapManager has to call a valid function in the SearchWidget.
//Add to your SearchWiget.mxml //query parameter public function querybmpid(sParam:String):void { var i:Number = cboLayerText.selectedIndex; queryLayer = configSearchText.url; if(queryExpr){ }else{ queryExpr = configSearchText.expr; } queryFields = configSearchText.fields; queryTitleField = configSearchText.titlefield; queryLinkField = configSearchText.linkfield; if (queryLayer) { var queryTask:QueryTask = new QueryTask(queryLayer); var query:Query = new Query(); var pExpr:String = sParam.toUpperCase(); var expr:String = queryExpr.replace("[value]", pExpr); query.where = expr; query.outFields = queryFields.split(","); query.returnGeometry = true; query.outSpatialReference = map.spatialReference; queryTask.execute(query, new AsyncResponder(onResult, onFault)); showMessage(loadingLabel, true); showStateResults(null); // on result function onResult(featureSet:FeatureSet, token:Object = null):void { try { var recAC:ArrayCollection = createRecordData(featureSet); addSharedData(widgetTitle, recAC); wRepeater.dataProvider = recAC; showMessage(selectionLabel + " " + featureSet.features.length, false); onLoadDone(null); map.cursorManager.removeAllCursors(); } catch (error:Error) { showMessage(error.message, false); onLoadDone(null); } } //on fault function onFault(info:Object, token:Object = null) : void { onLoadDone(null); showMessage(info.toString(), false); } } }
Naty, So you are missing more code that was discussed in the original tread then.//In BaseWidget.as add private static var _Widget:BaseWidget; //Then in the initWidgetTemplate function add _Widget = this;The QueryPID error means that you need to look in your SearchWidget for a public function called QueryPID. In the original thread I called it "public function queryPPIN(sParam:String):void".The CustomDraw error means that your MapManager code is now looking for my EnhancedDraw widget instead of the standard draw tool of ESRI's. That code was not in Sandra's MapManger code so If you are not using my custom draw widget than I would say look back up at the beginning of this thread and grab Sandra's MapManager code she posted.
//In BaseWidget.as add private static var _Widget:BaseWidget; //Then in the initWidgetTemplate function add _Widget = this;
Thank u Robert, I will try with it...Naty
Natasha, Yep you missed a couple of steps from the older thread. //Add to the BaseWidget.as /** * Added by me * so that I could get the widget instance */ public function getInstance():BaseWidget { return _Widget; } //Add to the IBaseWidget.as /** * Used to get a refference to this widget for code */ function getInstance():BaseWidget; //Add to the WidgetManagerDocked.mxml public function getWidget(id:Number):IBaseWidget { var widget:IBaseWidget; var label:String = configData.configWidgets[id].label; var icon:String = configData.configWidgets[id].icon; var config:String = configData.configWidgets[id].config; var url:String = configData.configWidgets[id].url; if (widgetTable.containsKey(id)) { widget = widgetTable.find(id) as IBaseWidget; widget.setState("maximized"); var wObj:DisplayObject = widget as DisplayObject; scrollToWidget(wObj); } else { //module loaded if (moduleTable.containsKey(url)) { var modInfo:IModuleInfo = moduleTable.find(url) as IModuleInfo; widget = modInfo.factory.create() as IBaseWidget; widget.setId(id); widget.setTitle(label); widget.setIcon(icon); widget.setConfig(config); widget.setConfigData(configData); widget.setMap(map); var widgetDO:DisplayObject = widget as DisplayObject; widgetBox.addChild(widgetDO); widgetTable.add(id, widget); } else { return null; loadWidget(id, url); } } return widget; }
//Add to the BaseWidget.as /** * Added by me * so that I could get the widget instance */ public function getInstance():BaseWidget { return _Widget; } //Add to the IBaseWidget.as /** * Used to get a refference to this widget for code */ function getInstance():BaseWidget; //Add to the WidgetManagerDocked.mxml public function getWidget(id:Number):IBaseWidget { var widget:IBaseWidget; var label:String = configData.configWidgets[id].label; var icon:String = configData.configWidgets[id].icon; var config:String = configData.configWidgets[id].config; var url:String = configData.configWidgets[id].url; if (widgetTable.containsKey(id)) { widget = widgetTable.find(id) as IBaseWidget; widget.setState("maximized"); var wObj:DisplayObject = widget as DisplayObject; scrollToWidget(wObj); } else { //module loaded if (moduleTable.containsKey(url)) { var modInfo:IModuleInfo = moduleTable.find(url) as IModuleInfo; widget = modInfo.factory.create() as IBaseWidget; widget.setId(id); widget.setTitle(label); widget.setIcon(icon); widget.setConfig(config); widget.setConfigData(configData); widget.setMap(map); var widgetDO:DisplayObject = widget as DisplayObject; widgetBox.addChild(widgetDO); widgetTable.add(id, widget); } else { return null; loadWidget(id, url); } } return widget; }
This is my code in mapmanager.mxml...in attachment the code and the error...
Natasha, I've attached my sitecontainer. Hope it helps, if not, hopefully Robert will respond. He's the best.
Thank You very very much! It worked.
public function querybmpid(sParam:String):void { var i:Number = cboLayerText.selectedIndex; queryLayer = "http://arcgis.sd.gov/Arcgis/rest/services/BMP2/MapServer/0"; queryExpr = "BMPID = '[value]'"; queryFields = "*"; queryTitleField = "BMPID"; queryLinkField = "";
refreshLayer("BMP Locations",30000);
//map load complete private function mapLoadComplete(event:MapEvent):void { SiteContainer.dispatchEvent(new AppEvent(AppEvent.LAYER_LOADED, false, false, null)); try { if (ExternalInterface.available) { var result:URLVariables = new URLVariables(); var urlSubstring:String = ExternalInterface.call("window.location.search.substring", 1); if (urlSubstring && urlSubstring.length > 0) { result.decode(urlSubstring); // Parse URL var xParam:String; var xExt:String; if (result["BMPID"]) xParam = result.BMPID; if (result["EXT"]) xExt = result.EXT; if (!xParam = ""){ var timer:Timer = new Timer(4000, 1); timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerComplete); timer.start(); } if (!xExt == ""){ var extArray:Array = xExt.split(","); var extent:Extent = new Extent(Number(extArray[0]), Number(extArray[1]), Number(extArray[2]), Number(extArray[3]),map.spatialReference); map.extent = extent; } function timerComplete( event:TimerEvent ):void { timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerComplete); var id:Number = SiteContainer.getInstance().getWidgetId("Search"); var bWidget:IBaseWidget = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; if (bWidget){ var bWidg:BaseWidget = bWidget.getInstance(); var vSW:SearchWidget = bWidg as SearchWidget; vSW.querybmpid(xParam); } else { var bWidget2:IBaseWidget; bWidget2 = SiteContainer.getInstance().widgetManager.getWidget(id) as IBaseWidget; var vSW2:SearchWidget = bWidget2 as SearchWidget; vSW2.querybmpid(xParam); } } } } } catch (error:Error){} refreshLayer("BMP Locations",30000); //uncomment if you are using my enhanced draw widget //map.addLayer(drawgLayer); }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.