카테고리 없음

로컬스토리지 사용, hex색상을 rgb로 변환 코드

숲별 2024. 2. 19. 10:51
728x90

function natest(name){
  const data = {key : name, number : 1992};
  localStorage.setItem('jsonKey', JSON.stringify(data));

  const storedJson = localStorage.getItem('jsonKey');
  const parsedData = JSON.parse(storedJson);
  console.log(parsedData.key);
  console.log(parsedData.number);
 }



  let lineColor = document.getElementById("lineColor").value;
  let lineAlpha = document.getElementById("lineColorAlpha").value;
  let lineWidth = document.getElementById("stroke-width").value;
 
  console.log(event)
  debugger;
  lineColor = hexToRgba(lineColor, lineAlpha);

  function hexToRgba(hexColor, lineAlpha) {
    // Remove the hash (#) if present
    hexColor = hexColor.replace(/^#/, '');
 
    // Parse the hex values
    var bigint = parseInt(hexColor, 16);
 
    // Extract RGB values
    var r = (bigint >> 16) & 255;
    var g = (bigint >> 8) & 255;
    var b = bigint & 255;
 
    // Return the RGB values as a string
    return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + lineAlpha + ')';
  }
  // Display RGB color in the console
  console.log(lineColor);

  let lineStyle = new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: lineColor,
      width: lineWidth })
    });
  console.log(lineStyle);
  let lineLayer = gwsJS.getLayers()[2].getLayersArray()[1]
  lineLayer.setStyle(lineStyle)