javascript - Canvas 元素 + Javascript 在 Chrome 和 Firefox 中工作,而不在 Internet Explorer 中工作

标签 javascript google-chrome firefox html5-canvas leaflet

我正在使用传单的修改版本 FullCanvas Plugin在 map 上画线。这些线条在 Firefox 和 Chrome 上完美运行,但在 Internet Explorer(版本 11,我使用的是 Windows 8.1)上,这些线条在移动/缩放 map 时永远不会重置。我做了一个 fiddle 来说明问题:

http://jsfiddle.net/tee99z65/

尝试在 Chrome 或 Firefox 上拖动和缩放,然后在 Internet Explorer (11) 上。这段代码是怎么回事?每次需要重新绘制线条时调用的方法是 drawCanvas() :

drawCanvas: function () {
        var canvas = this.getCanvas();
        var ctx = canvas.getContext('2d');
        var me = this;
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        var bounds = this._myMap.getBounds();
        if (!this.options.filterPointsInBounds) bounds = new L.LatLngBounds([-90, -180], [90, 180]);
        var points = this._myQuad.retrieveInBounds(this.boundsToQuery(bounds));
        points.forEach(function (point) {
            var d = point.data;
            if (d.draw && !d.draw(d)) return;    // allows dynamic filtering of curves
            var spoint = me._myMap.latLngToContainerPoint(new L.LatLng(d.slat, d.slon));
            if (d.tlat && d.tlon) {
                var tpoint = me._myMap.latLngToContainerPoint(new L.LatLng(d.tlat, d.tlon));
                me.drawCurve(point, spoint, tpoint, d.style ? d.style(d) : null);
            }
        });
    },

有人知道这里发生了什么吗?修复会很好,但如果有人能指出为什么会发生这种情况,我就已经很高兴了,这样我就可以尝试自己修复了。

最佳答案

为什么?

因为鼠标滚轮事件还没有标准化。 (给浏览器制造商的注意事项:说真的!???,为什么你们还没有标准化鼠标滚轮事件。滚动鼠标已经存在多年了!——结束咆哮/)。

修复:

您必须在 IE 上监听 mousewheel 事件,而不是大多数其他浏览器监听的 DOMMouseScroll 事件。我不使用 leavlet,但这似乎是您需要添加修复程序的地方。

关于javascript - Canvas 元素 + Javascript 在 Chrome 和 Firefox 中工作,而不在 Internet Explorer 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27528867/

相关文章:

javascript - 在 Greasemonkey/Javascript 中激活 Firefox 选项卡?这可能吗?

html - 我可以在 <a> 标签内添加图像 map 区域吗?

javascript - 通过Jquery查找表中没有复选框的所有行

javascript - Intellij 插件 : AirBnB ESLint w/React

javascript - 未捕获引用错误 : camera is not defined

web-applications - 用于 Intranet 应用程序的 Chrome 或 Firefox(或与浏览器无关)?

firefox - 如何制作在 Firefox session 中使用的 cookie?

javascript - 将图表从道场图表导出/转换为图像

javascript - 无法在 Chrome 中加载资源 + $.ajax 调用

google-chrome - Chrome 扩展已下架。你是如何进行的?