Cesium embeded into a C# Winform or WPF application?

2,088 views
Skip to first unread message

David Taylor

unread,
Jul 28, 2014, 1:28:38 PM7/28/14
to cesiu...@googlegroups.com
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?



Matthew Amato

unread,
Jul 31, 2014, 11:12:23 PM7/31/14
to cesiu...@googlegroups.com
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 '<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">' 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.

David

unread,
Jul 31, 2014, 11:14:18 PM7/31/14
to cesiu...@googlegroups.com
THANK YOU! thats a great solution I'll try it out tomorrow.


--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/snCQbClHfE4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted
Message has been deleted

David Taylor

unread,
Aug 21, 2014, 3:12:25 PM8/21/14
to cesiu...@googlegroups.com
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?
To unsubscribe from this group and all its topics, send an email to cesium-dev+unsubscribe@googlegroups.com.

Willem

unread,
Jan 21, 2015, 9:00:27 AM1/21/15
to cesiu...@googlegroups.com
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 

debr...@gmail.com

unread,
Mar 14, 2015, 4:36:07 PM3/14/15
to cesiu...@googlegroups.com
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?

Matthew Amato

unread,
Mar 14, 2015, 10:04:16 PM3/14/15
to cesiu...@googlegroups.com
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.


--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

Matthew Amato

unread,
Mar 17, 2015, 1:13:45 PM3/17/15
to cesiu...@googlegroups.com
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).
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+unsubscribe@googlegroups.com.

Dan Bracey

unread,
Mar 17, 2015, 11:52:58 PM3/17/15
to cesiu...@googlegroups.com
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.

--
Dan Bracey

--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/snCQbClHfE4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.

Matthew Amato

unread,
Mar 18, 2015, 10:44:27 AM3/18/15
to cesiu...@googlegroups.com
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.

To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

Willem van der Gugten

unread,
Aug 12, 2015, 8:48:32 AM8/12/15
to cesium-dev
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


On Wednesday, March 18, 2015 at 3:44:27 PM UTC+1, Matthew Amato wrote:
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.
On Tue, Mar 17, 2015 at 11:52 PM, Dan Bracey <debr...@gmail.com> wrote:
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.

--
Dan Bracey

On Tue, Mar 17, 2015 at 1:13 PM, Matthew Amato <matt....@gmail.com> wrote:
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).


On Saturday, March 14, 2015 at 10:04:16 PM UTC-4, Matthew Amato wrote:
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.
On Sat, Mar 14, 2015 at 4:36 PM, <debr...@gmail.com> wrote:
On Wednesday, January 21, 2015 at 9:00:27 AM UTC-5, Willem wrote:
> 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?

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/snCQbClHfE4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Willem van der Gugten

unread,
Aug 14, 2015, 8:56:55 AM8/14/15
to cesium-dev
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
Reply all
Reply to author
Forward
0 new messages