Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b54e416
feat(initialView): add initial view plugin
LivMoeser Jul 29, 2026
aea2ee3
Merge branch 'next' of https://github.com/Dataport/polar into next
LivMoeser Jul 29, 2026
396b606
feat(initialView): change to one-button application
LivMoeser Jul 30, 2026
004ab9d
Merge branch 'next' of https://github.com/Dataport/polar into next
LivMoeser Jul 30, 2026
af11964
fix(initialView): move comment to variable in types.ts
JoselinGuevaraHoppe Jul 31, 2026
6b517b4
fix(initialView): get startCenter and startResolution via core config…
JoselinGuevaraHoppe Jul 31, 2026
b823a80
fix(initialView): rename "initialViewStore" according ro camelCase
JoselinGuevaraHoppe Jul 31, 2026
236bc0c
fix(initialView): inline function
JoselinGuevaraHoppe Jul 31, 2026
949c299
fix(initialView): delete unused value
JoselinGuevaraHoppe Jul 31, 2026
56b870a
fix(initialView): rename "returnToInitialView" to "initialView"
JoselinGuevaraHoppe Aug 3, 2026
e67cbc4
fix(initialView): comment @aplha in store
JoselinGuevaraHoppe Aug 3, 2026
922d69b
fix(initialView): comment @internal in store
JoselinGuevaraHoppe Aug 3, 2026
38d6aac
feat(initialView): add tests to store
LivMoeser Aug 3, 2026
f96fb95
Merge branch 'feat(initialView)' of https://github.com/Dataport/polar…
LivMoeser Aug 3, 2026
29e7076
fix(initialView): fix comment @alpha in store
JoselinGuevaraHoppe Aug 3, 2026
8a226bc
feat(core): remove readonly restriction
JoselinGuevaraHoppe Aug 3, 2026
c477d2c
fix(initialView): change returnToInitialView to reference to coreStor…
JoselinGuevaraHoppe Aug 3, 2026
ee1a583
fix: move plugin "initialView" to iconMenu
JoselinGuevaraHoppe Aug 3, 2026
0399d64
fix(initialView): add tooltip-position to store
LivMoeser Aug 3, 2026
80ca013
Merge branch 'feat(initialView)' of https://github.com/Dataport/polar…
LivMoeser Aug 3, 2026
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'
Comment thread
dopenguin marked this conversation as resolved.
Outdated
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 thread
dopenguin marked this conversation as resolved.
Outdated
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. */
Comment thread
dopenguin marked this conversation as resolved.
Outdated
returnToInitialView?: InitialViewPluginOptions
Comment thread
dopenguin marked this conversation as resolved.
Outdated

/** 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'
Comment thread
dopenguin marked this conversation as resolved.
Outdated
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
21 changes: 21 additions & 0 deletions src/plugins/initialView/components/ReturnToInitialView.ce.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<PolarIconButton
:hint="$t(($) => $.label.return, { ns: PluginId })"
icon="kern-icon--home"
tooltip-position="left"
@click="onClick"
Comment thread
dopenguin marked this conversation as resolved.
Outdated
/>
</template>

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

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

const InitialViewStore = useInitialViewStore()
Comment thread
dopenguin marked this conversation as resolved.
Outdated

function onClick() {
InitialViewStore.returnToInitialView()
}
</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
Comment thread
dopenguin marked this conversation as resolved.
Outdated
*/
/* 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'
34 changes: 34 additions & 0 deletions src/plugins/initialView/locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable tsdoc/syntax */
/**
* @module locales/plugins/returnToInitialView
Comment thread
dopenguin marked this conversation as resolved.
Outdated
*/
/* eslint-enable tsdoc/syntax */

import type { Locale } from '@/core'

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

export const resourcesEn = {
title: 'Return to Start View',
Comment thread
dopenguin marked this conversation as resolved.
Outdated
label: {
return: 'Return to start view',
},
} as const

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

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

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

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

const viewCenter = coreStore.map.getView().getCenter() as
[number, number] | undefined
const viewResolution = coreStore.map.getView().getResolution()

const initialCenter = coreStore.configuration.returnToInitialView
?.startCenter ??
viewCenter ?? [0, 0]

const initialResolution =
coreStore.configuration.returnToInitialView?.startResolution ??
viewResolution ??
1

const startCenter = ref(initialCenter)
const startResolution = ref(initialResolution)

function returnToInitialView() {
coreStore.map.getView().setCenter(startCenter.value)
coreStore.map.getView().setResolution(startResolution.value)
Comment thread
dopenguin marked this conversation as resolved.
Outdated
}

function setupPlugin() {
const options = coreStore.configuration.returnToInitialView
if (options?.startCenter) {
startCenter.value = options.startCenter
}
if (options?.startResolution) {
startResolution.value = options.startResolution
}
}

function teardownPlugin() {}

return {
startCenter,
startResolution,
returnToInitialView,
Comment thread
dopenguin marked this conversation as resolved.
setupPlugin,
teardownPlugin,
Comment thread
dopenguin marked this conversation as resolved.
}
})
15 changes: 15 additions & 0 deletions src/plugins/initialView/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Defines if the geoLocation button is rendered independent or as part of the
* icon menu.
* @defaultValue `'independent'`
*/

Comment thread
dopenguin marked this conversation as resolved.
Outdated
import type { PluginOptions } from '@/core'

export const PluginId = 'initialView' as const

export interface InitialViewPluginOptions extends PluginOptions {
renderType?: 'independent' | 'iconMenu'
startCenter?: [number, number]
startResolution?: number
}
Comment thread
dopenguin marked this conversation as resolved.
Loading