MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / getChangedImageUrl

Function getChangedImageUrl

src/common/mapping/utils/L7LayerUtil.js:1521–1544  ·  view source on GitHub ↗
(url, iconStyle)

Source from the content-addressed store, hash-verified

1519 }
1520
1521 async function getChangedImageUrl(url, iconStyle) {
1522 const img = await loadImage(url);
1523 const { color, rotate } = iconStyle;
1524 const canvas = document.createElement('canvas');
1525 const ctx = canvas.getContext('2d');
1526 canvas.width = img.width;
1527 canvas.height = img.height;
1528 ctx.translate(canvas.width / 2, canvas.height / 2);
1529 rotate !== 0 && ctx.rotate((rotate * Math.PI) / 180);
1530 ctx.drawImage(img, -img.width / 2, -img.height / 2);
1531 if (color) {
1532 const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
1533 const data = imageData.data;
1534 const { r, g, b, a } = string2RGBAData(color);
1535 for (let i = 0; i < data.length; i += 4) {
1536 data[i] = r;
1537 data[i + 1] = g;
1538 data[i + 2] = b;
1539 data[i + 3] = Math.round(data[i + 3] * a);
1540 }
1541 ctx.putImageData(imageData, 0, 0);
1542 }
1543 return canvas.toDataURL();
1544 }
1545
1546 function loadImage(url) {
1547 return new Promise((resolve, reject) => {

Callers 1

processImageFunction · 0.85

Calls 8

loadImageFunction · 0.85
string2RGBADataFunction · 0.85
createElementMethod · 0.80
translateMethod · 0.80
roundMethod · 0.80
getContextMethod · 0.45
rotateMethod · 0.45
toDataURLMethod · 0.45

Tested by

no test coverage detected