Getting Started with ArcGIS API for Microsoft Silverlight/WPF
←
→
Page content transcription
If your browser does not render page correctly, please read the page content below
Getting Started with ArcGIS API for Microsoft Silverlight/WPF Transcript Copyright © 2009 ESRI All rights reserved. Printed in the United States of America. The information contained in this document is the exclusive property of ESRI. This work is protected under United States copyright law and other international copyright treaties and conventions. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, or by any information storage or retrieval system, except as expressly permitted in writing by ESRI. All requests should be sent to Attention: Contracts and Legal Services Manager, ESRI, 380 New York Street, Redlands, CA 92373-8100 USA. The information contained in this document is subject to change without notice. U.S. GOVERNMENT RESTRICTED/LIMITED RIGHTS Any software, documentation, and/or data delivered hereunder is subject to the terms of the License Agreement. In no event shall the U.S. Government acquire greater than RESTRICTED/LIMITED RIGHTS. At a minimum, use, duplication, or disclosure by the U.S. Government is subject to restrictions as set forth in FAR §52.227-14 Alternates I, II, and III (JUN 1987); FAR §52.227-19 (JUN 1987) and/or FAR §12.211/12.212 (Commercial Technical Data/Computer Software); and DFARS §252.227-7015 (NOV 1995) (Technical Data) and/or DFARS §227.7202 (Computer Software), as applicable. Contractor/Manufacturer is ESRI, 380 New York Street, Redlands, CA 92373-8100 USA. @esri.com, 3D Analyst, ACORN, Address Coder, ADF, AML, ArcAtlas, ArcCAD, ArcCatalog, ArcCOGO, ArcData, ArcDoc, ArcEdit, ArcEditor, ArcEurope, ArcExplorer, ArcExpress, ArcGIS, ArcGlobe, ArcGrid, ArcIMS, ARC/INFO, ArcInfo, ArcInfo Librarian, ArcInfo—Professional GIS, ArcInfo—The World's GIS, ArcLessons, ArcLocation, ArcLogistics, ArcMap, ArcNetwork, ArcNews, ArcObjects, ArcOpen, ArcPad, ArcPlot, ArcPress, ArcQuest, ArcReader, ArcScan, ArcScene, ArcSchool, ArcScripts, ArcSDE, ArcSdl, ArcSketch, ArcStorm, ArcSurvey, ArcTIN, ArcToolbox, ArcTools, ArcUSA, ArcUser, ArcView, ArcVoyager, ArcWatch, ArcWeb, ArcWorld, ArcXML, Atlas GIS, AtlasWare, Avenue, Business Analyst Online, BusinessMAP, CommunityInfo, Data Automation Kit, Database Integrator, DBI Kit, EDN, ESRI, ESRI BIS, ESRI—Team GIS, ESRI—The GIS Company, ESRI—The GIS People, ESRI—The GIS Software Leader, FormEdit, GeoCollector, Geographic Design System, Geography Matters, Geography Network, GIS by ESRI, GIS Data ReViewer, GIS Day, GIS for Everyone, GISData Server, JTX, MapBeans, MapCafé, MapData, MapObjects, Maplex, MapStudio, ModelBuilder, MOLE, MPS-Atlas, NetEngine, PC ARC/INFO, PC ARCPLOT, PC ARCSHELL, PC DATA CONVERSION, PC STARTER KIT, PC TABLES, PC ARCEDIT, PC NETWORK, PC OVERLAY, PLTS, Rent-a-Tech, RouteMAP, SDE, Site·Reporter, SML, Sourcebook·America, Spatial Database Engine, StreetEditor, StreetMap, Tapestry, the ARC/INFO logo, the ArcAtlas logo, the ArcCAD logo, the ArcCAD WorkBench logo, the ArcCOGO logo, the ArcData logo, the ArcData Online logo, the ArcEdit logo, the ArcEurope logo, the ArcExplorer logo, the ArcExpress logo, the ArcGIS logo, the ArcGIS Explorer logo, the ArcGrid logo, the ArcIMS logo, the ArcInfo logo, the ArcLogistics Route logo, the ArcNetwork logo, the ArcPad logo, the ArcPlot logo, the ArcPress for ArcView logo, the ArcPress logo, the ArcScan logo, the ArcScene logo, the ArcSDE CAD Client logo, the ArcSDE logo, the ArcStorm logo, the ArcTIN logo, the ArcTools logo, the ArcUSA logo, the ArcView 3D Analyst logo, the ArcView Data Publisher logo, the ArcView GIS logo, the ArcView Image Analysis logo, the ArcView Internet Map Server logo, the ArcView logo, the ArcView Network Analyst logo, the ArcView Spatial Analyst logo, the ArcView StreetMap 2000 logo, the ArcView StreetMap logo, the ArcView Tracking Analyst logo, the ArcWorld logo, the Atlas GIS logo, the Avenue logo, the BusinessMAP logo, the Data Automation Kit logo, the Digital Chart of the World logo, the ESRI Data logo, the ESRI globe logo, the ESRI Press logo, the Geography Network logo, the GIS Day logo, the MapCafé logo, the MapObjects Internet Map Server logo, the MapObjects logo, the MOLE logo, the NetEngine logo, the PC ARC/INFO logo, the Production Line Tool Set logo, the RouteMAP IMS logo, the RouteMAP logo, the SDE logo, The Geographic Advantage, The Geographic Approach, The World's Leading Desktop GIS, Water Writes, www.esri.com, www.esribis.com, www.geographynetwork.com, www.gis.com, www.gisday.com, and Your Personal Geographic Information System are trademarks, registered trademarks, or service marks of ESRI in the United States, the European Community, or certain other jurisdictions. Other companies and products mentioned herein may be trademarks or registered trademarks of their respective trademark owners.
Getting Started with ArcGIS API for Microsoft Silverlight/WPF Presenters: David Martinez Nathan Bennett ESRI Redlands, CA Good morning, everyone. My name is David Martinez, and I work on the product marketing team here in Redlands, California. Joining me today is Nathan Bennett, who works on the technical marketing team in Redlands. We would like to welcome everyone to today’s live training seminar. Copyright © 2009 ESRI. All rights reserved. 1
Seminar overview ¾ Topics Introduction to ArcGIS API for Microsoft Silverlight/WPF Getting started with ArcGIS API for Microsoft Silverlight/WPF Developing an interactive Web application Publishing Silverlight applications ¾ Format Each topic is followed by a software demonstration, review, and Q & A session. Send in your questions anytime during the presentation. Copyright © ESRI. All rights reserved. In this seminar, we will introduce and cover how to get started with the ArcGIS API for Microsoft Silverlight/WPF. We will discuss how to build applications with the API, as well as how to publish a Silverlight application. Each topic will be followed by a software demonstration, a review of concepts covered, and a question and answer session. Copyright © 2009 ESRI. All rights reserved. 2
Introduction to ArcGIS API for Microsoft Silverlight/WPF Copyright © ESRI. All rights reserved. We will begin with an introduction to the ArcGIS API for Microsoft Silverlight/WPF. Copyright © 2009 ESRI. All rights reserved. 3
ArcGIS Server overview Author, serve, and use GIS resources Maps, locators, models ArcGIS APIs Use REST or SOAP Use Serve Silverlight REST Flex JavaScript Author .NET Web ADF SOAP ArcGIS Java Web ADF Server ArcGIS Desktop Copyright © ESRI. All rights reserved. Our first topic we will cover is ArcGIS Server. ArcGIS Server allows you to serve and use GIS resources authored with ArcGIS Desktop. For example, resources can include map documents, geoprocessing models, routing, imagery, and address locators. Once published to ArcGIS Server, these resources become Web services and can be accessed by either the REST or SOAP protocol. The ArcGIS API for Microsoft Silverlight/WPF uses the REST protocol to access these services. The service is then consumed through a client, such as WPF or Silverlight application that we will be talking about in this seminar. Copyright © 2009 ESRI. All rights reserved. 4
Rich Internet Applications What are Rich Internet Applications (RIAs) Desktop-like functionality in a Web application Increased productivity RIAs + GIS Creative visualization of geographic analysis Interact with features, attributes, and symbols Copyright © ESRI. All rights reserved. Before we dive directly into the API it would be beneficial to understand and cover Rich Internet Applications (RIAs) or Rich Interactive Applications. RIAs deliver rich content that is comparable to what is available in desktop applications, but with all the benefits of the Web. These applications offer compelling graphics and an intuitive interface with a consistent user experience across multiple browsers and platforms. Developers and designers can create these types of applications with professional-quality tools like Microsoft Visual Studio for coding and Microsoft Expression Blend for layout and graphic design. For GIS users, RIAs can often perform and display better maps and interaction that traditional server-side applications. In particular, applications that avoid round trips to the server by processing locally on the client machines can also improve server performance. RIAs also allow a much more creative visualization of geographic analysis. Rather than static maps, RIAs allow a much more fast and dynamic map, with the ability to interact not only with the map itself, but the attributes, features, and symbols of the map. Copyright © 2009 ESRI. All rights reserved. 5
ArcGIS API for Microsoft Silverlight/WPF Built on Silverlight and WPF Platform Combine Rich Interactive Applications with ArcGIS Server and Bing Map Enterprise Services Applications rendered by Microsoft Silverlight plug-in Powered by ArcGIS Server REST services Only need URL to access a GIS Server Free to use No development or deployment license required for non- commercial use Access the online SDK and download the API library at the ArcGIS API for Microsoft Silverlight/WPF Server Resource Center Copyright © ESRI. All rights reserved. The ArcGIS API for Microsoft Silverlight/WPF is a full-featured API that allows you to consume ArcGIS Server and Bing Map Enterprise services inside a Silverlight application created with Microsoft Visual Studio or Visual Web Developer Express. You can also use the API to create Windows Presentation Foundation (WPF) applications, but in this presentation we are focusing on the Silverlight platform. As mentioned previously, this API is powered by REST services from ArcGIS Server. This means you only need a URL to access these services to add GIS functionality to your application. One of the great things about this API is it is free to use. The API is free to use in internal and non-commercial environments. The online SDK and API library can be downloaded at the ArcGIS API for Microsoft Silverlight/WPF Resource Center. In the next section of this presentation we will walk you through downloading and using the API. Copyright © 2009 ESRI. All rights reserved. 6
Microsoft Silverlight framework Visual Studio Code using an integrated development environment (IDE) Interactive step-though debugging Rich set of components including the Silverlight toolkit Other Silverlight Tools Expression Blend Deep Zoom Composer Coding with .NET Framework XAML • Declarative XML language C# or VB • Object-oriented programming language Copyright © ESRI. All rights reserved. In this seminar, we will discuss developing Silverlight applications with Microsoft Visual Studio. Visual Studio is an integrated development environment (IDE) which includes a full-featured code and XAML editor, debugger, profiler, data designer, etc. If you’re are going to build Silverlight applications, you should use Visual Studio. As you do more Silverlight development, there are other tools that you might want to utilize such as Expression Blend. Expression Blend is a tool for designers and developers to create graphics, design animations, and produce user experiences. Expression Blend uses XAML and the same project system as Visual Studio. In Silverlight, XAML will be used to create visible user interfaces, data binding, and other features. To handle the response to events and manipulate objects declared in XAML, languages such as C# [Sharp] or Visual Basic will be used. Copyright © 2009 ESRI. All rights reserved. 7
Microsoft Silverlight framework Plug-in environment Silverlight runtime Applications deploy consistently on All major browsers Windows, Mac, and Linux Cross-platform Application dependent on Silverlight plug-in only Security Through Silverlight plug-in Strong developer community http://silverlight.net/ http://msdn.microsoft.com/silverlight Copyright © ESRI. All rights reserved. The Silverlight framework operates in a plug-in environment around the Silverlight runtime. This allows Silverlight applications to run consistently on all major browsers and operating systems. Silverlight currently runs on Windows, Mac, and on Linux through the open source project called Mono. An added bonus is the security provided by the Silverlight plug-in. Silverlight applications operate within a security boundary that is called a sandbox. What this basically means is, when you are running client code in Silverlight, by default Silverlight will restrict that code from accessing your file system or doing anything that could damage your machine. There is also a strong developer community around the Silverlight platform including our own. We have a Silverlight community at the Resource Center. Do not worry about copying these URLs at this time. We will have them all available at the end of the presentation. Copyright © 2009 ESRI. All rights reserved. 8
System requirements Web browser Internet Explorer, Firefox, Google Chrome, etc. Silverlight runtime Version 2 or 3 Programming with Silverlight Visual Studio 2008 SP1 or Visual Web Developer Express with SP1 Silverlight 3 Tools for Visual Studio 2008 SP1 Silverlight 3 Toolkit Copyright © ESRI. All rights reserved. There are only a few system requirements necessary to view Silverlight applications. A Silverlight application runs in the browser and requires the Silverlight plug-in for the browser. Any browser that is compatible with the Silverlight plug-in will display the Silverlight application. Currently, the ArcGIS API for Microsoft Silverlight/WPF will display on versions 2 and 3 of the Silverlight runtime. To develop with Silverlight and the ArcGIS API for Microsoft Silverlight/WPF, you need to have Visual Studio 2008 with SPI or Visual Web Developer Express with SP1. You will also need Silverlight 3 tools for Visual Studio 2008 SP,1 and we also recommend installing the Silverlight 3 toolkit. Copyright © 2009 ESRI. All rights reserved. 9
Software demonstration Copyright © ESRI. All rights reserved. Now I will launch into the Silverlight application and review how it is created in Visual Studio. In my first example, I see a simple Silverlight application that contains two basemaps from ArcGIS Online. To switch between the maps, a slider control is used along with the shiny blue theme from the Silverlight Toolkit. This theme is a simple way to enhance the user interface— the UI—in your application. It also contains a dynamic map service for Louisville, Kentucky, which includes layers for parcel and zoning. You can use the mouse to navigate the map. If I click the map, I can drag the map to pan, roll the mouse wheel to zoom in or out, and I can hold down the Shift key and draw a box around an area I would like to zoom into. If I zoom in enough, you will see the parcels layers of the dynamic map service. This is all default functionality of a mapping application built with the ArcGIS API for Microsoft Silverlight/WPF. What we are looking at is a compiled Silverlight application running inside a Web browser. If we right-click the map, we see the context menu for the Silverlight plug-in. This tells us that the Silverlight application is running inside the Silverlight plug-in. I will now open Visual Studio and see how these services were called. Inside Visual Studio, we can see the simple code it takes to write this application. Inside the grid container there is an ESRI map element to use the map component. Inside this element, there is an extent tag to define the initial view extent of the map. Importantly, there are two ArcGIS tiled map service layer elements with ID tags to define the names, and URLs defining where the surface is coming from. These map services are coming from ArcGIS Online, and the name of the services are 3_Imagery_Prime_World_2D/MapServer and ESRI_StreetMap_World_2D/MapServer. There is Copyright © 2009 ESRI. All rights reserved. 10
also a dynamic map service being consumed from the ArcGIS Online sample server for the Louisville land records. To use a dynamic map service, I used the ArcGIS Dynamic Map Service Layer Element, and I added an opacity property to set the transparency for this layer. There are a few things to consider when adding layers to a map. First, layers are drawn bottom to top. So, the first layer in a layer collection is drawn first—on the bottom. And, each subsequent layer is drawn on top of it. Under the commented section called Basemap Controls, I have also defined the UI for the sliding control as well as the shiny blue theme from the Silverlight Toolkit. Now I am going to show you how easy it is to change the URL of the imagery map service. But first I will need to have access to a service directory of a GIS server. Here, if I go to the service directory for ArcGIS Online, I am currently using the I3 Imagery Prime World 2D map service. If I want to switch the URL or the service in my application, I can click on another service. For example, I will click on NGS, Topo, U.S. 2D. I am taken to a page with information for just this service. This gives me all types of information regarding the service including whether it's cached or not, tile info, the spatial reference, and information such as the extent of the service. At this point, I'm only interested in the URL, which I can copy from the address bar of my Web browser. I return to Visual Studio, I select and delete the old URL, paste the new URL. I should also remove the name Imagery from the slider control text block text tag and add the new topo name. I just hit F5 to run from Visual Studio. Now I have the same application, but instead of the imagery map, it's now using the topo map. I can demonstrate this change by using the slider control to switch between the maps. Copyright © 2009 ESRI. All rights reserved. 11
ArcGIS Services Directory List of published services Services published from ArcGIS Server Manager/ArcCatalog Web interface Provides information for each service Expose the Service’s URL Example http://server.arcgisonline.com/ArcGIS/rest/ services/ESRI_StreetMap_World_2D/MapServer • URL goes into Silverlight application Copyright © ESRI. All rights reserved. In our first demonstration, we copied URLs from the Services Directory of ArcGIS Online. The Services Directory is a list of services available from ArcGIS Server. The services have been published through either ArcCatalog or ArcGIS Server Manager. The Services Directory will be created whenever an ArcGIS Server is configured. Much like ArcGIS Server Manager, the Service directory is navigated through a Web interface meaning when launched, your Services directory will display in your default Web browser. The Service directory provides information for your services and, most importantly for your Silverlight application, the URL your services are accessing. As I demonstrated in our previous demo, I copied the URL from the Web browser address bar and pasted it into the ArcGIS Server tiled map service layer element. This allowed me to reference a cached map service from ArcGIS Online in my Silverlight application. Copyright © 2009 ESRI. All rights reserved. 12
Review and Q & A ¾ ArcGIS Server Overview ¾ Rich Internet Applications ¾ ArcGIS API for Microsoft Silverlight/WPF ¾ Microsoft Silverlight Framework ¾ ArcGIS Services Directory Photo of Presenters Copyright © ESRI. All rights reserved. To sum up the first session, ArcGIS Server allows you to publish and serve GIS resources created with ArcGIS Desktop. Rich Internet applications are an expressive, interactive, and are a combination of desktop and Web functionality. The ArcGIS API for Microsoft Silverlight/WPF allows Rich Internet Applications to be built on top of ArcGIS Server services. All Silverlight applications run with the Silverlight plug-in. Finally, the Services Directory is a Web interface created by ArcGIS Server to allow you to browse the contents of an ArcGIS Server and obtain information about the services published. Now let’s take a few questions from some of our attendees. Nate? Thanks, Dave. We've got some good questions coming in. First, Greg from Savannah asks, you mentioned that Visual Studio 2008 is required. Is it required to use Silverlight in general, or is it required for the ArcGIS Silverlight API? Well Greg, Visual Studio 2008 is required for Silverlight in general, regardless of our API. So if you want to do any Silverlight development at all, you're going to need Visual Studio 2008 as well as the other prerequisites that Dave mentioned earlier, such as Visual Studio tools for Silverlight and also Expression Blend, Expression Blend SDK, and the Silverlight 3 Toolkit. We've got another question here from Tim from Omaha. He asks, you talked about ArcGIS Silverlight API being able to access Bing Maps. How do I implement this? Well, within the ArcGIS Silverlight API, we provide objects to help you work with some of the services available from Bing Maps such as tiled basemap layers, as well as the Bing Maps that have a geocoder. To implement this, you need to retrieve a token from Bing Maps. And the way you can do that is Copyright © 2009 ESRI. All rights reserved. 13
in the ASPX or HTML page in which the Silverlight application is hosted. You can retrieve a token through the Bing Maps SOAP end point and then you can pass that token to the application as an initialization parameter. And then once it's within the Silverlight application, you can access it from the main page XAML. If you go to the Silverlight API reference located at resources.esri.com, and then you search for Silverlight, if you click on that first entry you can navigate to the API documentation and there is a sample in there that will walk you through step by step how to access a Bing Maps token and integrate it into your application. We've got another question here from John in Atlanta. And he asks, is ArcGIS Server API for Silverlight installed with ArcGIS Server? The answer to that question is no, it is not installed. You're going to have to go ahead and download that from the Resource Center. In our next demonstration, we'll walk you through that exact process of how you would go about downloading and installing the SDK. We've got another question here from John from Cleveland. And he asks, what is the licensing model for the ArcGIS API for Microsoft Silverlight WPF? Dave, do you want to answer that one? Yeah, thanks Nate. The APIs are available at no cost for internal or personal within an organization, and external, noncommercial purposes. This means no license fees are required for internal use or for noncommercial external use. If you're going to use the API for commercial purposes, you can purchase a subscription through ArcGIS Online through the ArcGIS Web mapping APIs. To find out more information, you can contact your local regional ESRI office or your local distributor to find out more about the subscription pricing and licensing. Thanks, Dave. We've got another question here from Jim in Ontario. And he asks, what does Silverlight offer an RIA developer that Flex Java and JavaScript do not? That's a good question. In terms of the functionality exposed in the API to access ArcGIS Server, you'll find that Silverlight, Flex, and JavaScript all have very similar functions and can do similar things dealing with ArcGIS Server. So the main difference why you would choose Silverlight over the other APIs is that you're more comfortable working in the Microsoft environment using Visual Studio as well as accessing objects in .NET that you may have experience with. So if you're using a Web client object to download data from a remote server using data types, building projects, you'll find that the learning curve will be much less significant because you already have previous experience working in that environment. So really it's all about what API is right for you, right for your organization, and right for your development experience. So if you're a .NET head, Silverlight may be the right choice. One more question here from Sara in Halifax. And she asks, what are the main differences between Silverlight and WPF? That's a great question. Well, to start off, Silverlight is built in the WPF environment, and you can build applications using XAML in one and use it in the other. You can also write controls once and use them in both places. Silverlight is great for Copyright © 2009 ESRI. All rights reserved. 14
building Web applications, but if you want to build the richest possible Web applications, WPF is the high end. One of the other advantages of using WPF is that it doesn't run within the security sandbox that Dave mentioned, which means you have access to the remote file system without requiring a user saying it's okay. We've got another question here coming from Vincent Z. in Bluffton concerning the lifespan of the product. For example, VB6—which one should I use—Silverlight or WPF? You know, honestly, well…we can't say what Microsoft's plans are for the future, but I think that both code bases are not going away. So I think the question is more related to in what kind of capacity are these applications going to be running, what kind of access do they need. The nice thing about Silverlight is, it doesn't need to be installed on a person's machine, it's installed on a Web server so it's easier for them to get updates to the product. But if you're looking for a more sophisticated application with some of that advanced functionality, WPF may be the right choice. So it's really up to you. I think they're both pretty much a safe bet. I'll answer just one more question here from Jules in Virginia Beach. And that is, will end users have any different system requirements whether they develop your app with Silverlight versus Flex, such as plug-ins? That's a good question. The different system requirements for an end users are that they need to have the appropriate player for the RIA application. So if you're using Flex, you need to have the Flash Player plug-in, and if you're using Silverlight, you need to have the Silverlight Player installed. Those are really the only requirements other than having a Web browser that can access these applications. But overall, the difference is just the player. Once they have the player installed, they'll be able to consume the application. Dave? Okay, great. Thanks, Nate. Let's get back to our presentation. Copyright © 2009 ESRI. All rights reserved. 15
Getting started with ArcGIS API for Microsoft Silverlight/WPF Copyright © ESRI. All rights reserved. In this section, I’m going to talk about how to get started with the ArcGIS API for Microsoft Silverlight/WPF Copyright © 2009 ESRI. All rights reserved. 16
Features continued Task Find Identify Query Address Locator • Geocode Geoprocessing Routing Copyright © ESRI. All rights reserved. The API for Microsoft Silverlight/WPF includes methods for performing common GIS tasks. Tasks include the ability to find, identify, and query features, as well as geocoding and routing tasks. The API can also use geometry services, which are used to work dynamically with the geometry of features used in your application, such as measuring, performing simple buffer analysis, projecting, or simplifying features. With the API, you can also consume your custom geoprocessing tasks. This can be accomplished by publishing your models and configuring them as tasks. One important thing to take note of tasks is they do not define user interfaces, so to allow your application’s user to interact with a task, you must provide an interface for specifying the task’s input and displaying the task’s results. Copyright © 2009 ESRI. All rights reserved. 17
Create your first application 1. Download API library Unzip 2. Reference assemblies in Visual Studio 3. Write code XAML and C# or VB 4. Run application Reference Download assemblies Write code Run API Library in Visual application Studio Copyright © ESRI. All rights reserved. So how do you downloaded and use the libraries for the API? Well it’s pretty easy. First, you download the ArcGIS API for Microsoft Silverlight/WPF Zip file. You unzip the content in a directory of your choice. Inside you will find a set of assemblies. All assemblies are supported in 32-bit and 64-bit operating environments. You will reference the assemblies in your application using Visual Studio. You write some code in XAML, C # [Sharp], or VB. And finally, you compile your app and you run your application. Copyright © 2009 ESRI. All rights reserved. 18
Software demonstration Copyright © ESRI. All rights reserved. In our next demonstration, I will walk you through how to create your first project in Visual Studio. But first, we need to download the API from the Resource Center. As I launch the Resource Center, there is a link on the right-hand side to download the API under the Getting Started section. Due to time constraints, we have downloaded the API libraries and saved them to our local C drive. I will open Visual Studio and create a new application from scratch. Under File, I select New, select Project, and I select the Silverlight application template. And I click OK. I will be using the C Sharp language for all of our demos. You will be prompted to create a page to host your Silverlight application. A window titled New Silverlight Application will display to inform you to click the check box below to host a Silverlight application in a Web site. Click the check box if it is not checked and accept the defaults by clicking OK. By default, the Silverlight application includes a main page.xaml file. This is the container for the Silverlight controls. You will only add mark-up to the XAML view to create your layout and designs. To add the ArcGIS API for Microsoft Silverlight WPF components, I need to add a reference in our project in Solution Explorer. I select and right-click References, select Add Reference, I go to the Browse tag, and I look in the folder where my API assemblies are. I'm going to select the ESRI ArcGIS Client Assembly and now I hit OK. And now what this does is, it references it in our project. Next, I need to add an XML name space mapping that references the ESRI ArcGIS client name space in the ESRI ArcGIS Client Assembly. As I start typing, the value after the XML name Copyright © 2009 ESRI. All rights reserved. 19
spacing attribute XMLNS defines the name space identifier you'll use to reference controls in the ESRI ArcGIS client name space. In this example, the identifier is ESRI. As I select the ESRI ArcGIS client assembly, I hit Enter, and I can now use the assembly. To save time, I will switch to a project already created. As we launch our project already created, I would like to note that we're going to use ESRI symbols and ESRI convertors. So I've already added these name spaces for the ESRI ArcGIS client symbols and the ESRI ArcGIS client value convertors. Since I declared name spaces for these assemblies, I can use the components in the API. Inside the name grid element, we have resources that can be shared throughout the application. Inside the grid resource element, I will add some graphics to symbolize police stations using simple marker symbols. To use elements and XAMLs, I need to prefix the name with the name specified in the XML name space mapping. As I type ESRI symbols, I should see an intelligence window—which I do. I have a list of items to choose, I select the ESRI symbols, and I select the simple marker symbol. I will give it a name of SMS Police Stations. And what this does is, it will display the police stations when I retrieve the feature layer. I will add properties for style, size, and color. This will be used to display feature graphics for the locations of the police stations in the feature layer. As I scroll down, the rest of the ESRI symbols will be used to display graphics for the fire stations and other graphics in the application. To display the attributes of these symbols when I mouse over, I am going to use a MapTip. A dictionary convertor resource must be specified to allow binding to a fill when declaring a MapTip. As you can see, we have our map control with an extent and the two basemaps used in our previous example. However, one thing I would like to point out is, I have added an event method for Map Loaded. This will basically call an event handler to load the query task when the application starts. As I scroll down in my code, there is a feature layer. A feature layer is a type of graphics layer that contains features such as geometries and attributes. It contains an ID property for police stations, an ID property where one equals one, meaning all features will be retrieved. The Feature Symbol property will use a simple marker symbol to display the individual graphics retrieved from the Louisville Land Records map service. And to include the police station names and addresses, I have specified the outflow property to retrieve the attributes from the feature layer. Inside the feature layer MapTip element, it contains the MapTips definition and the logic to display the UI I'm going to retrieve from the feature layer inside the grid. Inside the first stack panel, there are two text blocks controls to display the symbol and to bind the name of the police station attributes using the dictionary converter class. I repeat the same process in the next stack panel to bind the address. A great thing about using feature layers is it allows you to display feature graphics without writing any managed .NET code—also called code-behind. As I scroll further down, the next part of this application defines a UI to query the fire stations. Using the Query task, it will display the result features in a graphics layer. It has MapTips enabled. Since tasks do not define user interfaces, I have implemented an interface for the query task input. This allows application users to execute queries to find fire stations. Inside the Copyright © 2009 ESRI. All rights reserved. 20
graphics layer element, you can see we have defined the UI to bind the name, address, and district to the graphics layer contained in the map element. When specifying graphics layers, be sure to specify the graphics layer below any base layer. For example, like the tiled map service layer such as the street map. This will allow the graphics to display above those layers when you run your application. As I scroll down further, we have the same slider control I used in the first demonstration. And I have created some UI for the query task. After I have specified the query task UI, I need to define it's execution logic in the main pages code-behind. This execution logic can be divided into three parts, which is task execution, task results display, and execution error handling. If we go to the code-behind, under the Initialize Component method, it declares and creates a query object. The query object is used to define the execution parameters for query tasks. The next lines of code return the geometries, x- and y-coordinates, it specifies what features I want, the attributes to return and add with an asterisk. To initialize a query task, I set the map service layer using our URL. This will query by passing the layer's URL to the query task constructor. This example uses the layer of the Louisville Land Records service. Next, I specify a handler for the executed complete event, and a handler for the failed event. The executed completed event method will be called when the query task is done executing. The failed event method will trigger if there is a problem executing the query. When the map is loaded, it executes a query task by calling the queryFireTaskFire.ExecuteAsync (_queryFire) as we can see in the map loaded event method. The ExecutedComplete method is called when the query task is done executing, and it basically gets a reference to the results graphics layer, it clears any previously added graphics from it, it checks whether any results satisfying the query were found, and it adds those results as symbols to the graphics layer. Here is the failed event method. And what this does, it handles any problems with executing the query task. It will notify the user of the problem with the MessageBox. I have also created some additional methods to handle some of the events for the UI created in XAML. For example, when a user hits the query task or the geographic filter button, I need code-behind to handle these events. Now, let's launch a browser and see how this application looks. As I launch the application, you can see the blue symbols are the police stations and the red symbols are the fire stations. Each graphic symbol contains MapTips that display information about the current graphic attribute when I mouse over. To display the fire stations when the application is started, we initialize the query task to execute on the map loaded event method. If I select the Geographic Filter button, it allows me to draw a polygon on the map. And to run a query against that, I select the Query Fire Stations button and the application executes a spatial query to find fire stations within the polygon. Copyright © 2009 ESRI. All rights reserved. 21
Review and Q & A ¾ Features of the ArcGIS API for Microsoft Silverlight/WPF Maps Graphics Tasks ¾ Create your first application Photo of Presenters Copyright © ESRI. All rights reserved. Let’s review the concepts of the second section. We took a look at some of the features in the API such as maps, graphics, and tasks, and we learned how they are implemented and used in a Silverlight application. We then looked at how to create your first Silverlight application and implemented some of these features. At this time, I’ll turn it over to Nate to take some questions from some of our attendees. Thanks, Dave. We've got some great questions coming in. First one from David in Oklahoma City asks, I have a 64-bit workstation for development and will host on a 64-bit server. Will Silverlight work properly in these environments? That's a great question. In terms of developing on a 64-bit workstation, it works perfectly fine. That's actually the environment I use for my Silverlight development, and hosting Silverlight apps on a 64-bit server is also fine. The only issue you could have is if your end users are using a 64-bit browser. For Silverlight applications, you need to be using a 32-bit browser. But in terms of development and hosting, 64-bit is perfectly fine. Another question here from Seychelles in Miami. Is there any configuration that has to be done in ArcGIS Server to be able to use map services in Silverlight? The answer to that question is no. If you publish a service with ArcGIS Server, whether it's an ArcGIS tiled map service layer or a dynamic map service layer, those can be consumed in Silverlight without any extra steps being done on the server. So you just point to that URL, and as long as it's a valid URL that returns your features and your map tiles, everything should work fine without any extra steps needing to be taken. Copyright © 2009 ESRI. All rights reserved. 22
Alejandro from Miami asks, do we need to have ArcGIS Server to run Silverlight apps? The answer to that question is no. You do not need to have ArcGIS Server. You could build a Silverlight application, download the client assemblies, and build an application to use basemap services or geoprocessing tasks that are published on the Internet, such as our ArcGIS Online sample servers. The one thing you'll find, though, is if you have your own ArcGIS Server, you'll be able to publish your own data, you'll be able to publish map services that you can consume, geoprocessing models, query tasks that access your data, and draw client-side graphics. So you don't need to have ArcGIS Server to run Silverlight, but I think you can make much more compelling applications that are relevant to you if you have ArcGIS Server. Another question here from Ion in Tempe. Does this work with Expression Blend? The answer for that question is yes. Our API works with …it can work in an Expression Blend environment, you can use Expression Blend for your layout, building a lot of that XAML. And actually in the last demonstration, we'll show how Expression Blend is integrated right into Visual Studio. But yeah, absolutely, it does work with Expression Blend and it probably should be used to help speed up your development. Thanks, Nate. We’ll go back to our presentation here. Copyright © 2009 ESRI. All rights reserved. 23
Developing an interactive Web application Copyright © ESRI. All rights reserved. So far we have looked at some of the features and functionality of the API. When building real- world applications using the API for Microsoft Silverlight/WPF, you will likely want to take advantage of the vast library components offered with the API and the Silverlight toolkit. In our third section, we will take a look at some of the components and capabilities in the Silverlight toolkit and how they are used with the ArcGIS API for Microsoft Silverlight/WPF to create Silverlight applications on top of ArcGIS services. Copyright © 2009 ESRI. All rights reserved. 24
Silverlight capabilities Components Data grids • Results of query Charts • Visualize attributes ESRI toolkit • Navigation • MapTips • Toolbar • More… Copyright © ESRI. All rights reserved. Out of the box, you can use ready-made data components of the Silverlight framework such as data grids, tree views, and themes to enhance your application’s appearance. The data visualization component included in the Silverlight toolkit offers charts to visualize and analyze your data. ESRI has also created a set of widgets (controls) designed to work with the map control. For example, you can add the navigation control to your application to zoom in and out, pan, rotate as well full extent. Copyright © 2009 ESRI. All rights reserved. 25
Advanced capabilities Data binding Provides a simple way to display and interact with data Synchronize actions between components Events Interactions or changes with application • Mouse-click, button, page load, data received Working with Events Application users trigger events Event listeners wait for events Event handlers perform action Copyright © ESRI. All rights reserved. In our previous software demonstration we showed how to use a feature layer and data bind it to a specific key in a dictionary using the DictionaryConverter resource. This was possible by using data binding which is a simple way for Silverlight-based applications to display and interact with data. Often times, your GIS Web application will need to include geospatial functionality that goes beyond simple map display and interaction. For instance, your application may need to give your users the ability to view the locations of projects that are on schedule, find parcels that are within a certain distance of a river, or plot the area within a five-minute drive of a proposed store location. In this case you will be working with GIS tasks and in the .NET code-behind to handle the events in your application. From a programming perspective, an event is a message sent by an object to signal the occurrence of an action. An action could be caused by user interaction, such as a mouse click, or it could be triggered by the internal logic of a class. Basically, the purpose of events is to communicate time-specific, relatively lightweight information from an object at run time and potentially deliver that information to other objects in the application. Copyright © 2009 ESRI. All rights reserved. 26
Software demonstration Copyright © ESRI. All rights reserved. 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. The polygons represent one-, two- and three-minute drive times. As I mouse over each drive- time poly graphic, it contains a MapTip from the ESRI toolkit. This displays the attributes for that graphic such as the buffer time. If I click on another fire station, the application will clear all previous graphics and execute the geoprocessing task for that area. One thing I would like to point out is, the mouse cursor changes to a hand once I mouse over a fire station graphic, and it changes back to an arrow when it's not selected. This is all possible with the events in the application. Now let's go ahead and open Visual Studio to see how I handle the events to execute the geoprocessing task, as well as the various components implemented. In the main page XAML, I used a picture marker symbol to define the source and image from the graphic to display the fire Copyright © 2009 ESRI. All rights reserved. 27
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. Copyright © 2009 ESRI. All rights reserved. 28
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 © 2009 ESRI. All rights reserved. 29
Review and Q & A ¾ Components Data grids Charts ¾Data binding ¾Events Generated on change in application Photo of Presenters 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 Copyright © 2009 ESRI. All rights reserved. 30
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 © 2009 ESRI. All rights reserved. 31
Publishing Silverlight applications Copyright © ESRI. All rights reserved. In our last section, we will publish a Silverlight application and discuss some considerations for deployment. Copyright © 2009 ESRI. All rights reserved. 32
Requirements and considerations Publishing your application XAP files: downloaded by the browser Tips Web server • Allow MIME types of the following to your server: Extension MIME Type .xap application/x-silverlight-app Expression blend Cross-domain access • Requires a clientaccesspolicy.xml file Instantiate the Silverlight plug-in as early as possible Copyright © ESRI. All rights reserved. Once an application has been fully tested and is confirmed to be stable, the application is ready to be deployed. I will open Visual Studio and publish the application using our last demonstration. In Visual Studio I select Build, Publish Silverlight Application. And for this example, we are going to publish it to the local Internet information server. I select the local IIS icon, I highlight the default Web site directory. In the upper right-hand corner, select Create New Web Application, and I will give it a name of LTS_demo. I click Open, and I will select Publish. This will publish all the files I need to run my Silverlight application on a Web server. I can also publish an application in Solution Explorer, as well. If I open my browser and type the address, it will launch my application that I'm running on my local Web server. Silverlight applications are downloaded by the browser in ZAP files, and ZAP files are located in the client bin folder. A ZAP is a compressed package of the code, data files, and manifest for your application. The ZAP manifest specifies which managed code assemblies to download, which language resources to use, the entry point to your application, and it contains other information required to load your application. Silverlight applications can be hosted on most types of Web servers like Internet information server, also called IIS, or Apache. However, most Web servers are usually configured to serve only a short list of well known file extensions. To allow Silverlight applications to be served from your Web server, you have to allow the mine types for ZAP. You can find the mine types in IS Web servers by selecting default Web site properties, selecting the HTTP header tabs, and selecting file types. As you can see, we have both file types for XAML and ZAP. IIS7, included Copyright © 2009 ESRI. All rights reserved. 33
in Windows Server 2008, already includes all the relevant mine types for both WPF and Silverlight including both ZAP and XAML extensions. So if you are using Windows Server 2008, you're all set. The same applies to a clean install of Windows Vista SP1. An alternative to using Visual Studio to create XAML is to design XAML using Expression Blend. A Silverlight application creating Visual Studio can be easily opened in Expression Blend by right-clicking on the main page XAML file in Studio Solution Explorer and by selecting Open in Expression Blend from the Context menu. Silverlight applications not hosted on the same server or domain as the data services you are accessing will need a client access poly.xml file on the remote Web service root directory. In other words, if you deploy a Silverlight application and an ArcGIS Server on different servers or domains, you will need a client access policy.xml file. Here is an example of the policy file used by ArcGIS Online. You could use this as a reference when creating your own client policy.xml file. Silverlight begins downloading components and running your application as soon as the Silverlight plug-in object is loaded. To improve the load times of your Web page, you can call the Silverlight plug-in as early as possible in your Web page logic. This could be whether it's in HTML or whether it's in ASP.NET. Copyright © 2009 ESRI. All rights reserved. 34
You can also read