Select to view content in your preferred language

How to show GIF through dynamiclayer?

316
0
05-15-2022 09:31 PM
ZhouYC
by
Emerging Contributor

I useBaseDynamicLayer.createSubclass to create a layer with a picture. If the picture is static, it can work normally, but if the picture is GIF, only the first frame will be displayed.

Here is my code:

 

let layerClass = BaseDynamicLayer.createSubclass({
      // override BaseDynamicLayer methods
      getImageUrl(extent, width, height) {
        return imgUrl
      },

      // override BaseDynamicLayer methods
      fetchImage(extent, width, height) {
        let url = this.getImageUrl(extent, width, height)
          return new Promise((resolve) => {
            self._requestImg(url).then(data => {
              let img = data

              let cvs = document.createElement('canvas')
              let context = cvs.getContext('2d')
              cvs.width = width
              cvs.height = height

              // context.fillStyle = '#000'
              // context.fillRect(0, 0, width, height)
              // context.globalCompositeOperation = 'destination-atop'
              const pos = self._computePosition(extent, width, height)
              // console.log(pos)
              // const sPos = self.mapView.toScreen({
              //   x: pos.x,
              //   y: pos.y,
              //   spatialReference: {wkid: 4326}
              // })
              context.drawImage(img, pos.x, pos.y, pos.width, pos.height)
              // context.drawImage(img, 0, 0, width, height)

              resolve(cvs)
            })
          })
      }
    })

 

0 Kudos
0 Replies