Skip to content

Home Control (OlStyledHomeControl)

OlStyledHomeControl is a "Go Home" button for OpenLayers maps. Clicking it resets the map view to the initial or a specified extent.

Features

  • Records the map's initial extent after the first render; clicking the button returns to this extent.
  • Supports custom extent prop to define the target extent.
  • Customizable button icon and tooltip text.
  • Adapts to multiple visual themes.

Props

NameTypeDefaultDescription
extent[number, number, number, number] | undefined-The extent to return to (OpenLayers extent format). If not set, uses the initial extent
durationnumber800Animation options for map fit

Events (Emits)

EventDescription
clickTriggered when the button is clicked
go-homeTriggered when the map view returns home

Methods (Expose)

MethodDescription
goHomeManually trigger the go home action

Usage Example

vue
<template>
  <ol-styled-control-bar>
    <ol-styled-home-control :extent="[0,0,100,100]" />
  </ol-styled-control-bar>
</template>

Slot

You can customize the control icon via the default slot:

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

Notes

  • The control automatically records the initial extent after the map's first render.
  • If the map is not initialized with a view/extent, the control will calculate the current extent on first click.
  • Make sure the control is used as a child of the map or can properly inject the map instance.

Internationalization (i18n)

  • The default button text uses the home.title i18n key, which can be customized in src/i18n/locales/en.ts and zh-CN.ts.

Released under the MIT License.