Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic hex radius for less cluttered map #64

Merged
merged 3 commits into from Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/hexbin-layer.js
Expand Up @@ -39,6 +39,17 @@ L.HexbinLayer = L.Layer.extend({
.clamp(true)
},

// Make hex radius dynamic for different zoom levels to give a nicer overview of the sensors as well as making sure that the hex grid does not cover the whole world when zooming out
getFlexRadius () {
if (this.map.getZoom() < 3) {
return this.options.radius / (3 * (4 - this.map.getZoom()))
} else if (this.map.getZoom() > 2 && this.map.getZoom() < 8) {
return this.options.radius / (9 - this.map.getZoom())
} else {
return this.options.radius
}
},

onAdd (map) {
this.map = map
let _layer = this
Expand Down Expand Up @@ -174,7 +185,7 @@ L.HexbinLayer = L.Layer.extend({
_createHexagons(g, data, projection) {
// Create the bins using the hexbin layout
let hexbin = d3.hexbin()
.radius(this.options.radius / projection.scale)
.radius(this.getFlexRadius() / projection.scale)
.x( (d) => d.point.x )
.y( (d) => d.point.y )
let bins = hexbin(data)
Expand Down
1 change: 1 addition & 0 deletions src/places.js
Expand Up @@ -305,6 +305,7 @@ module.exports = {
// Ireland
"ireland": [53.1333,-8.1167],
"dublin": [53.3425,-6.2658],
"sligo": [54.276790, -8.474551]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line should end with a comma (and this commit should be moved to a separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. The places update was not supposed to be part of this PR.


// Italy
"italy": [42,12],
Expand Down