vue-svg-pan-zoom/src/SvgPanZoom.vue

66 lines
1.5 KiB
Vue
Raw Normal View History

2018-01-15 23:40:59 +00:00
<template>
<div>
<slot />
<SvgPanZoomThumbnail v-if="has_thumbnail"
:onThumbnailShown="onThumbnailShown"
:mainSPZ="spz"
:bus="bus"
>
<slot name="thumbnail" />
</SvgPanZoomThumbnail>
</div>
2018-01-15 23:40:59 +00:00
</template>
<script>
import svg_pan_zoom from 'svg-pan-zoom';
import props from './props';
import { EventBus } from './EventBus';
2018-01-23 00:58:23 +00:00
import SvgPanZoomThumbnail from './SvgPanZoomThumbnail.vue';
2018-01-15 23:40:59 +00:00
export default {
props,
2018-01-23 00:58:23 +00:00
components: { SvgPanZoomThumbnail },
2018-01-15 23:57:05 +00:00
computed: {
2018-01-23 00:58:23 +00:00
has_thumbnail: function() { return this.$slots.thumbnail },
2018-01-15 23:57:05 +00:00
options: function() {
let options = {};
const is_defined = k => this[k] !== undefined;
Object.keys(props)
.filter( is_defined )
.forEach( k => options[k] = this[k] );
2018-01-15 23:40:59 +00:00
2018-01-15 23:57:05 +00:00
return options;
}
},
mounted: function() {
2018-01-23 00:58:23 +00:00
let options = {};
Object.keys(props).filter( k => this[k] !== undefined ).forEach( k => options[k] = this[k] );
options.onZoom = (...args) => {
this.bus.$emit( 'mainZoom' );
if( this.onZoom ) this.onZoom(args);
};
options.onPan = (...args) => {
this.bus.$emit( 'mainPan' );
if( this.onPan ) this.onPan(args);
};
this.spz = svg_pan_zoom( this.$slots.default[0].elm , options );
2018-03-16 16:24:59 +00:00
this.$emit( 'svgpanzoom', this.spz );
2018-01-15 23:40:59 +00:00
},
data: () => ({ spz: null, bus: EventBus() }),
2018-01-15 23:40:59 +00:00
};
</script>