Thursday, August 20, 2009 11:50 AM -
ArcGIS-Explorer-Team
Getting started with the ArcGIS Explorer SDK: your first button
If you want to customize ArcGIS Explorer there's a lot you can do without any programming. Application configurations provide an easy way to customize everything from the startup splash screen, functions which are available to users, and what tabs and controls are displayed. But invariably you may want to extend ArcGIS Explorer's capabilities, perhaps by tapping into an ArcGIS, or other, service. To do that you'll need to program with the SDK.
Here's a quick start to creating your first button control, which can be easily packaged, shared, and delivered as an add-in. (*.eaz file). Using templates provided with the SDK this is easy to do. Add-ins can also be part of an application configuration, and we'll cover more on that in future posts. But let's get started...
First, you need to download the ArcGIS Explorer SDK, a separate download from the core application. Begin by starting Visual Studio and create a new project.

Within the SDK you have both project and item templates. In this case we are going to make use of the project template for a new button add-in. From the new project window in Visual Studio browse the template options in the language of your choice (either VB.Net or C#) and look under ArcGIS Explorer for the project templates. Choose the ArcGIS Explorer button option form the list on the right, then fill in the information about what to call the project and what folder to place it in. Here we've called the new project "myFirstButton."

After specifying the project name (or taking the default) and setting the folder, click the OK button. There are various additional parameters you can set for your project and the button you’re about to create. The templates include a wizard to guide you through this process. On the first page of the wizard are all the settings for the project including a description and the name of the group to place the button in.

When you've completed your project settings (or accepted the default), click on the Next button to move on to the button settings. On the button settings page you are setting the parameters specific to the button we are going to create. Projects can have one then one Add-In within them, so you need to set parameters for each individual Add-In (button in this case). The button settings include the Caption that will be displayed in ArcGIS Explorer, the Image to use with it, and the Availability setting.
We are going to leave the Availability at the default setting of Always, but this is a key setting as it allows you to specify what conditions are necessary for your button to be active. For instance, you may write a button to perform a custom operation on a Feature Layer and therefore would only want the button to be available when a Feature Layer was selected in the Contents window.

After completing your button settings, select the Finish button and the project will be created. As well as creating the project with a new class for your button and the supporting images specified, the template will lay down the references to the required ArcGIS Explorer libraries and create an XML file containing all the parameters to be used by the application for group names, etc. (i.e., everything you specified in the project and button settings). The template will also set a debug path to the install directory for ArcGIS Explorer, so you can test your add-in right away.

Now that we have a project with our button class, all we need to do is write a little code. Double click on the AddGraphic.cs class in the Solution Explorer to open it. You’ll notice that all the API namespaces have been referenced by the button template, so we can begin coding. For a button, all we need to do is put some code in the OnClick event, so add the following:
Using C#:
MapDisplay mapDisp = Application.ActiveMapDisplay;
Graphic newGraphic = new Graphic(mapDisp.Target);
newGraphic.Symbol = Symbol.Marker.Sphere.Red;
newGraphic.Symbol.Size = 500;
mapDisp.Graphics.Add(newGraphic);
Using VB:
Dim mapDisp As MapDisplay = Application.ActiveMapDisplay
Dim newGraphic As Graphic = New Graphic(mapDisp.Target)
newGraphic.Symbol = Symbol.Marker.Sphere.Red
newGraphic.Symbol.Size = 500;
mapDisp.Graphics.Add(newGraphic)
The code will get the active map display, create a new graphic based on the target location for our view in 3D, add a symbol to that graphic (a red sphere), exaggerate the size of the symbol so we can see it at a global scale, then add the graphic to the collection for the display. There’s no need to explicitly call a refresh or anything else to repaint the display.
That's all there is to it, and we're ready to go. Just click on the Debug button in Visual Studio to start the application. As mentioned earlier, the path to the ArcGIS Explorer application (based on the install directory) is set by the project template, so it will start when you begin debugging.
When you create an add-in, by default they will appear on a new tab in ArcGIS Explorer called "Add-Ins." When you deploy add-ins to your end users you would normally want to place the customizations in a more appropriate place using application configurations (look for more info on this in a later blog).
Our add-in is on the Add-Ins tab in the SDK test group, based on what was specified in our project settings. When we click on it a red sphere is added to the middle (target) of our globe.

So that's your first button, stay tuned for more...