Permalink
Browse files

Merge pull request #64 from orangesonappletrees/master

Dynamic hex radius for less cluttered map
  • Loading branch information...
ricki-z committed Sep 4, 2018
2 parents 5c6e898 + 769858b commit c015c230fb8f313138ce4784bdd18859d30126aa
Showing with 13 additions and 1 deletion.
  1. +12 −1 src/hexbin-layer.js
  2. +1 −0 src/places.js
View
@@ -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
@@ -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)
View
@@ -305,6 +305,7 @@ module.exports = {
// Ireland
"ireland": [53.1333,-8.1167],
"dublin": [53.3425,-6.2658],
"sligo": [54.276790, -8.474551],
// Italy
"italy": [42,12],

1 comment on commit c015c23

@YaguraStation

This comment has been minimized.

Show comment
Hide comment
@YaguraStation

YaguraStation Sep 6, 2018

Awesome job - looking really good!

YaguraStation commented on c015c23 Sep 6, 2018

Awesome job - looking really good!

Please sign in to comment.