How to Use the WCF Service in ArcGIS viewer for Silverlight to display the Rainfall Map (1)

Source: Internet
Author: User
Tags silverlight

In my work, some users like to use ArcGIS viewer for Silverlight to build some simple projects to serve as the prototype system of the system to be built, or try some functions, this is a convenient and quick way. However, not all functions can be configured using the viewer. Sometimes, extended development is required.

In particular, some users already have a series of data access encapsulated WCF in other systems, but they only need to call and display the data in the viewer, in this case, you need to flexibly expand the viewer. In this series of articles, I will use the WCF call data to display the Rainfall Map.

I originally wanted to directly write the short section of the WCF call, but I found that if I do not know the extended development of the viewer, many problems will not be introduced in the future. Therefore, this series will cover the topic in three sections:

The first article describes how to expand and develop tools for the viewer;

Article 2 describes how to call the WCF Service for data query;

Article 3 describes how to display the queried data in a topic diagram.

I won't talk about using ArcGIS viewer for Silverlight to configure the project. You should be better at it and start with extended development:

1. Create a silveright project.

Note that the ASP. NET Website is selected as the Silverlight host. Why? If you have noticed the Application Generated by using the viewer configuration, it is clear that it is actually a site, and we will also use this site as the host for debugging in our project.

As mentioned above, you need to clear unnecessary files because you use websites.

We can see two projects. The above project is the Silverlight host site, and the following is the Silverlight application. After the host site is cleared, the site file generated by the viewer is copied. The application can delete both XAML files. After completing this step, set the website as a startup project, and set index.htm as the starting page. Run F5, And the OK site is displayed successfully.

2. Set the Silverlight program extension.

It is important to note that the viewer version must be the same as or higher than the ArcGIS API for Silverlight version used. The Silverlight extension created by the viewer cannot be added to the viewer.

First, add the Silverlight program to the host site. Do not check "add a test page to reference this control". If you do so, there will be two useless pages (it does not matter if you select this option, just delete the unnecessary pages ).

Add references to the Silverlight application.

The most important thing is the following two:

It is best to set the two dynamic libraries not to be copied to the local machine. Otherwise, a warning will be prompted when you add your extensions to the viewer, saying that the two DLL files are already packaged in the viewer. This is also a way to make the expansion package smaller.

After that, we can build our own extension tools!

 

3. Create a type (taking querytool as an example)

Querytool inherits from icommand and isupportsconfiguration. You can click "implementation interface" to generate required interfaces.

An extension tool generally has two classes. the CS class is the querytool mentioned above, but the querytool does not have a user interaction interface, so there must be a class to display. Generally, it is a XAML and can inherit any uielement.

The following is the function of the interface I have commented on:

Using system; using system. collections. generic; using system. io; using system. windows. input; using system. XML. LINQ; using ESRI. arcGIS. client. extensibility; namespace wcfsilverlight {public class querytool: icommand, isupportsconfiguration {// <summary> // query window interface for user interaction /// </Summary> querytoolwindow thequerytoolwindow = NULL; /// <summary> /// store the configured layer /// </Summary> Public dictionary <string, string> layersdic = new dictionary <string, string> (); /// <summary> /// method for determining whether the command can be executed /// </Summary> /// <Param name = "parameter"> parameter used for determining </ param> // <returns> </returns> Public bool canexecute (object parameter) {// whether return can be executed return true ;} /// <summary> /// whether the event with the modified value can be executed /// </Summary> public event eventhandler canexecutechanged; /// <summary> /// run the command /// </Summary> /// <Param name = "parameter"> the parameter passed by the command </param> Public void execute (object parameter) {This. thequerytoolwindow = new querytoolwindow (this); // display thequerytoolwindow as the interactive interface of the tool mapapplication. current. showwindow ("call WCF", this. thequerytoolwindow);} // <summary> // configure /// </Summary> Public void configure () {// configure the tool according to the configuration information} // <summary> // read the configuration information of the tool. the XML file contains /// </Summary> /// <Param name = "configdata"> label "tool. value in configdata </param> Public void loadconfiguration (string configdata) {// The author writes the configuration information into XML format, so this configuration is required, this operation can be avoided if a common string is used. You can directly use using (stringreader sr = new stringreader (configdata) {xdocument configdataxdocument = xdocument. load (SR); foreach (xelement layer in configdataxdocument. root. elements ("layer") {string url = layer. attribute ("url "). value; string id = layer. attribute ("ID "). value; layersdic. add (ID, URL );}}} /// <summary> /// Save the configuration file when you exit tools /// </Summary> /// <returns> </returns> Public String saveconfiguration () {// pass the configuration file to be saved as a string. For example, if you prefer to use xml configuration, you must convert it to a string return string. empty ;}}}

After this step is completed, we will not look at how to write classes in the interactive interface (if debugging fails, you can create a class named "querytoolwindow" XAML without any operation ), we first go to the host site and configure the tool to the site generated by the viewer.

 

4. configure tool

First, open config/application. xml and add a reference to xap in the node.

<Extensions>    <Extension Url="ClientBin/WCFSilverlight.xap" /></Extensions>

Configure tool reference in config/tools. xml

<Tools> <tool label = "query precipitation" icon = "images/toolbar/togglesearchcommand16.png" Description = "call WCF to query precipitation and generate a Topic Map"> <tool. class> <querytool xmlns = "CLR-namespace: wcfsilverlight; Assembly = wcfsilverlight"/> </tool. class> <tool. configdata> <queryconfig> <layer id = "point" url = "http: // localhost: 6080/ArcGIS/rest/services/centervalue/mapserver/0 "> </layer> </queryconfig> </tool. configdata> </tool> </tools>

We can see that the tool is added to the tools node. The tool has tool. Class nodes and tool. configdata nodes under the tool. The former is the class used by the configuration tool, in the format:

<Tool. Class> <class name xmlns = "CLR-namespace: namespace; Assembly = assembly"/> </tool. Class>

Some may ask: Do I need to add the Silverlight assembly to the host site above? The answer is no! Because in application. xap references are configured in XML. Therefore, the viewer of the viewer. xap will actually parse the referenced xap, And the xap generated by our extension tool itself has packaged and passed its own assembly. If you are interested, you can change the extension name of the xappackage to. Zip and then open it.

The tool. configdata label below can be filled with whatever you want. Here I use XML format to represent a layer and query configuration.

After the configuration is complete, run and check that the custom tool should appear in the tool bar on the right of the main form. Click it and try to see our own querytoolwindow?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.