I will now demonstrate how to use some of the functionality we just covered in this section.
In this next application, I have the navigation component developed by ESRI. This allows me to pan the map or rotate. It also has a full extent button to view the map at it's largest extent. As I pan around the map, there is a progress bar. This allows me to display the map's progress on the screen. Using the same query task in our previous example to display the fire stations, you will notice we have changed the graphic symbol from a simple marker symbol to a picture marker symbol with the fire station image. If I click on one of the fire stations on the map, the application will launch a progress bar to execute the geoprocessing task to calculate the drive times based on the area clicked. It will also zoom in to that area.
station results from the query task. As I scroll down, the next three simple fill symbols is the UI to display the geometry of the result features from the geoprocessing task. Inside the map element, there are two event methods specified—one for the progress bar and the other to load the query task.
If I right-click the map progress bar method and select Navigate to Event Handler, it will take me to the code-behind, which contains the logic to implement this handler. The progress bar is a component included in Silverlight. I will go back to the main page XAML editor and see how we declared the UI in XAML for the progress bar. But first, before doing this, I think we should point out that we added an opacity property to set the graphics layer ID for drive times. This basically sets the transparency for the drive-time polygons. As we scroll to the progress bar and the calculate drive times polygon progress bar, I have placed them both inside a grid. This basically means it allows me to position them exactly where I want them to appear in the application.
In the next section, I used a MapTip component to display the attributes from the drive time geoprocessing task when I click on the map polygons. To use this component, I reference the ESRI ArcGIS Client Toolkit assembly and I added an XML name spacing to reference it. One of the great things about Silverlight is you can use components already created to enhance your application. For example, in the next section, this is all the XAML you need to use the
navigation component which is included in the ESRI Toolkit. To reference this element, I used the prefix name that was specified in the XML name space mapping and I gave it a name equal to navigation. This allowed me to reference it in the code-behind. I also assigned the margin to a property of five.
If I go back to the code-behind and I view the map loaded method, it shows me the code it takes to use navigation and MapTips control. Pretty simple code, huh? Since we are already in the code-behind, I will scroll down and review the code in this application. The query task has not changed, so we won't review that. But, to handle events such as interacting with graphics in the application when I mouse over, we have added some handlers. For instance, when I select a fire station, the mouse pointer changes to a hand and it changes back to an arrow when not on the graphic. In the mouse left button method, I launch the progress bar to calculate the drive-time polygons. I have also implemented the event to handle the mouse left button click. This allowed me to generate the geoprocessing task.
To initialize a geoprocessing task, just simply declare a geoprocessor object. I create the object, (instantiate) with the new keyword, and pass the URL of the geoprocessing service REST inpoint to the constructor. In this example, I'm using sample servers from ArcGIS Online. Next, a handler was specified for the task executed complete event. This will be called when the
geoprocessor task is done executing. The geoprocessing task execution method takes a list of GP parameter objects as inputs. All the geoprocessing parameter classes like the GP feature record set layer and GP stream derive from this class. The create drive time polygon service has two input parameters—the input location, which is of type GP feature record set layer, and drive times, which is of type GP stream.
If I open up the service directory for this sample server, I can see the parameters and data types.
There are two sets of members for executing and handling the results of a geoprocessing task—
synchronous and asynchronous. For this example, it uses a synchronous geoprocessing service.
When using a service to execute synchronous, you initiate the operation using the Execute A Sync method. The Geoprocessor Execute A Complete method is invoked when the task is complete. It basically loops through the result features, adds each to the graphics layer.
As you become more familiar with working with tasks such as geoprocessing, query, and address locators, you will notice some similar coding patterns. You probably could see that when we defined the tasks for the query and the task for the geoprocessing tasks—there was a lot of similar coding patterns. The good news is, we have a lot of the samples on the Resource Center on how to implement these tasks. You could literally copy and paste these samples directly into your Visual Studio project.
Copyright © ESRI. All rights reserved.
To sum up the third section, events are generated on a change in an application. Event listeners wait for an event and an event handler performs an action based on an event. Data binding is a method for passing data around an application, and can be used to link features on the maps, to records, in the data grid, or chart component. Finally, the ArcGIS API for Microsoft Silverlight WPF can use ready-made components from the Silverlight Toolkit, as well as the ESRI Toolkit, to enhance your application.
Now let's take some more questions from our attendees. Nate?
All right, thanks Dave. We've got some questions here. Gabby in McKinney asks, is the code for these demos available? The answer to that question is yes. If you go to the Silverlight Resource Center, resources.esri.com and then search for Silverlight and then click that first link that comes up, if you click on the Community tab, one of the first entries will be all three demos for this live training seminar. So they're all three up there and ready for you to use. They're compiled with Silverlight 3, so if you have Silverlight 2, make sure and upgrade before you use a demo.
Robert in Vancouver asks, is the ESRI Toolkit included with the free API? The answer to that question is yes. The Toolkit assembly is in there and ready to use.
Another question here from Melissa in Fort Worth. And she asks, is there a free IDE in which we can create Silverlight Web applications? Well, the answer to that question is yes. For development, Microsoft offers a Visual Studio Web development express integrated
development environment that you can use to create Silverlight applications. I think it's also
important to note that Expression Blend 3 is available for download, and I think it has a 30-day eval. So those are two software packages that you can download to begin interacting with developing Silverlight applications.
Another question here from Jean in Oakland. And she asks, if there is no IIS installed, can Silverlight applications be run/tested in the local machine. Well, the answer to that question is yes. There is a test Web server that comes with Visual Studio that you can use to run your applications. So if you don't have IIS installed, you can still develop and debug Silverlight applications.
We've got another question here from Daniel in Madison. Daniel asks, how do we add in our own personal data layers on top of ArcGIS Online services? That's a great question, Daniel.
There are two main ways that you can do that. You can create maps in desktop and publish them to server as either cached tiled map services or dynamic map services, and you can use those layers in Silverlight and access the tile services, bit maps, or whatnot, to add your data that way.
So that way, you can add some good cartography and get things symbolized just the way you want. The other option is to use client-side graphics. And the way you can do that is, you could use a feature layer like what we used before, or a graphics layer with a query task and download the data. And then, on the client side, you can decide how to symbolize that by adding graphics and MapTips and whatnot. So those are really the two main ways that you can add your own data on top of ArcGIS Online services. David?
Great. Thank you, Nate. And thank you everyone, for your questions.
Copyright © ESRI. All rights reserved.