Skip to content

导出组件 (OlStyledExportMapControl)

用于导出地图(截图式),包括地图上的栅格、矢量等图层。

使用 (Usage)

vue
<template>
  <ol-map class="map-container">
    <ol-view
      ref="view"
      :center="mapConfig.center"
      :zoom="mapConfig.zoom"
      :projection="mapConfig.projection"
    />

    <base-layer />
    <ol-styled-control-bar>
      <ol-styled-zoom-in-control />
      <ol-styled-zoom-out-control />
      <ol-styled-plot-control />
      <ol-styled-export-map-control />
    </ol-styled-control-bar>
  </ol-map>
</template>
<script lang="ts" setup>
import BaseLayer from '../components/base-layer.vue'
import { mapConfig } from '../config/config.ts'
</script>

属性 (Props)

属性名类型默认值说明
fileNameStringmap导出的图片名称
typejpeg/pngpng导出的图片格式
qualityNumber0.92图片质量,范围在 0.0 到 1.0 之间
backgroundString-图片的背景颜色

事件 (Events)

事件名说明参数
click控件被点击时触发(event: MouseEvent)
export-start开始导出时触发-
export-end结束导出时触发dataURL
export-error导出错误时触发Error

方法(Expose)

方法名说明参数
exportMap导出地图-
vue
<template>
  <ol-map>
    <ol-view />
    <ol-tile-layer>
      <ol-source-osm />
    </ol-tile-layer>
    
    <ol-styled-control-bar>
      <ol-styled-export-map-control :ref="controlRef" />
    </ol-styled-control-bar>
  </ol-map>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";

const controlRef = ref<any>(null);

onMounted(() => {
  controlRef.value?.exportMap()
});
</script>

插槽(Slot)

可以通过默认插槽自定义控件图标:

vue
<template>
  <ol-styled-export-map-control>
    <template #default>
      <i class="custom-export-icon"></i>
    </template>
  </ol-styled-export-map-control>
</template>

国际化

导出控件支持国际化,通过在安装插件时配置 localemessages

js
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import OpenLayersControls from 'vue3-openlayers-styled-controls'

const app = createApp(App)

app.use(OpenLayersControls, {
  locale: 'en',
  messages: {
    en: {
      exportMap: { title: 'Export map' }
    }
  }
})

app.mount('#app')

Released under the MIT License.