Skip to content

Commit fada6eb

Browse files
Merge pull request #1086 from geospoc/fix/container-undefined-issue
2 parents f0e131e + 899c569 commit fada6eb

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

src/layers/mapbox/VLayerMapboxGeojson.vue

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
</div>
55
</template>
66
<script lang="ts">
7-
import type { FeatureCollection } from 'geojson';
87
import type { AnyLayer, GeoJSONSourceRaw } from 'mapbox-gl';
98
import type { PropType, Ref } from 'vue';
109
import { defineComponent, onMounted, ref, watch } from 'vue';
@@ -24,7 +23,7 @@
2423
required: true,
2524
},
2625
source: {
27-
type: Object as PropType<FeatureCollection | GeoJSONSourceRaw>,
26+
type: Object as PropType<GeoJSONSourceRaw>,
2827
required: true,
2928
},
3029
layer: {
@@ -48,15 +47,6 @@
4847
source: props.sourceId,
4948
};
5049
51-
const source = () => {
52-
// Assuming the source is FeatureCollection
53-
if ('type' in props.source) {
54-
return { type: 'geojson', data: props.source } as GeoJSONSourceRaw;
55-
} else {
56-
return props.source;
57-
}
58-
};
59-
6050
map.value.on('style.load', () => {
6151
// https://github.com/mapbox/mapbox-gl-js/issues/2268#issuecomment-401979967
6252
const styleTimeout = () => {
@@ -89,7 +79,7 @@
8979
* @returns {void}
9080
*/
9181
function addLayer(): void {
92-
map.value.addSource(props.sourceId, source());
82+
map.value.addSource(props.sourceId, props.source);
9383
map.value.addLayer(layer, props.before);
9484
}
9585
},

src/map/VMap.vue

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div :id="`${options.container}` || 'map'" class="v-map-container">
2+
<div :id="getContainer()" class="v-map-container">
33
<slot />
44
</div>
55
</template>
@@ -26,9 +26,10 @@
2626
let events: Ref<Array<keyof MapEventType>> = ref(mapEvents);
2727
2828
onMounted(() => {
29-
const options = props.options.container
30-
? props.options
31-
: { ...props.options, container: 'map' };
29+
const options =
30+
'container' in props.options
31+
? props.options
32+
: { ...props.options, container: 'map' };
3233
map.value = new Map(options);
3334
loaded.value = true;
3435
provide(MapKey, map);
@@ -55,6 +56,22 @@
5556
});
5657
});
5758
}
59+
60+
/**
61+
* Gets the container element
62+
*
63+
* @returns {string} - The container element id
64+
*/
65+
const getContainer = (): string => {
66+
if (Object.keys(props.options).includes('container')) {
67+
return `${props.options.container}`;
68+
}
69+
return 'map';
70+
};
71+
72+
return {
73+
getContainer,
74+
};
5875
},
5976
});
6077
</script>

types/layers/mapbox/VLayerMapboxGeojson.vue.d.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference types="@types/mapbox-gl" />
2-
import type { FeatureCollection } from 'geojson';
32
import type { AnyLayer, GeoJSONSourceRaw } from 'mapbox-gl';
43
import type { PropType } from 'vue';
54
declare const _default: import('vue').DefineComponent<
@@ -15,13 +14,7 @@ declare const _default: import('vue').DefineComponent<
1514
required: true;
1615
};
1716
source: {
18-
type: PropType<
19-
| FeatureCollection<
20-
import('geojson').Geometry,
21-
import('geojson').GeoJsonProperties
22-
>
23-
| GeoJSONSourceRaw
24-
>;
17+
type: PropType<GeoJSONSourceRaw>;
2518
required: true;
2619
};
2720
layer: {
@@ -59,13 +52,7 @@ declare const _default: import('vue').DefineComponent<
5952
required: true;
6053
};
6154
source: {
62-
type: PropType<
63-
| FeatureCollection<
64-
import('geojson').Geometry,
65-
import('geojson').GeoJsonProperties
66-
>
67-
| GeoJSONSourceRaw
68-
>;
55+
type: PropType<GeoJSONSourceRaw>;
6956
required: true;
7057
};
7158
layer: {

types/map/VMap.vue.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ declare const _default: import('vue').DefineComponent<
99
default: () => {};
1010
};
1111
},
12-
void,
12+
{
13+
getContainer: () => string;
14+
},
1315
unknown,
1416
{},
1517
{},

0 commit comments

Comments
 (0)