Home > Uncategorized > Carmenta Engine 5, First contact

Carmenta Engine 5, First contact

The release of CE 5 is getting closer and just recently Carmenta Engine 5 RC 1 was announced. A lot of things have been reworked and improved – to say the least. As a first experiment I sat down and wrote a very basic “hello world” kind of application. Using the brand new WPF map control the user interface can be defined as simple as:

<Window x:Class="CE5TestApp.MainWindow"

       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;

       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;

       xmlns:local="clr-namespace:CE5TestApp"

       xmlns:cectrl="clr-namespace:Carmenta.Engine.Controls;assembly=CEControls.Dotnet"

       Title="MainWindow" Height="350" Width="525">  

    <Grid>

        <cectrl:MapControl View="{local:ViewFactory ConfigurationFile=testmap.px, ViewName=View0}"/>

    </Grid>

</Window>

 

The map control has a view property which is the only thing that must be set. The WPF sample in the documentation suggests, hooking up the Window.Loaded event and then setting the property from code. I am, however, more of a declarative programmer kind of guy so I wrote a MarkupExtension called ViewFactory that loads a configuration from file and retrieves the specified view. Here is the implemenation:

[MarkupExtensionReturnType(typeof(View))]

public class ViewFactory : MarkupExtension

{

    public string ConfigurationFile { get; set; }

 

    public string ViewName { get; set; }

 

    public override object ProvideValue(IServiceProvider serviceProvider)

    {

        if (!Runtime.IsInitialized)

            Runtime.Initialize();

 

        View result = null;

        if (ConfigurationFile != null && File.Exists(ConfigurationFile) && ViewName != null)

        {

            var config = new Configuration(ConfigurationFile);

            result = (View)config.GetPublicObject(ViewName);

        }

 

        return result;

    }

}

 

Nice. The only cloud on the sky was that I got this error message at first.

runtimeproblem 

It was easily fixed though, by adding the following snippet to the app.config:

<startup useLegacyV2RuntimeActivationPolicy="true">

  <supportedRuntime version="v4.0"/>

</startup>

 

The last thing I did was to add support for zooming and panning. Like before, this kind of map interaction, is handled by tools. The tool interface has been totally redesigned though; abstracting away low-level details. More over, instead of providing a flora of different tools a multi-tool called StandardTool is provided. I think this makes good sense. Well, lets get down to business and modify the application to use the standard tool. First we need to add a new namespace declaration to the xaml:

xmlns:ce="clr-namespace:Carmenta.Engine;assembly=CECore.Dotnet"

 

and then we simply set the tool property:

<cectrl:MapControl View="{local:ViewFactory ConfigurationFile=testmap.px, ViewName=View0}">

    <cectrl:MapControl.Tool>

        <ce:StandardTool/>

    </cectrl:MapControl.Tool>

</cectrl:MapControl>

 

All done. I am looking forward to try out more of CE5. It is clear that this is a major upgrade and that programming maps have become easier and more fun.

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: