【问题标题】:How to rotate static image in openlayers 6.x如何在 openlayers 6.x 中旋转静态图像
【发布时间】:2021-12-21 17:22:35
【问题描述】:

我需要在 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 也可能有所帮助?

【问题讨论】:

    标签: openlayers openlayers-6 openlayers-5 turfjs


    【解决方案1】:

    看看 ol-ext 扩展和ol.source.GeoImage。

    查看实际操作:https://viglino.github.io/ol-ext/examples/layer/map.geoimage.html

    【讨论】:

    • 不适用于 openlayers 6.9
    • 酷炫的 OpenLayers 扩展 (ol/ol3/ol4)。
    • 示例页面使用最新的ol版本运行...文档不是最新的...
    • GeoImage (ol-ext) 中 ImageLayer (openlayers) 的 imageExtent 的等价物是什么?与 imageCrop 相同?请问有什么例子吗?
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    相关资源
    最近更新 更多