function zoomable(mapContainer) {
let sync = true;
let ease = zoomableDefaults.ease;
const zoomSymbol = Symbol('zoomable');
const zoom = d3.zoom()
.duration(zoomableDefaults.duration)
.scaleExtent(zoomableDefaults.scaleExtent)
.extent(zoomableDefaults.extent)
.translateExtent(zoomableDefaults.extent);
function zoomable(selection, name) {
const mapGroup = mapContainer(selection);
zoom.on(`zoom.usmap-base${name && `-${name}`}`, function () {
const { transform } = d3.event;
const el = this;
if (sync) {
mapGroup.attr('transform', transform);
selection.each(function () { if (this !== el) this.__zoom = transform });
} else {
d3.select(el).select('g.usMap').attr('transform', transform);
}
});
selection.each(function () {
if (!this[zoomSymbol]) {
d3.select(this)
.call(zoom)
.append('rect')
.attr('width', usMapViewBox[0])
.attr('height', usMapViewBox[1])
.attr('fill', 'none')
.attr('pointer-events', 'visible')
.lower();
this[zoomSymbol] = true;
}
});
return mapGroup;
}
Object.assign(assignAllMethods(zoom, zoomable), mapContainer);
zoomable.clear = function (selection) {
zoomable
.ease(zoomableDefaults.ease)
.duration(zoomableDefaults.duration)
.scaleExtent(zoomableDefaults.scaleExtent)
.extent(zoomableDefaults.extent)
.translateExtent(zoomableDefaults.translateExtent);
selection.on('.zoom', null);
selection.on('click.zoomReset', null);
selection.each(function () { this[zoomSymbol] = undefined });
return this;
};
zoomable.sync = function (_) { return _ === undefined ? sync : (sync = _, this); }
zoomable.ease = function (_) { return _ === undefined ? ease : (ease = _, this); }
return zoomable;
}