MapboxScaleControl

View source
比例尺控件,随缩放显示当前地图比例,支持公制、英制与海里单位。

简介

MapboxScaleControl 显示当前地图比例尺并随缩放更新。options.unit 选择单位(metric / imperial / nautical),options.maxWidth 限制比例尺最大像素宽度。

用法

切换 unit 查看不同单位下的比例尺:

<script setup lang="ts">
withDefaults(defineProps<{ unit?: 'metric' | 'imperial' | 'nautical' }>(), {
  unit: 'metric'
})
</script>

<template>
  <div class="h-115 w-full overflow-hidden rounded-(--ui-radius) border border-default">
    <MapboxMap
      :options="{ style: 'mapbox://styles/mapbox/light-v11', center: [116.39, 39.91], zoom: 10 }"
    >
      <MapboxScaleControl position="bottom-left" :options="{ unit, maxWidth: 120 }" />
    </MapboxMap>
  </div>
</template>

API

Props

Prop Default Type
position"top-left" | "top" | "top-right" | "right" | "bottom-right" | "bottom" | "bottom-left" | "left"

控件停靠位置;省略用地图默认位置

optionsmapboxgl.ScaleControlOptions

ScaleControl 构造选项

Changelog

No recent changes
Copyright © 2026 - 2026 YiXuan - MIT License