91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

用canvas畫出一個路線圖的方法

發布時間:2020-09-28 14:20:48 來源:億速云 閱讀:333 作者:小新 欄目:web開發

這篇文章主要介紹了用canvas畫出一個路線圖的方法,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。

<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta content="always" name="referrer">
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0" name="viewport" />
    <title>CITEK反向尋車</title>
    <script src="<%=basePath%>wui/js/jquery.js"></script>
    <link rel="stylesheet" href="<%=cssPath%>wui.css" type="text/css"></link>
    <script type="text/javascript" src="<%=basePath%>wui/js/line_tool.js"></script>
    <script type="text/javascript">
var arrPosX = [], arrPosY = [];
        <s:iterator value="listNode" status="bean">          //設置路線中點的橫坐標和縱坐標的集合
            arrPosX.push(<s:property value="posX" />);
            arrPosY.push(<s:property value="posY" />);
        </s:iterator>
        var arrRoundPosX = [], arrRoundPosY = [];          //設置終點所在區域的范圍點橫坐標和縱坐標集合
        <s:iterator value="positionsX" status="bean">
            arrRoundPosX.push(<s:property />);
        </s:iterator>
        <s:iterator value="positionsY" status="bean">
            arrRoundPosY.push(<s:property />);
        </s:iterator>

        var ctxBackground, canvasBackground;
           var ctxSource, canvasSource;
        var canvasWidth, canvasHeight;
        
        var imgStart, imgEnd, imgBackground,;
        var areaImage;
        var isStart = false;
        
        var scale = 1;
        var scaleInterval = 3;
        var scaleCount = 0;
        var runCount = 0;
        var step = 2;    //像素
        var moveX = 1;
        var moveY = 1;
        var currIndex = 0;
        var a = 0;
        var tmpIconPaths = [                                                         //設置起點圖標
            "<%=basePath%>img/point_start.png", 
        ];
        var imgObjArr = [];
        var iLoadIndex = 0;
        
        /**
         * 將圖標放入集合中
         */
        function loadIconImages(){
            var oImg = new Image();
            oImg.addEventListener('load', eventIconImagesLoaded, false);
            oImg.src = tmpIconPaths[iLoadIndex];
            imgObjArr.push(oImg);
        }
        
        /**
         * 加載圖標
         */
        function eventIconImagesLoaded(){
            iLoadIndex++;
            if(iLoadIndex <= 3) {
                loadIconImages();
            } else {
                loadImage();
            }
        }
        
        /**
         * 加載背景圖標
         */
        function loadImage(){
               areaImage = new Image();
               areaImage.addEventListener('load', eventAreaImageLoaded, false);
               areaImage.src ="<%=basePath%>image/img.jpg;
        }
        
        function eventAreaImageLoaded(){
            initBase();
            initScene();
            initSprits();
            start();
            isStart = true;
        }
        
        /**
         * 初始化
         */
        function initBase() {
            imgStart = imgObjArr[0];
    
            canvasBackground = document.getElementById("canvasBackground");
            ctxBackground = canvasBackground.getContext("2d");
    
            canvasSource = document.getElementById("canvasSource");
            ctxSource = canvasSource.getContext("2d");
            
            canvasWidth = areaImage.width;
            canvasHeight = areaImage.height;
            
            var bodyWidth = document.body.clientWidth-10;
            var bodyHeight = document.body.clientHeight-10;
            var tmpCavW = canvasWidth;
            var tmpCavH = canvasHeight;
            
            if(canvasWidth > bodyWidth)    {
                canvasWidth = bodyWidth;
                canvasHeight = canvasWidth * (tmpCavH/tmpCavW);
            }
            if(canvasHeight > bodyHeight){
                canvasHeight = bodyHeight;
                canvasWidth = canvasHeight * (tmpCavW/tmpCavH);
            }
            canvasBackground.width = canvasWidth;
            canvasBackground.height = canvasHeight;
            
            canvasSource.width = canvasWidth;
            canvasSource.height = canvasHeight;
            moveX = arrPosX[0] * canvasWidth;
            moveY = arrPosY[0] * canvasHeight;
            
        }
        
        /**
         * 初始化畫布
         */
        function initScene() {
            ctxBackground.drawImage(areaImage, 0, 0, canvasWidth, canvasHeight);
        }
        
        /**
         * 開始繪圖
         */
        function initSprits() {
            /* 繪制路線的白底 */
             ctxBackground.beginPath();
             ctxBackground.strokeStyle = "white";
               ctxBackground.lineWidth = 8;
               ctxBackground.lineCap = "round";
               ctxBackground.lineJoin = "miter";
               ctxBackground.miterLimit = 30;
               for(var i=1; i < arrPosX.length; i++){
                   ctxBackground.moveTo(canvasWidth * arrPosX[i-1], canvasHeight * arrPosY[i-1]);   //指定一條線段的起點   
                   ctxBackground.lineTo(canvasWidth * arrPosX[i],     canvasHeight * arrPosY[i]);     //指定一條線段的終點   
             }  
             ctxBackground.stroke();
              /* 繪制路線的紅線 */
             ctxBackground.beginPath();                                             //是通過覆蓋白底實現的
               ctxBackground.strokeStyle = "rgba(255,0,0,1)";
               ctxBackground.lineWidth = 4;
               ctxBackground.lineCap = "round";
               ctxBackground.lineJoin = "miter";
               ctxBackground.miterLimit = 30;
               for(var i=1; i < arrPosX.length; i++){
                   ctxBackground.moveTo(canvasWidth * arrPosX[i-1], canvasHeight * arrPosY[i-1]);   //指定一條線段的起點   
                 ctxBackground.lineTo(canvasWidth * arrPosX[i],     canvasHeight * arrPosY[i]);     //指定一條線段的終點   
             }  
             ctxBackground.stroke();
             
            /* 繪制終點區域 */                                                                                     
            ctxSource.clearRect(0, 0, canvasWidth,canvasHeight);
            ctxBackground.beginPath();
            ctxBackground.strokeStyle = "rgba(255,0,0,1)";   //顏色
            ctxBackground.lineWidth = 0.5;
            ctxBackground.fillStyle = "rgba(255,0,0,0)";   //透明度
               ctxBackground.moveTo(canvasWidth * arrRoundPosX[0], canvasHeight * arrRoundPosY[0]);   //指定一條線段的起點   
             for(var i=1; i < arrRoundPosX.length; i++){
                 ctxBackground.lineTo(canvasWidth * arrRoundPosX[i],     canvasHeight * arrRoundPosY[i]);     //指定一條線段的終點 
             }   
            ctxBackground.lineTo(canvasWidth * arrRoundPosX[0],     canvasHeight * arrRoundPosY[0]);  
            ctxBackground.closePath();
            ctxBackground.fill();
            ctxBackground.stroke();

             /* 繪制起點圖標 */
            ctxBackground.drawImage(
                    imgStart, 
                    canvasWidth * arrPosX[0] - imgStart.width * 0.25, 
                    canvasHeight * arrPosY[0] - imgStart.height * 0.25 - imgStart.height * 0.25, 
                    imgStart.width * 0.5, 
                    imgStart.height * 0.5);
        }
        
        /**
         * 設置圖標的跳動
         */
        function loop(){
            if(!isStart) return;
            if(scale > 1.8) scale = 1;
            if(scaleCount > 999999) scaleCount = 0;
            if(runCount > 999999) runCount = 0;
            ctxSource.save();
            ctxSource.clearRect(0,0,canvasWidth,canvasHeight);
            /* 設置起點圖標的跳動 */
            ctxSource.translate(
                    canvasWidth * arrPosX[0] - imgStart.width * 0.25 +imgStart.width*0.25,
                    canvasHeight * arrPosY[0] - imgStart.height * 0.25+imgStart.height*0.25);
            ctxSource.scale(scale, scale);
            ctxSource.shadowOffsetX = 3; // 陰影x軸偏移
            ctxSource.shadowOffsetY = 4; // 陰影y軸偏移
            ctxSource.shadowBlur = 2; // 模糊尺寸
            ctxSource.shadowColor = 'rgba(0, 0, 0, 0.5)'; // 顏色    
            ctxSource.drawImage(
                    imgStart, 
                    - imgStart.width * 0.25, 
                    - imgStart.height * 0.25 - imgStart.height * 0.25, 
                    imgStart.width * 0.5, 
                    imgStart.height * 0.5);
            ctxSource.restore();
            ctxSource.save();
            
            
            /* 設置終點區域的透明度變化 */
            if (runCount % 4 == 0) {
                 a = a + 0.1;
            }
            if (a > 0.6) {
                a = 0;
            }
            ctxSource.strokeStyle = "rgba(255,0,0,1)";
            ctxSource.lineWidth = 10;
            ctxSource.fillStyle = "rgba(255,0,0,"+a+")";
               ctxSource.moveTo(canvasWidth * arrRoundPosX[0], canvasHeight * arrRoundPosY[0]);   //指定一條線段的起點   
             for(var i=1; i < arrRoundPosX.length; i++){
                 ctxSource.lineTo(canvasWidth * arrRoundPosX[i],     canvasHeight * arrRoundPosY[i]);     //指定一條線段的終點   
             }   
            ctxSource.lineTo(canvasWidth * arrRoundPosX[0],     canvasHeight * arrRoundPosY[0]);  
            ctxSource.closePath();
            ctxSource.fill();
            ctxSource.restore();
            ctxSource.save();
            
        
            scaleCount++;
            runCount++;
            if(scaleCount % scaleInterval == 0){
                scale += 0.1;
            }
        }
        
        /**
         * 設置標題和圖片的長寬高和跳動頻率
         */
        function start(){
            $("#monitor_list_box").width = canvasWidth + "px";
            $("#monitor_list_box").height = canvasHeight + "px";
            $("#canvasBackground").width = canvasWidth + "px";
            $("#canvasBackground").height = canvasHeight + "px";
            $("#canvasSource").width = canvasWidth + "px";
            $("#canvasSource").height = canvasHeight + "px";
            window.setInterval(loop,1000/30);    //60幀
        }
        
  </script>
  <style type="text/css">
        #monitor_list_box {width:100%; height:auto; overflow: auto;}
        #monitor_list_box canvas {position:absolute;width:100%; height:auto;}
 </style>
<body>
<div id="monitor_list_box">
        <canvas id="canvasBackground">
            Your browser does not support the canvas element.
        </canvas>
        <canvas id="canvasSource">
            Your browser does not support the canvas element.
        </canvas>
    </div>
</body>

感謝你能夠認真閱讀完這篇文章,希望小編分享用canvas畫出一個路線圖的方法內容對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,遇到問題就找億速云,詳細的解決方法等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

宝鸡市| 凭祥市| 海安县| 乡宁县| 沂源县| 庄浪县| 望谟县| 嘉义县| 民乐县| 开远市| 义马市| 辽中县| 蓝田县| 湖北省| 阿城市| 当雄县| 封开县| 怀仁县| 富顺县| 观塘区| 常山县| 博罗县| 鲁甸县| 柘城县| 左贡县| 都匀市| 河东区| 集贤县| 安庆市| 界首市| 定远县| 通榆县| 东莞市| 宁明县| 孝昌县| 高唐县| 黄浦区| 孙吴县| 万源市| 东乌珠穆沁旗| 土默特左旗|