Commit a1b58175 by wanghao

同步 v3.6.1代码

parent 2da070b5
/** /**
* Mars3D三维可视化平台 mars3d * Mars3D三维可视化平台 mars3d
* *
* 版本信息:v3.6.0 * 版本信息:v3.6.1
* 编译日期:2023-08-04 12:47:13 * 编译日期:2023-08-14 21:45:40
* 版权所有:Copyright by 火星科技 http://mars3d.cn * 版权所有:Copyright by 火星科技 http://mars3d.cn
* 使用单位:免费公开版 ,2023-03-17 * 使用单位:免费公开版 ,2023-03-17
*/ */
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
.queryPoiButton { .toolSearch {
position: absolute; width: 310px;
left: 3.5px; position: absolute;
top: -36px; left: 36px;
width: 310px; right: 0;
height: 300px; border: none;
background-color: rgba(0, 0, 0, 0) !important; color: white;
border: none; border: 1px solid #717171e0;
border-radius: 0 !important; overflow: hidden;
padding: 0; }
margin: 0;
box-shadow: none !important; .poiButtonResult {
} position: absolute;
.queryPoiButton:hover { left: 36px;
box-shadow: none; bottom: 0;
} width: 310px;
min-height: 120px;
.queryPoiButton svg { border: none;
position: absolute; color: white;
top: 0; overflow: hidden;
left: 0; }
background: #3f4854;
border: none; .deleteInput {
border-radius: 14%; position: absolute;
} top: -2px;
right: 5px;
.toolSearch { line-height: 0;
position: absolute; font-size: 18px;
left: 32px; cursor: pointer;
right: 0; }
top: -6px;
border: none; .searchInput {
color: white; width: 100%;
border: 1px solid #717171e0; height: 31px;
overflow: hidden; border: none;
} color: white;
background-color: rgba(40, 40, 40, 0.7);
.poiButtonResult { }
position: absolute;
left: 36px; input::-webkit-search-cancel-button {
top: 32.5px; display: none;
width: 274px; }
min-height: 120px;
border: none; .searchInput:focus {
color: white; border-color: #ea4;
overflow: hidden; background-color: rgba(63, 72, 84);
} box-shadow: none;
outline: none;
.deleteInput { }
position: absolute;
top: 0; /* 搜寻的结果显示 */
right: 5px; .searchResults {
line-height: 0; width: 100%;
font-size: 18px; height: 88%;
cursor: pointer; overflow: auto;
} font-size: 12px;
position: absolute;
.searchInput { background-color: rgba(40, 40, 40, 0.7);
width: 100%; }
height: 31px;
border: none; .searchResults p {
color: white; margin-left: -20px;
background-color: rgba(40, 40, 40, 0.7); width: 100%;
} text-align: center;
input::-webkit-search-cancel-button { }
display: none;
} .searchResults ul {
display: block;
.searchInput:focus { line-height: 25px;
border-color: #ea4; min-height: 100px;
background-color: rgba(63, 72, 84); max-height: 150px;
box-shadow: none; }
outline: none;
} .searchResults li {
margin: 0 0 9px -40px;
/* 搜寻的结果显示 */ color: #ebebebe7;
.searchResults { cursor: pointer;
width: 100%; position: relative;
height: 88%; text-align: left;
overflow: auto; text-indent: 25px;
font-size: 12px; }
position: absolute;
background-color: rgba(40, 40, 40, 0.7); .searchResults li::after {
} content: "";
position: absolute;
.searchResults p { left: 0;
margin-left: -20px; bottom: -3px;
width: 100%; width: 100%;
text-align: center; height: 1px;
} background: #a79ecc;
.searchResults ul { }
display: block;
line-height: 25px; .searchResults li:hover {
min-height: 100px; background: rgb(255 252 252 / 55%);
max-height: 150px; color: #795a5a;
} }
.searchResults li { .gaodesousuo img {
margin: 0 0 9px -40px; margin-right: 10px;
color: #ebebebe7; }
cursor: pointer;
position: relative; /*上下页数的样式 */
text-align: left; .resultNextPages {
text-indent: 25px; width: 100%;
} height: 12%;
color: #ebebebe7;
.searchResults li::after { cursor: pointer;
content: ""; font-size: 13px;
position: absolute; position: absolute;
left: -27px; bottom: 0;
bottom: -3px; padding-left: 10px;
width: 110%; line-height: 16px;
height: 1px; background-color: rgba(40, 40, 40, 0.7);
background: #a79ecc; }
}
.resultNextPages p {
.searchResults li:hover { float: left;
background: rgb(255 252 252 / 55%); }
color: #795a5a;
} /* 下一页 */
.resultNextPages p:nth-last-child(1) {
.gaodesousuo img { text-align: center;
margin-right: 10px; position: relative;
} right: -34px;
width: 18px;
/*上下页数的样式 */ border: 1px solid #f9ececb3;
.resultNextPages { }
width: 100%;
height: 12%; /* 上一页 */
color: #ebebebe7; .resultNextPages p:nth-last-child(2) {
cursor: pointer; text-align: center;
font-size: 13px; position: relative;
position: absolute; right: -30px;
bottom: 0; width: 18px;
padding-left: 10px; border: 1px solid #f9ececb3;
line-height: 16px; }
background-color: rgba(40, 40, 40, 0.7);
} /* 首页 */
.resultNextPages p:nth-last-child(3) {
.resultNextPages p { text-align: center;
float: left; position: relative;
} right: -10px;
width: 35px;
/* 下一页 */ border: 1px solid #f9ececb3;
.resultNextPages p:nth-last-child(1) { }
text-align: center;
position: relative; /* 页数 */
right: -34px; .resultNextPages p:nth-last-child(4) {
width: 18px; position: relative;
border: 1px solid #f9ececb3; right: -5px;
} width: 65px;
}
/* 上一页 */
.resultNextPages p:nth-last-child(2) { .resultNextPages p:nth-last-child(1):hover,
text-align: center; .resultNextPages p:nth-last-child(2):hover,
position: relative; .resultNextPages p:nth-last-child(3):hover {
right: -30px; text-decoration: underline;
width: 18px; }
border: 1px solid #f9ececb3; \ No newline at end of file
}
/* 首页 */
.resultNextPages p:nth-last-child(3) {
text-align: center;
position: relative;
right: -10px;
width: 35px;
border: 1px solid #f9ececb3;
}
/* 页数 */
.resultNextPages p:nth-last-child(4) {
position: relative;
right: -5px;
width: 65px;
}
.resultNextPages p:nth-last-child(1):hover,
.resultNextPages p:nth-last-child(2):hover,
.resultNextPages p:nth-last-child(3):hover {
text-decoration: underline;
}
...@@ -83,41 +83,74 @@ class PoiQueryButton extends mars3d.control.BaseControl { ...@@ -83,41 +83,74 @@ class PoiQueryButton extends mars3d.control.BaseControl {
) )
// 鼠标移入移出 // 鼠标移入移出
let numTime = null
let cacheTarget let cacheTarget
// 搜索框移入
this._container.addEventListener("mouseover", (e) => { this._container.addEventListener("mouseover", (e) => {
// 缓存,提高效率 if (numTime) {
if (cacheTarget === this.id) { clearTimeout(numTime)
return numTime = null
} }
cacheTarget = this.id
if (this._queryInputContainer.style.display !== "block") { if (this._queryInputContainer.style.display !== "block") {
this.toolSearchNoShow("block") this._queryInputContainer.style.top = this._container.offsetTop + "px"
this.toolActive() this._queryResultContainer.style.height = this.parentContainer.offsetHeight - this._container.offsetTop - 31 + "px"
mars3d.DomUtil.addClass(this._container, "queryPoiButton")
this._container.style.height = this.parentContainer.offsetHeight + 40 + "px" this.toolActive()
this._queryResultContainer.style.height = this.parentContainer.offsetHeight - 10 + "px"
} }
}) })
// 搜索框移出
this._container.addEventListener("mouseout", (e) => { this._container.addEventListener("mouseout", (e) => {
cacheTarget = null numTime = setTimeout(() => {
const queryVal = this._queryInputContainer.querySelector(".searchInput").value console.log("触发 mouseout ? _container")
if (queryVal.length === 0) { cacheTarget = null
this.clear()
this.toolSearchNoShow("none") const queryVal = this._queryInputContainer.querySelector(".searchInput").value
mars3d.DomUtil.removeClass(this._container, "queryPoiButton") if (queryVal.length === 0) {
this._container.style.height = "" this.clear()
} this.toolSearchNoShow("none")
}
}, 500)
}) })
// input面板,在queryPoiButton下面 // input面板,在queryPoiButton下面
this._queryInputContainer = mars3d.DomUtil.create("div", "toolSearch") this._queryInputContainer = mars3d.DomUtil.create("div", "toolSearch")
this._container.appendChild(this._queryInputContainer) this.parentContainer.appendChild(this._queryInputContainer)
// 搜索框移除
this._queryInputContainer.addEventListener("mouseover", (e) => {
if (numTime) {
clearTimeout(numTime)
numTime = null
}
})
this._queryInputContainer.addEventListener("input", (e) => {
if (numTime) {
clearTimeout(numTime)
numTime = null
}
// 缓存,提高效率
if (cacheTarget === this.id) {
return
}
cacheTarget = this.id
this.toolSearchNoShow("block")
})
this._queryInputContainer.addEventListener("mouseout", (e) => {
numTime = setTimeout(() => {
cacheTarget = null
const queryVal = this._queryInputContainer.querySelector(".searchInput").value
if (queryVal.length === 0) {
this.clear()
this.toolSearchNoShow("none")
}
}, 500)
})
// 搜寻结果,在mars3dContainer面板下面 // 搜寻结果,在mars3dContainer面板下面
this._queryResultContainer = mars3d.DomUtil.create("div", "poiButtonResult") this._queryResultContainer = mars3d.DomUtil.create("div", "poiButtonResult")
this._container.appendChild(this._queryResultContainer) this.parentContainer.appendChild(this._queryResultContainer)
this.toolSearchNoShow("none") this.toolSearchNoShow("none")
// 创建input输入框 // 创建input输入框
...@@ -133,7 +166,7 @@ class PoiQueryButton extends mars3d.control.BaseControl { ...@@ -133,7 +166,7 @@ class PoiQueryButton extends mars3d.control.BaseControl {
this._queryInputContainer.querySelector(".searchInput").value = "" this._queryInputContainer.querySelector(".searchInput").value = ""
this.clear() this.clear()
this.toolSearchNoShow("none") this.toolSearchNoShow("none")
mars3d.DomUtil.removeClass(this._container, "queryPoiButton") // mars3d.DomUtil.removeClass(this._container, "queryPoiButton")
this._container.style.height = "" this._container.style.height = ""
cacheTarget = null cacheTarget = null
}) })
......
...@@ -130,7 +130,7 @@ function startRoam() { ...@@ -130,7 +130,7 @@ function startRoam() {
// 当前的路线中的点位 // 当前的路线中的点位
const currIndex = fixedRoute.currIndex const currIndex = fixedRoute.currIndex
if (currIndex % 2 === 0) { if (currIndex % 2 === 1) {
return return
} }
......
...@@ -91,6 +91,8 @@ export function addRandomGraphicByCount(count) { ...@@ -91,6 +91,8 @@ export function addRandomGraphicByCount(count) {
}) })
graphicLayer.addGraphic(graphic) graphicLayer.addGraphic(graphic)
// graphic.openPopup(0)
graphicLayer.enabledEvent = true // 恢复事件 graphicLayer.enabledEvent = true // 恢复事件
return result.points.length return result.points.length
} }
......
...@@ -88,6 +88,8 @@ export function addRandomGraphicByCount(count) { ...@@ -88,6 +88,8 @@ export function addRandomGraphicByCount(count) {
}) })
graphicLayer.addGraphic(graphic) graphicLayer.addGraphic(graphic)
// graphic.openPopup(0)
graphicLayer.enabledEvent = true // 恢复事件 graphicLayer.enabledEvent = true // 恢复事件
return result.points.length return result.points.length
} }
......
...@@ -93,6 +93,9 @@ function addGraphicLayer() { ...@@ -93,6 +93,9 @@ function addGraphicLayer() {
}) })
// ui面板信息展示 // ui面板信息展示
fixedRoute.on(mars3d.EventType.change, (event) => { fixedRoute.on(mars3d.EventType.change, (event) => {
// const popup = event.graphic.getPopup()
// const container = popup?.container // popup对应的DOM
// console.log("漫游change", event) // console.log("漫游change", event)
throttled(eventTarget.fire("roamLineChange", event), 500) throttled(eventTarget.fire("roamLineChange", event), 500)
}) })
......
...@@ -60,19 +60,24 @@ export function onMounted(mapInstance) { ...@@ -60,19 +60,24 @@ export function onMounted(mapInstance) {
} }
// 设置动态位置 // 设置动态位置
graphicLayer.eachGraphic((graphic) => { changePosition(0)
graphic.addDynamicPosition(randomPoint()) // 首次出现的位置
})
graphicLayer.eachGraphic((graphic) => {
graphic.addDynamicPosition(randomPoint(), 30) // 按30秒运动至指定位置
})
// 定时更新动态位置(setInterval为演示) // 定时更新动态位置(setInterval为演示)
const interval = 30
changePosition(interval)
setInterval(() => { setInterval(() => {
graphicLayer.eachGraphic((graphic) => { changePosition(interval)
graphic.addDynamicPosition(randomPoint(), 30) }, interval * 1000)
}) }
}, 30000)
// 改变位置
function changePosition(time) {
graphicLayer.eachGraphic((graphic) => {
if (graphic.isPrivate) {
return
}
graphic.addDynamicPosition(randomPoint(), time) // 按time秒运动至指定位置
})
} }
/** /**
......
...@@ -85,7 +85,7 @@ function addDemoGraphic3(graphicLayer) { ...@@ -85,7 +85,7 @@ function addDemoGraphic3(graphicLayer) {
style: { style: {
url: "//data.mars3d.cn/gltf/mars/qiche.gltf", url: "//data.mars3d.cn/gltf/mars/qiche.gltf",
scale: 0.5, scale: 0.5,
heading: 30, heading: 90,
minimumPixelSize: 100 minimumPixelSize: 100
} }
}) })
...@@ -94,6 +94,7 @@ function addDemoGraphic3(graphicLayer) { ...@@ -94,6 +94,7 @@ function addDemoGraphic3(graphicLayer) {
// 移动模型 // 移动模型
graphicCar.moveTo({ graphicCar.moveTo({
position: [116.259138, 30.855247, 562], position: [116.259138, 30.855247, 562],
orientation: true,
time: 8 // 移动的时长(单位 秒) time: 8 // 移动的时长(单位 秒)
}) })
} }
...@@ -144,15 +144,20 @@ function addDemoGraphic2(graphicLayer) { ...@@ -144,15 +144,20 @@ function addDemoGraphic2(graphicLayer) {
}) })
graphicLayer.addGraphic(graphic) graphicLayer.addGraphic(graphic)
graphic.addDynamicPosition(randomPoint(), 0) // 设置动态位置
graphic.addDynamicPosition(randomPoint(), 20) changePosition(graphic, 0)
// 定时更新动态位置(setInterval为演示) // 定时更新动态位置(setInterval为演示)
const interval = 20
changePosition(graphic, interval)
setInterval(() => { setInterval(() => {
if (graphic.isAdded) { changePosition(graphic, interval)
graphic.addDynamicPosition(randomPoint(), 20) }, interval * 1000)
} }
}, 20000)
// 改变位置
function changePosition(graphic, time) {
graphic.addDynamicPosition(randomPoint(), time) // 按time秒运动至指定位置
} }
// 取区域内的随机点 // 取区域内的随机点
......
...@@ -5,7 +5,6 @@ import * as mars3d from "mars3d" ...@@ -5,7 +5,6 @@ import * as mars3d from "mars3d"
export let map // mars3d.Map三维地图对象 export let map // mars3d.Map三维地图对象
export let graphicLayer // 矢量图层对象 export let graphicLayer // 矢量图层对象
let imgData = null
let lastExtent = null let lastExtent = null
let bWorking = false let bWorking = false
let currentData let currentData
...@@ -30,8 +29,6 @@ export const mapOptions = { ...@@ -30,8 +29,6 @@ export const mapOptions = {
export function onMounted(mapInstance) { export function onMounted(mapInstance) {
map = mapInstance // 记录map map = mapInstance // 记录map
imgData = getImageData()
// 创建矢量数据图层 // 创建矢量数据图层
graphicLayer = new mars3d.layer.GraphicLayer() graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer) map.addLayer(graphicLayer)
...@@ -107,6 +104,11 @@ function startWorker(strBounds) { ...@@ -107,6 +104,11 @@ function startWorker(strBounds) {
} }
} }
const colorRamp = new mars3d.ColorRamp({
steps: [25, 75, 125, 175, 250, 400],
colors: ["rgb(0, 228, 0)", "rgb(256, 256, 0)", "rgb(256, 126, 0)", "rgb(256, 0, 0)", "rgb(153, 0, 76)", "rgb(126, 0, 35)"]
})
function createGraphics(currentData) { function createGraphics(currentData) {
graphicLayer.clear() graphicLayer.clear()
console.log("加载数据", currentData) console.log("加载数据", currentData)
...@@ -120,7 +122,7 @@ function createGraphics(currentData) { ...@@ -120,7 +122,7 @@ function createGraphics(currentData) {
position: [item.lon, item.lat], position: [item.lon, item.lat],
style: { style: {
image: mars3d.Util.getCircleImage(item.aqi, { image: mars3d.Util.getCircleImage(item.aqi, {
color: getColor(item.aqi), color: colorRamp.getColor(item.aqi),
radius: 25 radius: 25
}), }),
scale: 1, scale: 1,
...@@ -133,36 +135,3 @@ function createGraphics(currentData) { ...@@ -133,36 +135,3 @@ function createGraphics(currentData) {
graphicLayer.addGraphic(graphic) graphicLayer.addGraphic(graphic)
} }
} }
// 获取色带
function getImageData() {
const nWidth = 500
const canvas = document.createElement("canvas")
canvas.width = nWidth
canvas.height = nWidth
const ctx = canvas.getContext("2d")
ctx.beginPath()
/* 指定渐变区域 */
const grad = ctx.createLinearGradient(0, 0, nWidth, 0)
/* 指定几个颜色 */
grad.addColorStop(0.05, "rgb(0, 228, 0)") // green
grad.addColorStop(0.15, "rgb(256, 256, 0)") // yellow
grad.addColorStop(0.25, "rgb(256, 126, 0)") // orange
grad.addColorStop(0.35, "rgb(256, 0, 0)") // red
grad.addColorStop(0.5, "rgb(153, 0, 76)") // purple
grad.addColorStop(0.8, "rgb(126, 0, 35)") // maroon
/* 将这个渐变设置为fillStyle */
ctx.fillStyle = grad
/* 绘制矩形 */
ctx.rect(0, 0, nWidth, nWidth)
ctx.fill()
return ctx.getImageData(0, 0, nWidth, 1).data
}
function getColor(aqi) {
if (aqi > 500) {
return "rgba(126,0,35,0.8)"
} else {
return `rgba(${imgData[aqi * 4]},${imgData[aqi * 4 + 1]},${imgData[aqi * 4 + 2]},0.8)`
}
}
...@@ -25,17 +25,19 @@ export function onMounted(mapInstance) { ...@@ -25,17 +25,19 @@ export function onMounted(mapInstance) {
map.basemap = 2017 // 蓝色底图 map.basemap = 2017 // 蓝色底图
map.hasTerrain = false map.hasTerrain = false
// 风场 // 风场
canvasWindLayer = new mars3d.layer.CanvasWindLayer({ canvasWindLayer = new mars3d.layer.CanvasWindLayer({
worker: window.currentPath + "windWorker.js", // 启用多线程模式,注释后是单线程模式(非必须) worker: window.currentPath + "windWorker.js", // 启用多线程模式,注释后是单线程模式(非必须)
color: "#ffffff", // 颜色
frameRate: 20, // 每秒刷新次数 frameRate: 20, // 每秒刷新次数
speedRate: 60, // 风前进速率 speedRate: 60, // 风前进速率
particlesNumber: 10000, particlesNumber: 10000,
maxAge: 120, maxAge: 120,
lineWidth: 2 lineWidth: 2,
// 单颜色
color: "#ffffff"
// 多颜色
// colors: ["rgb(0, 228, 0)", "rgb(256, 256, 0)", "rgb(256, 126, 0)", "rgb(256, 0, 0)", "rgb(153, 0, 76)", "rgb(126, 0, 35)"],
// steps: [1.0, 2.0, 5.4, 7.9, 10.7, 13.8]
}) })
map.addLayer(canvasWindLayer) map.addLayer(canvasWindLayer)
......
...@@ -65,6 +65,17 @@ export function onUnmounted() { ...@@ -65,6 +65,17 @@ export function onUnmounted() {
// 叠加的图层 // 叠加的图层
let tileLayer let tileLayer
// 改wms请求的大小写
// Cesium.Resource.ReplaceUrl = function (url) {
// if (this._url.startsWith("//server.mars3d.cn/geoserver/mars/wms")) {
// return url.replaceAll("bbox", "BBOX") // 将3dtiles中的“+”符号转义下
// } else {
// return url
// }
// }
export function addTileLayer() { export function addTileLayer() {
removeTileLayer() removeTileLayer()
......
...@@ -67,7 +67,7 @@ export function removeAll() { ...@@ -67,7 +67,7 @@ export function removeAll() {
* 起点按钮 * 起点按钮
* *
* @export * @export
* @param {string} type 不同方式路线查询 * @param {number} type 不同方式路线查询
* @returns {string} * @returns {string}
*/ */
export function startPoint(type) { export function startPoint(type) {
......
...@@ -136,6 +136,11 @@ export function drawArea(date) { ...@@ -136,6 +136,11 @@ export function drawArea(date) {
}) })
} }
const colorRamp = new mars3d.ColorRamp({
steps: [5, 15, 25, 35, 50, 80],
colors: ["rgb(0, 228, 0)", "rgb(256, 256, 0)", "rgb(256, 126, 0)", "rgb(256, 0, 0)", "rgb(153, 0, 76)", "rgb(126, 0, 35)"]
})
function showRateResult(result) { function showRateResult(result) {
console.log("分析结果", result) console.log("分析结果", result)
...@@ -147,7 +152,7 @@ function showRateResult(result) { ...@@ -147,7 +152,7 @@ function showRateResult(result) {
position: p, position: p,
style: { style: {
pixelSize: 10, pixelSize: 10,
color: getColor(rate) // 计算颜色,色带颜色 color: colorRamp.getColor(rate) // 计算颜色,色带颜色
}, },
popup: `阴影率: ${rate.toFixed(2)}%` popup: `阴影率: ${rate.toFixed(2)}%`
}) })
...@@ -155,39 +160,40 @@ function showRateResult(result) { ...@@ -155,39 +160,40 @@ function showRateResult(result) {
}) })
} }
// 获取色带 // // 获取色带
function getImageData() { // function getImageData() {
const nWidth = 100 // const nWidth = 100
const canvas = document.createElement("canvas") // const canvas = document.createElement("canvas")
canvas.width = nWidth // canvas.width = nWidth
canvas.height = nWidth // canvas.height = nWidth
const ctx = canvas.getContext("2d") // const ctx = canvas.getContext("2d")
ctx.beginPath() // ctx.beginPath()
/* 指定渐变区域 */ // /* 指定渐变区域 */
const grad = ctx.createLinearGradient(0, 0, nWidth, 0) // const grad = ctx.createLinearGradient(0, 0, nWidth, 0)
/* 指定几个颜色 */ // /* 指定几个颜色 */
grad.addColorStop(0.05, "rgb(0, 228, 0)") // green // grad.addColorStop(0.05, "rgb(0, 228, 0)") // green
grad.addColorStop(0.15, "rgb(256, 256, 0)") // yellow // grad.addColorStop(0.15, "rgb(256, 256, 0)") // yellow
grad.addColorStop(0.25, "rgb(256, 126, 0)") // orange // grad.addColorStop(0.25, "rgb(256, 126, 0)") // orange
grad.addColorStop(0.35, "rgb(256, 0, 0)") // red // grad.addColorStop(0.35, "rgb(256, 0, 0)") // red
grad.addColorStop(0.5, "rgb(153, 0, 76)") // purple // grad.addColorStop(0.5, "rgb(153, 0, 76)") // purple
grad.addColorStop(0.8, "rgb(126, 0, 35)") // maroon // grad.addColorStop(0.8, "rgb(126, 0, 35)") // maroon
/* 将这个渐变设置为fillStyle */
ctx.fillStyle = grad // /* 将这个渐变设置为fillStyle */
/* 绘制矩形 */ // ctx.fillStyle = grad
ctx.rect(0, 0, nWidth, nWidth) // /* 绘制矩形 */
ctx.fill() // ctx.rect(0, 0, nWidth, nWidth)
return ctx.getImageData(0, 0, nWidth, 1).data // ctx.fill()
} // return ctx.getImageData(0, 0, nWidth, 1).data
// }
const imgData = getImageData()
// const imgData = getImageData()
// 计算颜色,色带颜色
function getColor(rate) { // // 计算颜色,色带颜色
if (rate > 100) { // function getColor(rate) {
return "rgba(126,0,35,0.8)" // if (rate > 100) {
} else { // return "rgba(126,0,35,0.8)"
rate = Math.round(rate) // } else {
return `rgba(${imgData[rate * 4]},${imgData[rate * 4 + 1]},${imgData[rate * 4 + 2]},0.8)` // rate = Math.round(rate)
} // return `rgba(${imgData[rate * 4]},${imgData[rate * 4 + 1]},${imgData[rate * 4 + 2]},0.8)`
} // }
// }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论