Skip to content

Commit

Permalink
some type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
razorness committed Aug 9, 2023
1 parent c6811b6 commit 92214f8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/lib/components/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ export default /*#__PURE__*/ defineComponent({
setup(props, ctx) {

const component = markRaw(getCurrentInstance()!),
container = shallowRef<HTMLDivElement | null>(null),
map = shallowRef<MaplibreMap | null>(null),
container = shallowRef<HTMLDivElement>(),
map = shallowRef<MaplibreMap>(),
isInitialized = ref(false),
isLoaded = ref(false),
isStyleReady = ref(false),
boundMapEvents = new Map<string, Function>(),
emitter = mitt<MglEvents>(),
registryItem = registerMap(component as any, props.mapKey);
registryItem = registerMap(component as any, map, props.mapKey);

let resizeObserver: ResizeObserver | undefined;

Expand Down Expand Up @@ -307,6 +307,8 @@ export default /*#__PURE__*/ defineComponent({

});

ctx.expose({ map });

return () => h(
'div',
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/composable/usePositionWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ShallowRef, watch } from 'vue';
import { IControl, Map } from 'maplibre-gl';
import { Position, PositionProp, PositionValues } from '@/lib/components/controls/position.enum';

export function usePositionWatcher(source: WatchSource<PositionProp | undefined>, map: ShallowRef<Map | null>, control: IControl) {
export function usePositionWatcher(source: WatchSource<PositionProp | undefined>, map: ShallowRef<Map | undefined>, control: IControl) {
watch(source, (v) => {
if (v && PositionValues.indexOf(v as Position) === -1) {
return;
Expand Down
9 changes: 5 additions & 4 deletions src/lib/lib/mapRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MglMap } from '@/lib/components';
import maplibregl from 'maplibre-gl';
import { reactive } from 'vue';
import { reactive, ShallowRef } from 'vue';
import { ValidLanguages } from '@/lib/types';

export interface MapInstance {
Expand All @@ -24,17 +24,18 @@ export function useMap(key: symbol | string = defaultKey): MapInstance {
return component;
}

export function registerMap(instance: InstanceType<typeof MglMap>, key: symbol | string = defaultKey): MapInstance {
export function registerMap(instance: InstanceType<typeof MglMap>, map: ShallowRef<maplibregl.Map | undefined>, key: symbol | string = defaultKey): MapInstance {
let component = instances.get(key);
if (!component) {
component = reactive({ isLoaded: false, isMounted: false, language: null });
instances.set(key, component);
}

component.isLoaded = false;
component.isMounted = false;
component.component = instance;
component.map = instance.map as maplibregl.Map;
component.isLoaded = (instance.map as maplibregl.Map)?.loaded() || false;
component.map = map.value;
component.isLoaded = map.value?.loaded() || false;

return component;
}
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MglMap } from '@/lib/components';
import { Emitter } from 'mitt';
import { SourceLayerRegistry } from '@/lib/lib/sourceLayer.registry';

export const mapSymbol = Symbol('map') as InjectionKey<ShallowRef<Map | null>>,
export const mapSymbol = Symbol('map') as InjectionKey<ShallowRef<Map | undefined>>,
isLoadedSymbol = Symbol('isLoaded') as InjectionKey<Ref<boolean>>,
isInitializedSymbol = Symbol('isInitialized') as InjectionKey<Ref<boolean>>,
componentIdSymbol = Symbol('componentId') as InjectionKey<number>,
Expand Down

0 comments on commit 92214f8

Please sign in to comment.