캔버스를 사용하여 로드맵을 그리는 방법(코드)
이 글의 내용은 캔버스를 사용하여 로드맵(코드)을 그리는 방법에 대한 것입니다. 필요한 친구들이 참고할 수 있기를 바랍니다.
<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>
관련 추천 :
HTML5 캔버스 - paths_html5 튜토리얼 스킬을 활용한 선 그리기 예제
HTML5 간단한 온라인 그리기 도구 구현 세부 사항 사례
위 내용은 캔버스를 사용하여 로드맵을 그리는 방법(코드)의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











H5 프로젝트를 실행하려면 다음 단계가 필요합니다. Web Server, Node.js, 개발 도구 등과 같은 필요한 도구 설치. 개발 환경 구축, 프로젝트 폴더 작성, 프로젝트 초기화 및 코드 작성. 개발 서버를 시작하고 명령 줄을 사용하여 명령을 실행하십시오. 브라우저에서 프로젝트를 미리보고 개발 서버 URL을 입력하십시오. 프로젝트 게시, 코드 최적화, 프로젝트 배포 및 웹 서버 구성을 설정하십시오.

H5 Page 프로덕션은 HTML5, CSS3 및 JavaScript와 같은 기술을 사용하여 크로스 플랫폼 호환 웹 페이지의 생성을 말합니다. 핵심은 브라우저의 구문 분석 코드, 렌더링 구조, 스타일 및 대화식 기능에 있습니다. 일반적인 기술에는 애니메이션 효과, 반응 형 디자인 및 데이터 상호 작용이 포함됩니다. 오류를 피하려면 개발자를 디버깅해야합니다. 성능 최적화 및 모범 사례에는 이미지 형식 최적화, 요청 감소 및 코드 사양 등이 포함됩니다. 로딩 속도 및 코드 품질을 향상시킵니다.

H5 클릭 아이콘을 생성하는 단계에는 다음이 포함됩니다. 이미지 편집 소프트웨어에서 정사각형 소스 이미지 준비. H5 편집기에 상호 작용을 추가하고 클릭 이벤트를 설정하십시오. 전체 아이콘을 덮는 핫스팟을 만듭니다. 페이지로 점프하거나 애니메이션 트리거링과 같은 클릭 이벤트의 동작을 설정하십시오. h5 문서를 HTML, CSS 및 JavaScript 파일로 내보내십시오. 내보내는 파일을 웹 사이트 또는 기타 플랫폼에 배포하십시오.

h5referstohtml5, apivotaltechnologyinwebdevelopment.1) html5introducesnewelements 및 dynamicwebapplications.2) itsupp ortsmultimediawithoutplugins, enovannangeserexperienceacrossdevices.3) SemanticLementsImproveContentsTructUreAndSeo.4) H5'Srespo

H5 (HTML5)는 마케팅 캠페인 페이지, 제품 디스플레이 페이지 및 기업 프로모션 마이크로 웨스 사이트와 같은 가벼운 응용 프로그램에 적합합니다. 그것의 장점은 교차 성형 및 풍부한 상호 작용에있어 있지만, 그 한계는 복잡한 상호 작용 및 애니메이션, 로컬 리소스 액세스 및 오프라인 기능에 있습니다.

예, H5 페이지 제작은 HTML, CSS 및 JavaScript와 같은 핵심 기술을 포함하는 프론트 엔드 개발을위한 중요한 구현 방법입니다. 개발자는 & lt; canvas & gt; 그래픽을 그리거나 상호 작용 동작을 제어하기 위해 JavaScript를 사용하는 태그.

H5는 독립형 프로그래밍 언어가 아니라 최신 웹 애플리케이션을 구축하기위한 HTML5, CSS3 및 JavaScript 모음입니다. 1. HTML5는 웹 페이지 구조와 컨텐츠를 정의하고 새로운 태그와 API를 제공합니다. 2. CSS3은 스타일과 레이아웃을 제어하고 애니메이션과 같은 새로운 기능을 소개합니다. 3. JavaScript는 동적 상호 작용을 구현하고 DOM 작업 및 비동기 요청을 통해 기능을 향상시킵니다.

H5 팝업 창 생성 단계 : 1. 트리거링 메소드를 결정합니다 (클릭, 시간, 종료, 스크롤); 2. 디자인 컨텐츠 (제목, 텍스트, 액션 버튼); 3. 세트 스타일 (크기, 색상, 글꼴, 배경); 4. 코드 구현 (HTML, CSS, JavaScript); 5. 테스트 및 배포.
