Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/snowbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pluginFullscreen from '@polar/polar/plugins/fullscreen'
import pluginGeoLocation from '@polar/polar/plugins/geoLocation'
import pluginIconMenu from '@polar/polar/plugins/iconMenu'
import pluginInitialView from '@polar/polar/plugins/initialView'
import pluginLayerChooser from '@polar/polar/plugins/layerChooser'
import pluginLoadingIndicator from '@polar/polar/plugins/loadingIndicator'
import pluginPins from '@polar/polar/plugins/pins'
Expand Down Expand Up @@ -93,7 +94,7 @@
colorScheme,
startCenter: [565874, 5934140],
layers: [
// TODO: Add internalization to snowbox

Check warning on line 97 in examples/snowbox/index.js

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO: Add internalization to snowbox'
{
id: basemapId,
visibility: true,
Expand Down Expand Up @@ -500,6 +501,11 @@
disabledOnMobile: true,
icon: 'kern-icon-fill--assistant-direction',
},
{
plugin: pluginInitialView({
renderType: 'iconMenu',
}),
},
],
[
{
Expand Down
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AddressSearch from '@/plugins/addressSearch'
import Fullscreen from '@/plugins/fullscreen'
import GeoLocation from '@/plugins/geoLocation'
import IconMenu from '@/plugins/iconMenu'
import ReturnToInitialView from '@/plugins/initialView'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming the import InitialView seems more fitting.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a

import LayerChooser from '@/plugins/layerChooser'
import LoadingIndicator from '@/plugins/loadingIndicator'
import Pins from '@/plugins/pins'
Expand Down Expand Up @@ -62,6 +63,12 @@ function addPlugins(map: typeof PolarContainer, enabledPlugins: string[]) {
displayComponent: true,
layoutTag: 'MIDDLE_MIDDLE',
}),
enabledPlugins.includes('returnToInitialView') &&
ReturnToInitialView({
displayComponent: true,
layoutTag: 'TOP_RIGHT',
renderType: 'iconMenu',
}),
Comment on lines +66 to +71

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the plugin is supposed to be added to the iconMenu it should be done in L32-46. In that case, that information should be added to the TSDoc comment of createMap in line 101.

enabledPlugins.includes('pointerPosition') &&
PointerPosition({
displayComponent: true,
Expand Down
4 changes: 4 additions & 0 deletions src/core/types/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import type { FullscreenPluginOptions } from '@/plugins/fullscreen'
import type { GeoLocationPluginOptions } from '@/plugins/geoLocation'
import type { IconMenuPluginOptions } from '@/plugins/iconMenu'
import type { InitialViewPluginOptions } from '@/plugins/initialView'
import type { LoadingIndicatorOptions } from '@/plugins/loadingIndicator'
import type { PinsPluginOptions } from '@/plugins/pins'
import type { PointerPositionPluginOptions } from '@/plugins/pointerPosition'
Expand Down Expand Up @@ -316,7 +317,7 @@

// Plugins are not sorted alphabetical, but listed last.
// Remember to sort them alphabetical inside their space.
// TODO: Generate this section via types/plugin.ts

Check warning on line 320 in src/core/types/main.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO: Generate this section via...'
/* eslint-disable perfectionist/sort-interfaces */

/** Configuration for addressSearch plugin. */
Expand All @@ -343,6 +344,9 @@
/** Configuration for iconMenu plugin. */
iconMenu?: IconMenuPluginOptions

/** Configuration for iInitialView plugin. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Configuration for iInitialView plugin. */
/** Configuration for initialView plugin. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a

returnToInitialView?: InitialViewPluginOptions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
returnToInitialView?: InitialViewPluginOptions
initialView?: InitialViewPluginOptions

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a


/** Configuration for loadingIndicator plugin. */
loadingIndicator?: LoadingIndicatorOptions

Expand Down
14 changes: 14 additions & 0 deletions src/core/types/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import type { PluginId as IconMenuPluginId } from '@/plugins/iconMenu'
import type { resourcesEn as IconMenuResources } from '@/plugins/iconMenu/locales'
import type { useIconMenuStore as IconMenuStore } from '@/plugins/iconMenu/store'
import type { PluginId as ReturnToInitialViewPluginId } from '@/plugins/initialView'
import type { resourcesEn as ReturnToInitialViewResources } from '@/plugins/initialView/locales'
import type { useInitialViewStore as ReturnToInitialViewStore } from '@/plugins/initialView/store'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names should reflect the name of the plugin. Thus, dropping the ReturnTo is the way forward.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a

import type { PluginId as LayerChooserPluginId } from '@/plugins/layerChooser'
import type { resourcesEn as LayerChooserResources } from '@/plugins/layerChooser/locales'
import type { useLayerChooserStore as LayerChooserStore } from '@/plugins/layerChooser/store'
Expand Down Expand Up @@ -153,6 +156,7 @@
| typeof LoadingIndicatorId
| typeof PinsPluginId
| typeof PointerPositionPluginId
| typeof ReturnToInitialViewPluginId
| typeof ReverseGeocoderPluginId
| typeof RoutingPluginId
| typeof ScalePluginId
Expand All @@ -162,7 +166,7 @@
type GetPluginStore<
T extends BundledPluginId,
I extends BundledPluginId,
// TODO: This fixes the type error, but relaxes type-checking for the plugin store too much.

Check warning on line 169 in src/core/types/plugin.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO: This fixes the type error, but...'
// However, it is not clear if Pinia's type system allows for stronger checks at the moment.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
S extends PolarPluginStore<any>,
Expand All @@ -186,6 +190,11 @@
typeof PointerPositionPluginId,
typeof PointerPositionStore
>
| GetPluginStore<
T,
typeof ReturnToInitialViewPluginId,
typeof ReturnToInitialViewStore
>
| GetPluginStore<
T,
typeof ReverseGeocoderPluginId,
Expand Down Expand Up @@ -235,6 +244,11 @@
typeof PointerPositionPluginId,
typeof PointerPositionResources
>
| GetPluginResources<
T,
typeof ReturnToInitialViewPluginId,
typeof ReturnToInitialViewResources
>
| GetPluginResources<T, typeof RoutingPluginId, typeof RoutingResources>
| GetPluginResources<T, typeof ScalePluginId, typeof ScaleResources>
| GetPluginResources<T, typeof ToastPluginId, typeof ToastResources>
Expand Down
17 changes: 17 additions & 0 deletions src/plugins/initialView/components/ReturnToInitialView.ce.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<PolarIconButton
:hint="$t(($) => $.label.return, { ns: PluginId })"
icon="kern-icon--home"
tooltip-position="left"
@click="initialViewStore.returnToInitialView()"
/>
</template>

<script setup lang="ts">
import PolarIconButton from '@/components/PolarIconButton.ce.vue'

import { useInitialViewStore } from '../store'
import { PluginId } from '../types'

const initialViewStore = useInitialViewStore()
</script>
32 changes: 32 additions & 0 deletions src/plugins/initialView/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable tsdoc/syntax */
/**
* @module @polar/polar/plugins/returnToInitialView

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @module @polar/polar/plugins/returnToInitialView
* @module @polar/polar/plugins/initialView

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a

*/
/* eslint-enable tsdoc/syntax */

import type { PluginContainer, PolarPluginStore } from '@/core'
import type { InitialViewPluginOptions } from './types'

import component from './components/ReturnToInitialView.ce.vue'
import locales from './locales'
import { useInitialViewStore } from './store'
import { PluginId } from './types'

/**
* Creates a plugin which offers a button to return to the map's start view.
*
* @returns Plugin for use with {@link addPlugin}.
*/
export default function pluginInitialView(
options: InitialViewPluginOptions = {}
): PluginContainer {
return {
id: PluginId,
component,
locales,
storeModule: useInitialViewStore as PolarPluginStore,
options,
}
}

export * from './types'
32 changes: 32 additions & 0 deletions src/plugins/initialView/locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable tsdoc/syntax */
/**
* @module locales/plugins/returnToInitialView

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @module locales/plugins/returnToInitialView
* @module locales/plugins/initialView

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

56b870a94ef0116efd77b7064016a920dbf9640a

*/
/* eslint-enable tsdoc/syntax */

import type { Locale } from '@/core'

export const resourcesDe = {
label: {
return: 'Zurück zur Startansicht',
},
} as const

export const resourcesEn = {
label: {
return: 'Return to start view',
},
} as const

const locales: Locale[] = [
{
type: 'de',
resources: resourcesDe,
},
{
type: 'en',
resources: resourcesEn,
},
]

export default locales
31 changes: 31 additions & 0 deletions src/plugins/initialView/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineStore } from 'pinia'
import { computed } from 'vue'

import { useCoreStore } from '@/core/stores'

export const useInitialViewStore = defineStore('plugins/initialView', () => {
const coreStore = useCoreStore()

const startCenter = computed(() => coreStore.configuration.startCenter)

const startResolution = computed(
() => coreStore.configuration.startResolution
)

function returnToInitialView() {
coreStore.map.getView().setCenter(startCenter.value)
coreStore.map.getView().setResolution(startResolution.value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue states that zoom should be updated in order to reuse the existing animation function that eases the zoom. The zoom corresponding to the startResolution can be retrieved from coreStore.configuration.options as the parameter zoomLevel of the zoom option with the correct resolution.

}

function setupPlugin() {}

function teardownPlugin() {}

return {
startCenter,
startResolution,
returnToInitialView,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
returnToInitialView,
/** @alpha */
returnToInitialView,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e67cbc41a315aa8139834626a64f51e410043d9f

setupPlugin,
teardownPlugin,
Comment on lines +33 to +36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other plugins mark these as @internal so this plugin should do the same

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

922d69b391b7279bb0ef1f5f960b906db767159b

}
})
12 changes: 12 additions & 0 deletions src/plugins/initialView/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { PluginOptions } from '@/core'

export const PluginId = 'initialView' as const

export interface InitialViewPluginOptions extends PluginOptions {
/**
* Defines if the initialView button is rendered independent or as part of the
* icon menu.
* @defaultValue `'independent'`
*/
renderType?: 'independent' | 'iconMenu'
}
Comment on lines +5 to +12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • InitialView: Add plugin with a button to return to the initial map view #893 describes that the plugin should not receive any additional configuration options beside renderType.
  • A similar TSDoc comment for renderType like in GeoLocationPluginOptions should be added here.
  • startCenter is a required configuration option. Thus, it can always be retrieved from coreStore.configuration.startCenter
  • startResolution is an optional configuration option but it has a default value. Thusm it can always safely be retrieved from coreStore.configuration.startResolution

@JoselinGuevaraHoppe JoselinGuevaraHoppe Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading