简体   繁体   English

在Chrome和Firefox中可以使用Canvas元素+ Javascript,而不能在Internet Explorer中使用

[英]Canvas element + Javascript working in Chrome and Firefox, not in Internet Explorer

I am using a modified version of the Leaflet FullCanvas Plugin to draw lines on a map. 我正在使用Leaflet FullCanvas插件的修改版本在地图上绘制线条。 These lines work perfectly find on Firefox and Chrome, but on Internet Explorer (version 11, I'm using Windows 8.1) these lines never get reset when moving/zooming the map. 这些行在Firefox和Chrome上可以完美地找到,但是在Internet Explorer(版本11,我使用的是Windows 8.1)上,这些行在移动/缩放地图时不会被重置。 I made a Fiddle to illustrate the problem: 我做了一个小提琴来说明这个问题:

http://jsfiddle.net/tee99z65/ http://jsfiddle.net/tee99z65/

Try dragging and zooming while on Chrome or Firefox, and then Internet Explorer (11). 在Chrome或Firefox上,然后在Internet Explorer(11)上,尝试拖动和缩放。 What is going on in this code? 此代码中发生了什么? The method that gets called every time the lines need to be redrawn is drawCanvas() : 每次需要重画线时调用的方法是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);
            }
        });
    },

Does anyone have any idea what's going on here? 有人知道这里发生了什么吗? A fix would be nice, but I'm already happy if anyone can point out why this is happening so I can attempt a fix myself. 一个修复程序会很不错,但是如果有人能指出为什么会这样,那么我已经很高兴了,因此我可以自己尝试修复。

Why? 为什么?

Because mousewheel events are not yet standardized. 因为鼠标滚轮事件尚未标准化。 (Note to browser makers: Seriously!??? , why have you not standardized the mousewheel event yet. Scrolling mice have been around for years! -- end of rant/ ). (致浏览器制造商的注意: 认真!??? ,为什么还没有对mousewheel事件进行标准化。滚动鼠标已经存在了很多年!-rant /结束)。

Fix: 固定:

You will have to listen for the mousewheel event on IE instead of the DOMMouseScroll event that most other browsers listen for. 你将不得不监听mousewheel上的IE事件,而不是DOMMouseScroll大多数其他浏览器监听事件。 I don't work with leavlet, but that appears to be where you need to add the fix. 我不使用leavlet,但这似乎是您需要添加修复程序的地方。

Problem solved: 问题解决了:

http://jsfiddle.net/tee99z65/3/ http://jsfiddle.net/tee99z65/3/

The function that draws the curve, drawCurve(), has been edited from: 绘制曲线的函数drawCurve()已从以下编辑:

ctx.moveTo(startPoint.x, startPoint.y);
ctx.quadraticCurveTo(px, py, endPoint.x, endPoint.y);
ctx.stroke();

To: 至:

 ctx.beginPath();
 ctx.moveTo(startPoint.x, startPoint.y);
 ctx.quadraticCurveTo(px, py, endPoint.x, endPoint.y);
 ctx.stroke();
 ctx.closePath();

Lesson learned: never forget about beginPath() and closePath(). 经验教训:永远不要忘记beginPath()和closePath()。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 包含外部HTML的JavaScript在Chrome中运行,但在Internet Explorer和Firefox中不起作用 - JavaScript to include external HTML is working in Chrome but not in Internet Explorer and Firefox 为什么这在fireFox中有效,但在Chrome或Internet Explorer 9中却无效? - Why is this working in fireFox but not in Chrome or Internet Explorer 9? 元标记中的javascript在Firefox和Internet Explorer上不起作用 - javascript in meta tag not working on firefox and internet explorer Javascript代码段无法在Chrome中运行,但可在Internet Explorer中使用 - Javascript snippet not working in Chrome, but works in Internet Explorer javascript脚本可在Firefox,Chrome,Safari,Internet Explorer &lt;9,而不是IE 9中运行 - javascript script works in Firefox, Chrome, Safari, Internet Explorer < 9, but not in IE 9 Flot图在Firefox或Internet Explorer中无效,仅适用于Chrome - Flot graph not working in Firefox or Internet Explorer, only Chrome 插入Javascript的元素在Firefox和Chrome中显示/更新,但在Internet Explorer 8中不显示/更新 - Javascript inserted elements appear/update in Firefox & Chrome, but not Internet Explorer 8 Javascript打印弹出窗口适用于Firefox / Chrome但不适用于Internet Explorer - Javascript printing a popup window works in Firefox/Chrome but not Internet Explorer 登录代码无法在Internet Explorer中使用,但可以在Chrome和Firefox中使用 - Sign-in code not working in Internet Explorer but yes in Chrome and Firefox selectedOptions.length在Internet Explorer中不起作用,但在chrome和firefox中可以正常工作吗? - selectedOptions.length not working in Internet explorer but works properly in chrome and firefox?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM