Skip to content

Commit

Permalink
When using griddata annotations as heatmaps, allow setting scaleWithZoom
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Nov 25, 2024
1 parent 1a49e4a commit 6f96231
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Better detect files with geotransform data that aren't geospatial ([#1718](../../pull/1718))
- Better scale float-valued tiles ([#1725](../../pull/1725))
- Tile iterators now report their length ([#1730](../../pull/1730))
- When using griddata annotations as heatmaps, allow setting scaleWithZoom ([#1731](../../pull/1731))

### Changes

Expand Down
15 changes: 11 additions & 4 deletions girder_annotation/docs/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ near by values aggregate together when viewed.
# false, the rangeValues are in the
# value domain. Defaults to true. Optional
"scaleWithZoom": true # If true, scale the size of points with the zoom level of
# the map. Defaults to false. In this case, radius is in
# pixels of the associated image. If false or unspecified,
# radius is in screen pixels. Optional
# the map. In this case, radius is in pixels of the
# associated image. If false or unspecified, radius is in
# screen pixels. Defaults to false. Optional
}

Grid Data
Expand All @@ -211,7 +211,7 @@ choropleth, a grid with a list of values can be specified.
<id, label, group, user> # Optional general shape properties
"interpretation": "contour", # One of heatmap, contour, or choropleth
"gridWidth": 6, # Number of values across the grid. Required
"origin": [0, 0, 0], # Origin including fized x value. Optional
"origin": [0, 0, 0], # Origin including fixed z value. Optional
"dx": 32, # Grid spacing in x. Optional
"dy": 32, # Grid spacing in y. Optional
"colorRange": ["rgba(0, 0, 0, 0)", "rgba(255, 255, 0, 1)"], # A list of colors corresponding to
Expand All @@ -227,6 +227,13 @@ choropleth, a grid with a list of values can be specified.
"maxColor": "rgba(255, 255, 0, 1)", # The color of data above the maximum range. Optional
"stepped": true, # For contours, whether discrete colors or continuous colors
# should be used. Default false. Optional
"radius": 25, # Positive number. Optional. The size of the gaussian
# point when using the heatman interprettation
"scaleWithZoom": true # If true, when using the heatmap interprettation, scale
# the size of points with the zoom level of the map. In
# this case, radius is in pixels of the associated image.
# If false or unspecified, radius is in screen pixels.
# Defaults to false. Optional
"values": [
0.508,
0.806,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ class AnnotationSchema:
'exclusiveMinimum': 0,
'description': 'radius used for heatmap interpretation',
},
'scaleWithZoom': {
'type': 'boolean',
'description':
'If true, and interpreted as a heatmap, scale the size '
'of points with the zoom level of the map.',
},
'colorRange': colorRangeSchema,
'rangeValues': rangeValueSchema,
'normalizeRange': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ function convertGridToHeatmap(record, properties, layer) {
const dx = (record.dx || 1);
const dy = (record.dy || 1);
const colorTable = heatmapColorTable(record, record.values);
const tileLayer = map.layers().find((l) => l instanceof window.geo.tileLayer && l.options && l.options.maxLevel !== undefined);
const scaleZoomFactor = tileLayer ? 2 ** -tileLayer.options.maxLevel : 1;
const heatmap = heatmapLayer.createFeature('heatmap', {
style: {
radius: record.radius || 25,
radius: (record.radius || 25) * (record.scaleWithZoom ? scaleZoomFactor : 1),
blurRadius: 0,
gaussian: true,
color: colorTable.color
color: colorTable.color,
scaleWithZoom: record.scaleWithZoom || false
},
position: (d, i) => ({
x: x0 + dx * (i % record.gridWidth),
Expand Down

0 comments on commit 6f96231

Please sign in to comment.