Skip to content

Commit

Permalink
Implement landarea selection brush
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobrasolin committed Jan 23, 2024
1 parent e24edb3 commit 5cb8260
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/controllers/map_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,33 @@ export default class extends Controller {
.append("path")
.attr("d", geoGenerator);

this.svg.append("g").attr("id", "hexbins");
this.hexbin = hexbin().radius(6).extent(extent);

const brush = d3
.brush()
.extent(extent)
.on("start brush end", this.handleBrush.bind(this));

this.svg
.append("g")
.attr("id", "mapBrush")
.call(brush)
.call(brush.move, null);
}

handleBrush(event: d3.D3BrushEvent<unknown>) {
const landarea: [[number, number], [number, number]] | null =
event.selection
? [
this.projection.invert!(event.selection[0] as [number, number])!,
this.projection.invert!(event.selection[1] as [number, number])!,
]
: null;

this.dispatch("landareaChanged", {
detail: { landarea },
});
}

disconnect() {}
Expand All @@ -84,8 +110,6 @@ export default class extends Controller {
return { ...d, x, y };
});
this.redrawheat();

this.svg.append("g").attr("id", "hexbins");
}

updateWordlist({
Expand Down

0 comments on commit 5cb8260

Please sign in to comment.