diff --git a/src/composables/useOpenLayersEvents.ts b/src/composables/useOpenLayersEvents.ts index acf5699..fd88e87 100644 --- a/src/composables/useOpenLayersEvents.ts +++ b/src/composables/useOpenLayersEvents.ts @@ -9,6 +9,7 @@ import { } from "vue"; import type BaseObject from "ol/Object"; import type { EventTypes } from "ol/Observable"; +import type { Vue3OpenlayersGlobalOptions } from "@/types"; export const COMMON_EVENTS = ["change", "error", "propertychange"]; @@ -47,7 +48,6 @@ export const FEATURE_EVENTS = [ "removefeature", ]; -// Define the composable function export function useOpenLayersEvents( feature: | BaseObject @@ -57,7 +57,12 @@ export function useOpenLayersEvents( eventNames: string[], ) { const instance = getCurrentInstance(); - const globalOptions = inject("ol-options"); + let globalOptions: Vue3OpenlayersGlobalOptions = { + debug: false, + }; + if (instance) { + globalOptions = inject("ol-options"); + } function updateOpenLayersEventHandlers() { ([...COMMON_EVENTS, ...eventNames] as EventTypes[]).forEach((eventName) => { @@ -83,9 +88,11 @@ export function useOpenLayersEvents( }); } - onMounted(() => { - updateOpenLayersEventHandlers(); - }); + if (instance) { + onMounted(() => { + updateOpenLayersEventHandlers(); + }); + } return { updateOpenLayersEventHandlers, diff --git a/src/composables/usePropsAsObjectProperties.ts b/src/composables/usePropsAsObjectProperties.ts index b04abce..74f6b95 100644 --- a/src/composables/usePropsAsObjectProperties.ts +++ b/src/composables/usePropsAsObjectProperties.ts @@ -1,4 +1,11 @@ -import { inject, reactive, type UnwrapNestedRefs, toRefs } from "vue"; +import { + inject, + reactive, + type UnwrapNestedRefs, + toRefs, + getCurrentInstance, +} from "vue"; +import type { Vue3OpenlayersGlobalOptions } from "@/types"; type OlClassOptions = T extends { styles: infer S } ? { style: S } & Omit @@ -22,7 +29,13 @@ function checkAndUpdateStylePropDef>( export default function usePropsAsObjectProperties< T extends Record, >(props: T): UnwrapNestedRefs> { - const globalOptions = inject("ol-options"); + const instance = getCurrentInstance(); + let globalOptions: Vue3OpenlayersGlobalOptions = { + debug: false, + }; + if (instance) { + globalOptions = inject("ol-options"); + } const revisedProps = checkAndUpdateStylePropDef(props);