Deal with Google Maps marker rotation

/ * 
* Function: canvas rotation icon, and generates the path 
* Parameters: Options (Object) 
* Uses: processing Google Maps marker rotation 
* * / 
const setRotation = (Options) => {
   return  new new Promise ((Resolve, Reject) = > { 
    the let W = 40 options.width || 
    the let H = || 40 options.height 
    the let Canvas = document.createElement ( 'Canvas' ) 
    canvas.width = W 
    canvas.height = H 
    the let CTX = canvas.getContext (' 2D ' ) 
    the let angle ? * = options.deg options.deg Math.PI / 180 [: 0 
    the let the centerX= w / 2
    let centerY = h / 2
    let dataURL = ''
    let img = new Image()
    img.src = options.url
    img.onload = function() {
      ctx.clearRect(0, 0, w, h)
      ctx.save()
      ctx.translate(centerX, centerY)
      ctx.rotate(angle)
      ctx.translate(-centerX, -centerY)
      ctx.drawImage(img, centerX/2, 0)
      ctx.restore()
      dataURL = canvas.toDataURL('image/png')
      resolve({
        size: options.size,
        origin: options.origin,
        url: dataURL
      })
    }
  })
}

 

Guess you like

Origin www.cnblogs.com/kiscon/p/11423561.html