properly setup base sizing for MapZoom & add method to reset the base transform
This commit is contained in:
@@ -14,17 +14,17 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { select, zoom } from 'd3'
|
import { select, zoom, zoomIdentity } from 'd3'
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MapZoom',
|
name: 'MapZoom',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: Object, default: () => ({ width: undefined, height: undefined }) },
|
|
||||||
id: { type: String, required: true },
|
id: { type: String, required: true },
|
||||||
minZoom: { type: Number, default: 0.3 },
|
minZoom: { type: Number, default: 0.3 },
|
||||||
maxZoom: { type: Number, default: 1 }
|
maxZoom: { type: Number, default: 1 },
|
||||||
|
initialZoom: { type: Number, default: 1 }
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
@@ -33,8 +33,8 @@ export default {
|
|||||||
svg: undefined, // d3 select(svg)
|
svg: undefined, // d3 select(svg)
|
||||||
width: undefined,
|
width: undefined,
|
||||||
height: undefined,
|
height: undefined,
|
||||||
scale: 1,
|
scale: this.initialZoom,
|
||||||
transform: 'translate(0, 0) scale(1)'
|
transform: zoomIdentity.translate(0, 0).scale(this.initialZoom)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -55,6 +55,11 @@ export default {
|
|||||||
|
|
||||||
onZoom (direction) {
|
onZoom (direction) {
|
||||||
this.zoom.scaleBy(this.svg, direction === 1 ? 1.3 : 1 / 1.3, [0, 0])
|
this.zoom.scaleBy(this.svg, direction === 1 ? 1.3 : 1 / 1.3, [0, 0])
|
||||||
|
},
|
||||||
|
|
||||||
|
reset () {
|
||||||
|
this.transform = zoomIdentity.translate(0, 0).scale(this.initialZoom)
|
||||||
|
this.svg.call(this.zoom.transform, this.transform)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -68,7 +73,7 @@ export default {
|
|||||||
|
|
||||||
this.updateSize()
|
this.updateSize()
|
||||||
this.svg = select('#' + this.id + ' svg')
|
this.svg = select('#' + this.id + ' svg')
|
||||||
this.svg.call(this.zoom)
|
this.svg.call(this.zoom).call(this.zoom.transform, this.transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user