Skip to content

标绘组件 (OlStyledPlotControl)

标绘组件提供了一个交互式工具,允许用户在地图上绘制各种几何图形,包括点、线、面和圆形以及文字。

使用 (Usage)

vue
<template>
  <ol-map
    ref="mapRef"
    class="map-container"
    :load-tiles-while-animating="true"
    :load-tiles-while-interacting="true"
    @mounted="onMapMounted"
  >
    <ol-view
      ref="viewRef"
      :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-text-label-control />
      <ol-styled-plot-control />
      <ol-styled-clear-control />
    </ol-styled-control-bar>
  </ol-map>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import type Map from 'ol/Map'
import BaseLayer from '../components/base-layer.vue'
import { mapConfig } from '../config/config.ts'

const mapRef = ref<any>(null)
const viewRef = ref<any>(null)

const onMapMounted = (map: Map) => {
  console.log('Map mounted:', map)
}
</script>

<style scoped lang="scss"></style>

OlStyledPlotControl 图形绘制

功能特性

  • 支持多种几何类型绘制:点、线、面、圆
  • 响应式设计,适配不同屏幕尺寸
  • 国际化支持(中英文)
  • 可定制的样式和主题
  • 与 Vue 3 和 OpenLayers 完美集成

使用说明

  1. 点击标绘控件按钮打开类型选择面板
  2. 选择要绘制的几何类型
  3. 在地图上点击开始绘制
  4. 根据类型不同,可能需要点击多个点来完成绘制
  5. 双击或按 ESC 键结束绘制

属性 (Props)

属性名类型默认值说明
plotThemeColorstring#ffcc33标绘主题色
clearOnCloseboolenfalse是否在关闭组件的时候清空图层

事件 (Events)

事件名说明参数
click控件被点击时触发(event: MouseEvent)
plot-active-change标绘状态改变时触发(active: boolean)
plot-start开始绘制时触发{ type: string, event: DrawEvent }
plot-end结束绘制时触发{ type: string, event: DrawEvent }

OlStyledTextLabelControl 文字绘制

属性 (Props)

属性名类型默认值说明
fontstring'sans-serif'文字字体
fontSizenumber12文字字体大小
fillColorstring#2f4b59文字填充颜色
strokeColorstring#ffffff文字边框颜色
strokeWidthnumber2文字边框宽度
offsetXnumber0文字水平偏移量
offsetYnumber-12文字垂直偏移量
clearOnCloseboolenfalse是否在关闭组件的时候清空图层

事件 (Events)

事件名说明参数
click控件被点击时触发(event: MouseEvent)
label-add文字标注添加时触发{ feature: Feature, text: string }

插槽(Slot)

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

vue
<template>
  <ol-styled-plot-control>
    <template #default>
      <i class="custom-plot-icon"></i>
    </template>
  </ol-styled-plot-control>
  <ol-styled-text-label-control>
    <template #default>
      <i class="custom-text-label-icon"></i>
    </template>
  </ol-styled-text-label-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: {
      plotControl: { title: 'Plot' },
      textLabelControl: { title: 'Text Label' }
    }
  }
})

app.mount('#app')

Released under the MIT License.