Cesium embeded into a C# Winform or WPF application?

I am wondering if its possible to embed Cesium into a winform or wpf application similar to what is done with Google Earth plugin and Bing Maps 3D.

This is the method I have used for Google Earth

public GEForm()

    {

        InitializeComponent();

        if (!this.DesignMode)

        {

             using (StreamReader sr = new

StreamReader(

             Assembly.GetExecutingAssembly().

             GetManifestResourceStream("GEForm.Resources.GE.html")))

            {

                string html =

sr.ReadToEnd();

webBrowser1.DocumentText = html;

            }

webBrowser1.ObjectForScripting = this;

        }

    }

then I execute a function within the html file using

webBrowser1.Document.InvokeScript(“Functionx”, new object

        { arg1, arg2,

arg3 });

Is something like this possible with cesium? using gecko or webkit or some compatible c# web browser?

I’ve been struggling with this question for a while (out of pure technical curiosity more than immediate need). I finally made a big breakthrough tonight.

If you are on Windows and can depend on IE 11, than by far the easiest way to do this is to use the built in WebBrowser control which is available in WinForms, WPF, C++, and any other language that can use ActiveX. The only drawback I kept running into was that performance was unusably slow when embedding IE this way. Finally, I ran across Internet Feature Controls, which are registry keys for controlling how embedded IE works in your application: http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx. Essentially you add your executable name to the registry and request that GPU acceleration be turned on for your app. This is trivial to do in WPF or Winforms

For WPF, put the below code in your App constructor before anything else runs.

using (var software = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(“Software”))

using (var microsoft = software.OpenSubKey(“Microsoft”))

using (var internetExplorer = microsoft.OpenSubKey(“Internet Explorer”))

using (var main = internetExplorer.OpenSubKey(“Main”))

using (var featureControl = main.OpenSubKey(“FeatureControl”, true))

{

using (var gpu = featureControl.CreateSubKey("FEATURE_GPU_RENDERING"))

{

    gpu.SetValue(Path.GetFileName(Application.ExecutablePath), 1, Microsoft.Win32.RegistryValueKind.DWord);

}

}

Now you can drop in the standard WebBrowser control and it will serve up accelerate WebGL.

One last note is that normally embedded IE runs as IE 7, but if you add ‘’ to your index.html header, it will automatically put it into “newest IE” mode (which is currently 11).

I’ll probably put together a blog post in the near future that tries to lay out some of the options for embedding Cesium (or any WebGL content) in thick clients. Other projects exist (such as Chromium Embedded Framework, Qt, Node-WebKit, etc…) and they each have their pros and cons; but I’ve had the most success with IE 11 so far.

THANK YOU! thats a great solution I’ll try it out tomorrow.

This method makes cesium usable in a winform or wpf, but it is still extremely slow when zoomed to street level. any other possible solutions?

With the information here, I have been able to create a basic C# WPF application with a WebBrowser control (IE11).

If I navigate to cesiumjs.org/Cesium/Apps/HelloWorld.html or to my local Apps/HelloWorld.html the page loads, but I cannot pan with the mouse (Left click + drag). The mouse wheel does work for zooming, and other interactions with the page work as well.

Is there a setting that I miss somewhere?

Thanks, Willem

I'm having this same problem -- control loads up -- can zoom, but can't pan. Were you ever able to make any headway on it?

I took a quick look at this and it’s an easy fix. Apparently while the PointerEvent class exists in the WebBrowser control, it doesn’t actually work and you need to fallback to using traditional mouse events. I’ll have a PR with the fix opened up on Monday and I’ll update this email with a link when it’s ready.

I just opened this pull request to address the issue: https://github.com/AnalyticalGraphicsInc/cesium/pull/2585 It will ship in Cesium 1.8, but it should be easy to backport yourself if you want to use it with 1.7.1 (or just switch to master once it’s merged).

In order to backport this to 1.7.1 I’d have to compile it from the source, correct?

I picked through the compiled items in the build directory and didn’t see any of those JS files.

Yes, you’d have to build from source. Of course if you were going to do that, it may be easier to just temporarily switch to the master branch instead of backporting and then update to 1.8 when it comes out on April 1st.

A question that might be related to this PointerEvent issue.

We have Cesium in a C# WPF application with a WebBrowser control (IE11). For some reason I cannot zoom, tilt or rotate using the touch screen. Dragging with one finger does work, so it seems to be related to two-finger touch handling.

In a stand-alone IE11 browser all touches works fine. I logged some information but the only difference I see is that window.navigator.pointerEnabled is false in the WebBrowser Control and true in the stand-alone browser:

+++ Info: Cesium.FeatureDetection.internetExplorerVersion(): 11,0

+++ Info: Cesium.FeatureDetection.supportsPointerEvents(): false

+++ Info: window.PointerEvent defined: true

+++ Info: window.navigator.pointerEnabled defined: true

+++ Info: window.navigator.pointerEnabled value: false

Any ideas on how to fix this, or how to debug?

Thanks, Willem

To answer my own question: there is a registry setting to override the use of the “legacy input model” by default for the WebBrowser Control in windows 8. See https://msdn.microsoft.com/library/ee330732(v=vs.85).aspx#legacy_input .
After setting FEATURE_NINPUT_LEGACYMODE to 0,all works fine (window.navigator.pointerEnabled is TRUE).

Thanks, Willem