Monday, February 11, 2013

ArcGIS Flex application on Adobe AIR

I have been doing some tests on how can one port an ArcGIS Flex Web Application to a desktop AIR App. To my surprise it was quite simple, fast and, most of all, everything worked on the first run.
This is what I did. My objective was to port ArcGIS Viewer for Flex to an ArcGIS AIR Application.

First of all I downloaded ArcGIS Viewer for Flex 3.1 source code, available on GitHub, and imported it to my Flash Builder workspace


Create a new Flex Project in File -> New -> Flex Project
Type a project name like ArcGISFlexDesktop and select Desktop (run in Adobe AIR)


For the next options go with the default.

Now that the project is created, expand folder src - (default package) and open the file ArcGISFlexDesktop.mxml. Also, on the FlexViewer Project, expand folder src - (default package) and open the file index.mxml



As you can see from the above image, the desktop application entry point is the s:WindowedApplication. As for the web application it’s the s:Application. So the first action is to copy the contents inside the s:Application tag, properties included, and paste them inside the s:WindowedApplication. 


Next, copy the selected  files (see image below) from the FlexViewer project to the ArcGISFlexDesktop project. The project structure must be the same for both projects.

    


The next step is to add all the modules to the project. Go to Project - Properties and then in the ArcGISFlexDesktop Properties dialog select Flex Modules and add the following mandatory widgets.
  1. HeaderControllerWidget.mxml
  2. InfoPopupWidget.mxml
  3. WidgetContainerWidget.mxml
  4. OverviewMapWidget.mxml
  5. NavigationWidget.mxml
  6. MapSwitcherWidget.mxml
I also added BookmarksWidget.mxml and QueryWidget.mxml but you can add all.

Finally you must copy the compiler arguments from the FlexViewer project to the ArcGISFlexDesktop project. Right click on the FlexViewer project and select Properties. Then go to the Flex Compiler tab and copy the text from the Addicional compiler arguments box. Paste this text into the same box on the ArcGISFlexDesktop project.


You’r all done! Press the run button and there you have it! An ArcGIS Flex AIR application.


To my surprise, porting a web Flex app to a Desktop AIR app was so easy that some questions came up. Why did Esri launch an ArcGIS runtime for Silverlight (WPF) and for Java but not for Flex. There are not even news or plans.

The ArcGIS runtime is intended to work in online and offline modes. For the offline mode map tile packages are used, so the app needs to access the local file system. Flex RIA has the capabilities to access local file system so I have no clue on why there are no plans on making an ArcGIS Runtime based on Flex.

Download the installer of ArcGIS Flex Viewer for Desktop