簡體   English   中英

如何在 openlayers 6.x 中旋轉靜態圖像

[英]How to rotate static image in openlayers 6.x

我需要在 openlayers 6 中創建和旋轉靜態圖像層。

靜態圖像的創建正在使用 url 和 imageExtent 工作,我可以在地圖內看到圖像。

new ImageLayer({
        source: new Static({
          url,
          imageExtent: [ minX, minY, maxX, maxY] })

現在,我需要旋轉這張圖片。

我決定使用Turfjs

所以我做了這個使用 Turfjs 的 transformRotate 旋轉的代碼:

 const poly = bboxPolygon([minX, minY, maxX, maxY])

  const rotatedPoly = transformRotate(poly, -extent.rotation, {})



  const leftBottom = JSON.parse(JSON.stringify(rotatedPoly.geometry.coordinates[0][0]))
  const rightBottom = JSON.parse(JSON.stringify(rotatedPoly.geometry.coordinates[0][1]))
  const rightTop = JSON.parse(JSON.stringify(rotatedPoly.geometry.coordinates[0][2]))
  const leftTop = JSON.parse(JSON.stringify(rotatedPoly.geometry.coordinates[0][3]))

  const bounds = [leftBottom, leftTop, rightTop, rightBottom]

  return new ImageLayer({
    source: new Static({
      url,
      imageExtent: bounds
    })
  })

最后一個塊代碼不起作用,我在地圖中什么也看不到。

我的坐標在 'EPSG:4326'

有什么想法嗎?

即使沒有 Turfjs,任何可能有幫助的解決方案?

查看 ol-ext 擴展名和ol.source.GeoImage

看到它在行動: https : //viglino.github.io/ol-ext/examples/layer/map.geoimage.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM