ฉันมีเลเยอร์ที่เรนเดอร์ LineStrings และกำลังพยายามใช้เอฟเฟกต์เรืองแสงกับเส้น สไตล์ที่ฉันสร้างขึ้นใช้ตัวเรนเดอร์ที่กำหนดเองเพื่อสร้างเส้นโครงร่างโดยมีการไล่ระดับสีตั้งฉากกับแต่ละส่วนของเส้น:
const glow_style = new Style({
renderer: (_coords, state) => {
const ctx = state.context;
const coords = _coords as Coordinate[];
ctx.lineWidth = 25;
for (let i = 1; i < coords.length; i++) {
const start = coords[i - 1];
const end = coords[i];
const [grd_start, grd_end] = getPerpendicularPoints(start, end, ctx.lineWidth);
const grd = ctx.createLinearGradient(grd_start[0], grd_start[1], grd_end[0], grd_end[1]);
grd.addColorStop(0, '#ffffff00');
grd.addColorStop(0.5, 'white');
grd.addColorStop(1, '#ffffff00');
ctx.strokeStyle = grd;
ctx.beginPath();
ctx.moveTo(start[0], start[1]);
ctx.lineTo(end[0], end[1]);
ctx.stroke();
}
}
});
สไตล์นี้ใช้ได้กับเส้นตรงทั้งหมด แต่จะแยกออกเป็นมุม เนื่องจากการไล่ระดับสีเชื่อมต่อระหว่างส่วนของเส้นได้ไม่ดีนัก ถ้า ctx.lineCap
เหลือเป็น butt
การไล่ระดับสีจะไม่อยู่ติดกันรอบมุม หากตั้งค่าเป็น round
ส่วนต่างๆ จะสัมผัสกัน แต่การไล่ระดับสีจะไม่ต่อเนื่องเนื่องจากการทับซ้อนกัน นี่คือตัวอย่างของแต่ละ:
ฉันมีตัวเลือกอะไรบ้างในการสร้างการไล่ระดับสีที่ราบรื่นตลอด LineString ทั้งหมด