Select to view content in your preferred language

Modify API Samples to Run in Flexviewer as Widget

2239
3
07-12-2012 05:10 AM
MattSiple
Deactivated User
Hi,

I am having a hard time understanding how to modify the example programs in the ACRGIS API Flex IdentifySample to work with Flexviewer as a widget. After 4 days of trying to figure this out, I need to finally admit defeat and ask for a little help.

I understand how to modify the "Application" to be a "BaseWidget" and "WidgetTemplate" and all of that. Using the "IdentifySample.xml" I modified the <Application> tag to <viewer:BaseWidget> tag and added the imports etc... I have run the debugger and found that all of the code executes. However, nothing happens when the code complete. So that tells me some variable not being set or is a different copy/instance of the variable. I suspect it is somewhere in one of the graphics variables but I am not sure.

Here is where I think the trouble comes in.

[INDENT]...
</fx: Declarations>
<esri:Map id="myMap" mapClick="mapClickHandler(event)">
<esri:extent>
<esri:WebMercatorExtent minlon="-120" minlat="30" maxlon="-100" maxlat="50"/>
</esri:extent>
<esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/>
<esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
<esri:GraphicsLayer id="clickGraphicsLayer"/>
</esri:Map>
</s:Application>

[/INDENT]
Here is my thinking:

1. The "<esri:Map id='myMap'..." is not needed since it already set to "map". So in the script portion where ever their is referenceto "myMap" I chance it to "map"

2. The "<esri:ArcGISTiledMapServiceLayer url="http:..." is just setting up the base map and since this done already I omit it.

3. The script makes use of the "{lastIdentifyResultGraphic}" and since I think that all this does is declarethe graphics provider I leave that line in there.

4. The next line " <esri:GraphicsLayer id="clickGraphicsLayer"/>" I am not sure what it is doing except declaring a variable named "clickGraphicsLayer" so I leave that in there as well.

So I have:
[INDENT]...
</fx: Declarations>
<esri:GraphicsLayer graphicProvider="{lastIdentifyResultGraphic}"/>
<esri:GraphicsLayer id="clickGraphicsLayer"/>
</viewer:BaseWidget>

[/INDENT]
I have attached the modified code so you can see the whole thing. The original code can be found at:
http://resources.arcgis.com/en/help/flex-api/samples/index.html#/Identify_features/01nq0000000z00000...

Thank in advance,
-matt
Tags (2)
0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus
Matt,

   With your limited understanding of ActionScript and MXML and what all the line in the sample are actually doing, why are you not just using the IdentifyWidget that has all of this done for you and much more?.. In Widgets almost everything except GUI elements are done in ActionScript and not MXML as in the samples. Graphics layers are added in the widgets widgetConfigLoaded event. As it stands the graphics layer that you have in the mxml code are not part of or added to the map in any way so they are useless. The Flex API sample are not meant to be ported over to widget but it can be done with the proper knowledge of what the code is doing and what needs to be changed to fit a widgets code structure.


Identify Widget:
http://www.arcgis.com/home/item.html?id=39cf66d58c234279ba728c50461a1a89

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:
0 Kudos
MattSiple
Deactivated User
Robert,
Thanks for taking the time to answer my question. Based on what you said about widgetConfigLoaded and mxml code, I was able to figure out the problem. Although the selected graphic was being added to the graphics layer, the graphics layer wasn't being added to the map. I added the "map.addLayer(clickGraphicsLayer);" and got rid of all of the MXML Elements and now it works.

There are several answers to your question:
Q. "Why are you not just using the IdentifyWidget".
[INDENT]A. It doesn't do everything I really need.
A. Because I am trying to build my knowledge of the product so that eventually I do know what I am doing.
A. Because I am an Engineer and that is what we do. 🙂 First we understand how something works, break it, put it back together again, modify it, get it to work again, (repeat about 100 times) and then maybe improve it.
[/INDENT]

Thanks again,
-matt



Matt,

   With your limited understanding of ActionScript and MXML and what all the line in the sample are actually doing, why are you not just using the IdentifyWidget that has all of this done for you and much more?.. In Widgets almost everything except GUI elements are done in ActionScript and not MXML as in the samples. Graphics layers are added in the widgets widgetConfigLoaded event. As it stands the graphics layer that you have in the mxml code are not part of or added to the map in any way so they are useless. The Flex API sample are not meant to be ported over to widget but it can be done with the proper knowledge of what the code is doing and what needs to be changed to fit a widgets code structure.


Identify Widget:
http://www.arcgis.com/home/item.html?id=39cf66d58c234279ba728c50461a1a89

Don't forget to click the Mark as answer check on this post and to click the top arrow (promote).
Follow the steps as shown in the below graphic:
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Matt,

   OK, sounds good. One word of advice is to tear apart existing esri and custom widgets like mine and use then as a baseline for building widgets. You will have no problem getting in to building widget using your engineer mentality of tear it apart and try to understand how it work.

Don't forget the most important part to click the Mark as answer check on this post.
Follow the steps as shown in the below graphic:
0 Kudos