Hello Robert,I'm sure you have covered this, so hopefully it will be easy to respond. When I combine the TOC with the Selection Widget, Once the Selection widget is activated, all the FeatureLayers used in the Selection Widget get added to the TOC, preventing FeatureLayers from being added is an option for me, but I'd figured I'll check with you to see if there is a cleaner solution.Thanks for your hard work
private function getLegendData(m_layer:*):void { if (_legendDataLoaded) return; _legendDataLoaded = true; if (m_layer.hasOwnProperty("url")){ const url:String = m_layer["url"]; if (url === null) return; }else{ return; } var httpServ:HTTPService = new HTTPService(); httpServ.requestTimeout = lTimeout; var lname:String; var lInfos:Array; if (m_layer is ArcGISTiledMapServiceLayer){ if(m_layer.version >= 10.01){ if(ArcGISTiledMapServiceLayer(m_layer).proxyURL){ //If layer uses proxy (my addition for proxy support) httpServ.url = ArcGISTiledMapServiceLayer(m_layer).proxyURL + "?" + ArcGISTiledMapServiceLayer(m_layer).url + "/legend?f=json"; }else{ //if layer doesn't use proxy (original code) httpServ.url = ArcGISTiledMapServiceLayer(m_layer).url + "/legend?f=json"; } httpServ.resultFormat = "text"; lname = ArcGISTiledMapServiceLayer(m_layer).id; lInfos = ArcGISTiledMapServiceLayer(m_layer).layerInfos; httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,Number.NaN,lInfos,httpServ.url)}); httpServ.send(); }else{ lname = ArcGISTiledMapServiceLayer(m_layer).id; ArcGISTiledMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)}); ArcGISTiledMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))}); ArcGISTiledMapServiceLayer(m_layer).getAllDetails(); } }else if (m_layer is ArcGISDynamicMapServiceLayer){ if(m_layer.version >= 10.01){ if(ArcGISDynamicMapServiceLayer(m_layer).proxyURL){ //If layer uses proxy (my addition for proxy support) httpServ.url = ArcGISDynamicMapServiceLayer(m_layer).proxyURL + "?" + ArcGISDynamicMapServiceLayer(m_layer).url + "/legend?f=json"; }else{ //if layer doesn't use proxy (original code) httpServ.url = ArcGISDynamicMapServiceLayer(m_layer).url + "/legend?f=json"; } httpServ.resultFormat = "text"; lname = ArcGISDynamicMapServiceLayer(m_layer).id; lInfos = ArcGISDynamicMapServiceLayer(m_layer).layerInfos httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,Number.NaN,lInfos,httpServ.url)}); httpServ.send(); }else{ lname = ArcGISDynamicMapServiceLayer(m_layer).id; ArcGISDynamicMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)}); ArcGISDynamicMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))}); ArcGISDynamicMapServiceLayer(m_layer).getAllDetails(); } }else if (m_layer is KMLLayer) { timeOutVar = setTimeout(getKMLLegend, 100, m_layer); }else if (m_layer is FeatureLayer){ var FeatServId:Number = Number.NaN; var msName:String = FeatureLayer(m_layer).url.replace("FeatureServer","MapServer"); if(msName.substring(msName.length - 9) != "MapServer"){ if(FeatureLayer(m_layer).proxyURL){ //If layer uses proxy (my addition for proxy support) httpServ.url = FeatureLayer(m_layer).proxyURL + "?" + msName.substring(0,msName.lastIndexOf("/")) + "/legend?f=json"; }else{ //if layer doesn't use proxy (original code) httpServ.url = msName.substring(0,msName.lastIndexOf("/")) + "/legend?f=json"; } FeatServId = parseInt(msName.substring(msName.lastIndexOf("/")+ 1)); }else{ if(FeatureLayer(m_layer).proxyURL){ //If layer uses proxy (my addition for proxy support) httpServ.url = FeatureLayer(m_layer).proxyURL + "?" + msName + "/legend?f=json"; }else{ //if layer doesn't use proxy (original code) httpServ.url = msName + "/legend?f=json"; } } if(m_layer.layerDetails.version >= 10.01){ httpServ.resultFormat = "text"; lname = FeatureLayer(m_layer).id; httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,FeatServId)}); httpServ.send(); } else { lname = FeatureLayer(m_layer).id; getFeatureResult(FeatureLayer(m_layer).layerDetails,lname); } }else{ FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$")); } }
private function getLegendData(m_layer:*):void { if (_legendDataLoaded) return; _legendDataLoaded = true; if (m_layer.hasOwnProperty("url")){ const url:String = m_layer["url"]; if (url === null) return; }else{ return; } var httpServ:HTTPService = new HTTPService(); httpServ.requestTimeout = lTimeout; var lname:String; var lInfos:Array; var tURL:String; if (m_layer is ArcGISTiledMapServiceLayer){ if(m_layer.version >= 10.01){ tURL = ArcGISTiledMapServiceLayer(m_layer).url; if(tURL.indexOf("?token=") > 0){ httpServ.url = ArcGISTiledMapServiceLayer(m_layer).url.replace("?token=", "/legend?f=json&token="); }else if(ArcGISTiledMapServiceLayer(m_layer).proxyURL){ //If layer uses proxy httpServ.url = ArcGISTiledMapServiceLayer(m_layer).proxyURL + "?" + ArcGISTiledMapServiceLayer(m_layer).url + "/legend?f=json"; }else{ httpServ.url = ArcGISTiledMapServiceLayer(m_layer).url + "/legend?f=json"; } httpServ.resultFormat = "text"; lname = ArcGISTiledMapServiceLayer(m_layer).id; lInfos = ArcGISTiledMapServiceLayer(m_layer).layerInfos; httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,Number.NaN,lInfos,httpServ.url)}); httpServ.send(); }else{ lname = ArcGISTiledMapServiceLayer(m_layer).id; ArcGISTiledMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)}); ArcGISTiledMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))}); ArcGISTiledMapServiceLayer(m_layer).getAllDetails(); } }else if (m_layer is ArcGISDynamicMapServiceLayer){ if(m_layer.version >= 10.01){ tURL = ArcGISDynamicMapServiceLayer(m_layer).url; if(tURL.indexOf("?token=") > 0){ httpServ.url = ArcGISDynamicMapServiceLayer(m_layer).url.replace("?token=", "/legend?f=json&token="); }else if(ArcGISDynamicMapServiceLayer(m_layer).proxyURL){ //If layer uses proxy httpServ.url = ArcGISDynamicMapServiceLayer(m_layer).proxyURL + "?" + ArcGISDynamicMapServiceLayer(m_layer).url + "/legend?f=json"; }else{ httpServ.url = ArcGISDynamicMapServiceLayer(m_layer).url + "/legend?f=json"; } httpServ.resultFormat = "text"; lname = ArcGISDynamicMapServiceLayer(m_layer).id; lInfos = ArcGISDynamicMapServiceLayer(m_layer).layerInfos httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,Number.NaN,lInfos,httpServ.url)}); httpServ.send(); }else{ lname = ArcGISDynamicMapServiceLayer(m_layer).id; ArcGISDynamicMapServiceLayer(m_layer).addEventListener(DetailsEvent.GET_ALL_DETAILS_COMPLETE,function(event:DetailsEvent):void{getAllDetailsResult(event,lname)}); ArcGISDynamicMapServiceLayer(m_layer).addEventListener(FaultEvent.FAULT, function(event:Event):void{FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$"))}); ArcGISDynamicMapServiceLayer(m_layer).getAllDetails(); } }else if (m_layer is KMLLayer){ timeOutVar = setTimeout(getKMLLegend, 100, m_layer); }else if (m_layer is FeatureLayer){ var FeatServId:Number = Number.NaN; var msName:String = FeatureLayer(m_layer).url.replace("FeatureServer","MapServer"); if(msName.substring(msName.length - 9) != "MapServer"){ tURL = msName.substring(0,msName.lastIndexOf("/")); if(tURL.indexOf("?token=") > 0){ httpServ.url = msName.substring(0,msName.lastIndexOf("/")).replace("?token=", "/legend?f=json&token="); }else if(FeatureLayer(m_layer).proxyURL){ //If layer uses proxy httpServ.url = FeatureLayer(m_layer).proxyURL + "?" + msName.substring(0,msName.lastIndexOf("/")) + "/legend?f=json"; }else{ httpServ.url = msName.substring(0,msName.lastIndexOf("/")) + "/legend?f=json"; } FeatServId = parseInt(msName.substring(msName.lastIndexOf("/")+ 1)); }else{ httpServ.url = msName + "/legend?f=json"; } if(m_layer.layerDetails.version >= 10.01){ httpServ.resultFormat = "text"; lname = FeatureLayer(m_layer).id; httpServ.addEventListener(ResultEvent.RESULT,function(event:ResultEvent):void{processLegend(event,lname,FeatServId)}); httpServ.send(); }else{ lname = FeatureLayer(m_layer).id; getFeatureResult(FeatureLayer(m_layer).layerDetails,lname); } }else{ FlexGlobals.topLevelApplication.dispatchEvent(new Event("legendDataLoaded$")); } }
there is any way to make the widget grow dynamically as layers are added
is there any way to remove the option to close the widget
Lixin, The directions on how to add this widget to a Flex Viewer project are included in the download from the code gallery page.
Lixin, You are on your own when you want to use the widget outside the Flex Viewer. That would require alot of decoupling from the Flex Viewer framework.
All, The new Flex Viewer 2.5 version of the TOC Widget is now available.Version 2.5 - 12 Dec, 2011* Added new Flex Viewer 2.5 Layer menu capability to TOC.* Enhanced the visual appearance of the out of the box Flex Viewer 2.5 Layer options menu and added more options.* You can choose to use esri's new description capability or the current functionality that the TOC Widget has for Metadata.
Giuseppe, Actually, esri came up with the TOC menu first, I just added more options and made it look better.WMS layer legends are not supported. I do look for the Flex team to add a true TOC like this to the API and/or viewer as all the other APIs have this functionality (Silverlight, JS).
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.