Skip to content

Commit

Permalink
Merge pull request #1086 from geospoc/fix/container-undefined-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayakkulkarni authored Jul 7, 2022
2 parents f0e131e + 899c569 commit fada6eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
14 changes: 2 additions & 12 deletions src/layers/mapbox/VLayerMapboxGeojson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</div>
</template>
<script lang="ts">
import type { FeatureCollection } from 'geojson';
import type { AnyLayer, GeoJSONSourceRaw } from 'mapbox-gl';
import type { PropType, Ref } from 'vue';
import { defineComponent, onMounted, ref, watch } from 'vue';
Expand All @@ -24,7 +23,7 @@
required: true,
},
source: {
type: Object as PropType<FeatureCollection | GeoJSONSourceRaw>,
type: Object as PropType<GeoJSONSourceRaw>,
required: true,
},
layer: {
Expand All @@ -48,15 +47,6 @@
source: props.sourceId,
};
const source = () => {
// Assuming the source is FeatureCollection
if ('type' in props.source) {
return { type: 'geojson', data: props.source } as GeoJSONSourceRaw;
} else {
return props.source;
}
};
map.value.on('style.load', () => {
// /~https://github.com/mapbox/mapbox-gl-js/issues/2268#issuecomment-401979967
const styleTimeout = () => {
Expand Down Expand Up @@ -89,7 +79,7 @@
* @returns {void}
*/
function addLayer(): void {
map.value.addSource(props.sourceId, source());
map.value.addSource(props.sourceId, props.source);
map.value.addLayer(layer, props.before);
}
},
Expand Down
25 changes: 21 additions & 4 deletions src/map/VMap.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div :id="`${options.container}` || 'map'" class="v-map-container">
<div :id="getContainer()" class="v-map-container">
<slot />
</div>
</template>
Expand All @@ -26,9 +26,10 @@
let events: Ref<Array<keyof MapEventType>> = ref(mapEvents);
onMounted(() => {
const options = props.options.container
? props.options
: { ...props.options, container: 'map' };
const options =
'container' in props.options
? props.options
: { ...props.options, container: 'map' };
map.value = new Map(options);
loaded.value = true;
provide(MapKey, map);
Expand All @@ -55,6 +56,22 @@
});
});
}
/**
* Gets the container element
*
* @returns {string} - The container element id
*/
const getContainer = (): string => {
if (Object.keys(props.options).includes('container')) {
return `${props.options.container}`;
}
return 'map';
};
return {
getContainer,
};
},
});
</script>
Expand Down
17 changes: 2 additions & 15 deletions types/layers/mapbox/VLayerMapboxGeojson.vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// <reference types="@types/mapbox-gl" />
import type { FeatureCollection } from 'geojson';
import type { AnyLayer, GeoJSONSourceRaw } from 'mapbox-gl';
import type { PropType } from 'vue';
declare const _default: import('vue').DefineComponent<
Expand All @@ -15,13 +14,7 @@ declare const _default: import('vue').DefineComponent<
required: true;
};
source: {
type: PropType<
| FeatureCollection<
import('geojson').Geometry,
import('geojson').GeoJsonProperties
>
| GeoJSONSourceRaw
>;
type: PropType<GeoJSONSourceRaw>;
required: true;
};
layer: {
Expand Down Expand Up @@ -59,13 +52,7 @@ declare const _default: import('vue').DefineComponent<
required: true;
};
source: {
type: PropType<
| FeatureCollection<
import('geojson').Geometry,
import('geojson').GeoJsonProperties
>
| GeoJSONSourceRaw
>;
type: PropType<GeoJSONSourceRaw>;
required: true;
};
layer: {
Expand Down
4 changes: 3 additions & 1 deletion types/map/VMap.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ declare const _default: import('vue').DefineComponent<
default: () => {};
};
},
void,
{
getContainer: () => string;
},
unknown,
{},
{},
Expand Down

0 comments on commit fada6eb

Please sign in to comment.