五十七、openlayers官网示例Map Export解析——将地图导出为图片

官网demo地址:

 Map Export

 这篇介绍了如何把地图导出为图片。

先在地图上添加两个图层。

 const style = new Style({
      fill: new Fill({
        color: "#eeeeee",
      }),
    });

    this.map = new Map({
      layers: [
        new VectorLayer({
          source: new VectorSource({
            url: "https://openlayers.org/data/vector/ecoregions.json",
            format: new GeoJSON(),
          }),
          background: "white",
          style: function (feature) {
            const color = asArray(feature.get("COLOR_NNH") || "#eeeeee");
            color[3] = 0.75;
            style.getFill().setColor(color);
            return style;
          },
        }),
        new HeatmapLayer({
          source: new VectorSource({
            url: "https://openlayers.org/en/latest/examples/data/geojson/world-cities.geojson",
            format: new GeoJSON(),
          }),
          weight: function (feature) {
            return feature.get("population") / 1e7;
          },
          radius: 15,
          blur: 15,
          opacity: 0.75,
        }),
      ],
      target: "map",
      view: new View({
        center: [0, 0],
        zoom: 2,
      }),
    });

然后绑定一个点击事件,使用this.map.renderSync()同步渲染一次地图,让地图触发rendercomplete事件。

exportData() {
      this.map.once("rendercomplete", () => {


      });
      this.map.renderSync();
    },

说地图导出前,我们先来看一个例子。

在canvas上绘制图形,并导出为图片。

 // 获取canvas和context
        const canvas = document.getElementById('myC
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值