简体   繁体   中英

ol3 with IE11 in a c# webbrowser control mouse click events not working

I've "upgraded" to IE 11 for the browser inside ac# application using the webbrowser control.

When I load my web page into the IE 11 browser natively everything works properly on the map.

When I'm in the c# application everything loads without error except that I can not click on the map and drag it.

All of my map click events will also not fire.

I can use the arrow keys to move the map, and the wheel mouse also works.

I have noticed that when I use IE 11 natively, and use the developer tools with "Break on all exceptions", I get an error in ol3 when its checking if PointerEvent.HAS_BUTTONS is supported, saying Object doesn't support this action.

error is on line 44619 of ol-debug.js, using ol-3.4.0

Note: Yes, I've set the proper registry values for the browser_emulation for both the 32 bit and 64 bit keys for my application name, and the one for the vhost.exe version of the application.

UPDATE :

I should also note that if I use

map.on('click', function(e) { 
    //do stuff
    });

there is nothing fired... However, if I use jquery and do

$(map.getViewport().on('click', function(e) {
//do stuff
});

... then my click events work....

I know this is a bit of a late post, but hopefully it might help others if they stumble across it.

I was in exactly the same boat: using a WebBrowser control with compatibility set to IE11 was causing OpenLayers 3 to ignore mouse button clicks when displaying 2D maps. I tried CefSharp 3, and sure enough it resolves the problem, but there are other reasons why that can't be used for me. After lots of trial and error, I stumbled across this as a workable solution:

    <meta http-equiv="X-UA-Compatible" content="IE=11" />
    <script>
        if (navigator.appVersion.indexOf("MSIE 7.") !== -1)
        {
            delete window.PointerEvent;
            window.navigator.msPointerEnabled = false;
        }
    </script>

This needs to be on the page before the inclusion of ol.js.

It's a crude test of whether the page is running in a WebBrowser control admittedly, but should suffice now that IE7 is no longer supported. The only real instance of "MSIE 7." in the user agent string will be from a default WebBrowser control.

I've not found any other OpenLayers problems as yet.

So, I decided to roll back to IE10. Everything works in both the native browser and in the WebBrowser control.

IE11 breaks too much stuff, and isn't worth the "upgrade" at this point in time.

I will be checking out CefSharp in the future, just not enough time to put into upcoming release.

I was in the same situation than you a few months ago. The non working mouse events, are just the first symptom. I strongly recommend you to use Chromium for that, because at the end, you are not using an IE11 (Webbrowser control is based on a IE9 kernel), and you just can influence "a bit" how it works, BUT: if you have a complex problem you have no way to really update your browser, to debug, etc. Chromium works really fine and you can embed it completely in your solution, star it separately to debug or test, and it's based on a modern chrome. To integrate it on a .net solution, you can use:

https://github.com/cefsharp/CefSharp

Regards

The problem is related to the legacy input model, which is enabled by default for WebBrowser Controls hosted by an application.

To get your OpenLayers3 application working you have to disable it in the registry. To do this you have to set FEATURE_NINPUT_LEGACYMODE to 0 for your application. If this key doesn't exist in your FeatureControl branch, you have to create it manually.

For more information about the legacy input model read this .

I had a lot of issues with ol3 / WebBrowser in winforms, like a lot of features not working well; After I added this in the HTML header, it was perfect :

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM