Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
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
194 changes: 20 additions & 174 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"bundle": "rollup -c build/rollup.config.ts",
"bundle:min": "rollup -c build/rollup.config.min.ts",
"build:dts": "vue-tsc --declaration --emitDeclarationOnly --skipLibCheck && npm run lintfix",
"prepare": "husky install",
"prepare": "husky install && npm run build",
"docs:dev": "vuepress dev docs --port 3000",
"docs:build": "vuepress build docs",
"lint": "npm run lint:prettier && npm run lint:eslint && npm run lint:css",
Expand Down
5 changes: 3 additions & 2 deletions src/controls/VControlGeolocate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { injectStrict, MapKey } from '../utils';
export default defineComponent({
name: 'VControlFullscreen',
name: 'VControlGeolocate',
props: {
options: {
type: Object as PropType<{
Expand All @@ -18,7 +18,7 @@
showUserLocation?: boolean;
}>,
default: () => ({}),
required: true,
required: false,
},
position: {
type: String as PropType<
Expand Down Expand Up @@ -50,5 +50,6 @@
});
}
},
render: () => [],
});
</script>
2 changes: 1 addition & 1 deletion src/controls/VControlNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { injectStrict, MapKey } from '../utils';

export default defineComponent({
name: 'VControlFullscreen',
name: 'VControlNavigation',
props: {
options: {
type: Object as PropType<{
Expand Down
2 changes: 1 addition & 1 deletion src/controls/VControlScale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { injectStrict, MapKey } from '../utils';

export default defineComponent({
name: 'VControlFullscreen',
name: 'VControlScale',
props: {
options: {
type: Object as PropType<{ maxWidth?: number; unit?: string }>,
Expand Down
59 changes: 25 additions & 34 deletions src/layers/mapbox/VLayerMapboxGeojson.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</template>
<script lang="ts">
import type { AnyLayer, GeoJSONSourceRaw } from 'mapbox-gl';
import type { PropType, Ref } from 'vue';
import { defineComponent, onMounted, ref, watch } from 'vue';
import type { PropType } from 'vue';
import { defineComponent, onMounted, onUnmounted, watch } from 'vue';
import { injectStrict, MapKey } from '../../utils';
export default defineComponent({
Expand Down Expand Up @@ -36,52 +36,43 @@
default: '',
required: false,
},
visible: {
type: Boolean as PropType<boolean>,
default: true,
required: false,
},
},
setup(props) {
let map = injectStrict(MapKey);
let loaded: Ref<boolean> = ref(false);
const layer = {
...props.layer,
id: props.layerId,
source: props.sourceId,
};
map.value.on('style.load', () => {
// https://github.com/mapbox/mapbox-gl-js/issues/2268#issuecomment-401979967
const styleTimeout = () => {
if (!map.value.isStyleLoaded()) {
loaded.value = false;
setTimeout(styleTimeout, 200);
} else {
loaded.value = true;
}
};
styleTimeout();
});
/**
* Watcher(s)
*/
watch(loaded, (value) => {
if (value) {
addLayer();
}
onMounted(() => {
map.value.addSource(props.sourceId, props.source);
map.value.addLayer(layer, props.before);
});
onMounted(() => {
addLayer();
onUnmounted(() => {
if (map.value.getLayer(props.layerId))
map.value.removeLayer(props.layerId);
if (map.value.getSource(props.sourceId))
map.value.removeSource(props.sourceId);
});
/**
* Re–adds the layer when style changed
*
* @returns {void}
*/
function addLayer(): void {
map.value.addSource(props.sourceId, props.source);
map.value.addLayer(layer, props.before);
}
watch(
() => props.visible,
(visible) => {
map.value.setLayoutProperty(
props.layerId,
'visibility',
visible ? 'visible' : 'none',
);
},
);
},
});
</script>
Loading