Esri Silverlight Bezier Curve Rendering

Esri Silverlight API graphics samples have some well explained examples for rendering basic graphic objects. It is possible to define graphics symbols both using xaml and code(c#).

I will explain how to render a bezier curve using esri simple renderer with a xaml. First of all, add your silverlight project a resources.xaml. It should contain a resource dictionary that will define the behaviour of the renderer for our graphicslayer object. An example resource.xaml  :

In the resources.xaml file there are some bindings that may take your attention. For example the Fill property of the symbol is bound to Color attribute. I will initialize this attribute with a SolidColorBrush while constructing Graphic object. Than I will add the Graphic object to graphics layer.

Initialize graphicslayer with the resource dictionary and add it to map’s Layers:

Now our graphics layer is ready to render a Bezier curve. We just need to apply the bezier formula to our map points and obtain a Polyline object.

In my case I have two MapPoints ( P0 and P2) and need to draw a curve between them. It is obvious that I need one more intermediate point to apply bezier formula. I generated an intermediate point whose coordinates have equal distances from my initial points and a little away from the straight line between the initial points. The generated intermediate point,  P1, and the midpoint between the initial points forms a 2D vector which is orthogonal to the vector<p0,p2>.Now I will use the Quadratic Bézier curves formula which is explained here.

The polyline object created above contains an array of PointCollections. Each PointCollection object containts two points. First one is the end point of previous PointCollection and second one is the end point for the current PointCollection. The second point will be used in the loop as a start point for the next PointCollection.

It is time to create a Graphic object and give it to a predefined GraphicsLayer of the map to render.

That’s all. Our bezier curve should just appear on the map.

References:

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm

http://en.wikipedia.org/wiki/B%C3%A9zier_curve

Modifying web.config file – Web setup project

In my previous post I talked about how to open a web setup project and add custom actions and user interfaces to it. Now I will give some examples of how to modify the web.config file that is copied in the virtual directory by our installer.

Most setups need to change the content of the web.config file for many reasons such as target machine properties, link updates etc. Setups may also require additional information from user to update the web.config accordingly.

For gathering input from user, there are several ways:

  • Using Web Setup Project’s User Interfaces

If a few text boxes are enough for you, the provided User Interfaces will satisfy your needs. You can pass the user entered parameters to your installer class.(Explained in previous post)

‘targetdir’ parameter keeps the web.config file path.

An important note: You should not try to modify the web.config during installation process. Use the AfterInstall event handler to make your updates.

  • Creating Your Own Forms Applciation

You can create a windows forms project and run it as a process at AfterInstall event handler.

run executable

To do this, you need to add the project output of the forms application you created to the web setup. After doing this, web setup will copy your executable to the target directory and you will be able to run it there.

The forms application can modify the web.config anyway you like.

  • ASP.Net configuration
If your web application is a asp.net application, then you can easily modify the web.config from the application itself. Prepare a web.config modification page and at codebehind update the web.config file like that:
The example code updates the AppSetting part of the web.config with the given key. But you can modify any section of the config file. See: more ways
Taylan

Visual Studio Web Setup Project

Web setup project is simply a visual studio setup project that helps web projects to be installed on a target machine’s IIS. Setup project and Web Setup project templates are available in Visual Studio.

open web setup project

     After you open a web setup project. Click on the project on solution explorer and press f4. Title of installer, icon, version, manufacter etc. can be set here.

properties window

     Since we are creating a web setup, we should have web project that is going to be published under IIS. Add an existing web project of yours in the web setup solution. After that right click on the web setup project Add->Project Output. In the pop-up dialog select your web project from the combo box at the top and select both ‘Primary Output’ and ‘Content Files’ in the list box. Note that only the dlls that are referenced by your web project will be copied into virtual directory.

Other dlls in your bin directory that are copied by a postbuid event or a manual copy/paste, will not be available in the VirtualDirectory/bin folder. A quick solution is to add reference to these dlls in your web project so that they will be recognized by web setup project as dependency and copied to target virtual directory.

add project output

User Interface :

Right click on the project on solution explorer and navigate to View->User Interace.

There are some template dialogs you can add to your installer. Right click on the Start and click Add Dialog.

Choose the template that fits your purpose and begin to edit the dialog through Properties window.

Set visibility of fields to false that are not needed. Edit#Property is the variable that is assigned with user’s input. We are going to use these values in next part.

dialog properties window

this configuration will look like that

text box dialog example

Custom Actions:

Custom actions are user defined executables, dlls or scripts which run by installer.  I will show a C# example custom action.

Right click on the solution and Add -> New Project -> Class Library. You can add an existing project too.

We need to have reference to System.Configuration.dll & System.Configuration.Install.dll. Now you can create your own Installer class and play with it.  Inherit Installer class and don’t forget the RunInstaller attribute.

Installer class example

     Now we need to add the project output to the setup project. Right click on the setup project Add -> Project Output. Select the Class library project and select Primary Output then click OK.

To add this class library project as a custom action to our web setup project. Right click on setup project View->CustomActions then Add Custom Action to Install. And press f4 after adding the custom action. You will see something like:

custom action properties

     We have a installer class and we need user inputs in that class. To provide these parameters write your parameters in the Custom Action Box above. In my case it is :

/targetdir=”[TARGETDIR]\” /targetvdir=”[TARGETVDIR]” /targetsite=”[TARGETSITE]” /sql=”[SQL_SERVERNAME]” /sqldbname=”[SQL_DB_NAME]” /sqluser=”[SQL_USERNAME]” /sqlpw=”[SQL_PASSWORD]” /

Retrieve these in your installer class :

retrieve parameters in custom action

That is a brief introduction to web setup projects.  I will talk about specific problems I encountered in my next posts.

Taylan