heatmapColorGradient Change heatmap (gps path) based on pingms along path on each lat/long movement of device. (Ping test usecase)
Im looking to see if we can use heatmapColorGradient with results to change the heatmap color on the GPS path or along the device that is in path. so where ever we are moving we have a consistent ping going to a server but it would be cool to show red when ping is over >100ms range or >300ms and green between. I think i did the eval but to use maps+ i cant seem to get the colors to display along the GPS path track
|eval pingms = if(packetloss="100", "0", pingms) |timechart span=1m avg(pingms) as ping avg(latitude) as latitude avg(longitude) as longitude
|eval description=ping
|eval heatmapLayer="ping"
| eval normalized_ping = case(
ping = 0, 0,
ping <= 60, 1,
ping <= 90, 0.6 + (120 - ping) / 60 * 0.4,
ping <= 100, 0.4 + (300 - ping) / 180 * 0.2,
ping <= 600, 0.2 + (600 - ping) / 300 * 0.2,
1=1, 0.1
)
| eval heatmapColorGradient = case(
normalized_ping = 0, "{\"1\":\"red\", \"0.6\":\"orange\", \"0.4\":\"yellow\", \"0.2\":\"blue\", \"0.1\":\"green\"}",
normalized_ping <= 0.2, "{\"1\":\"orange\", \"0.6\":\"red\", \"0.4\":\"yellow\", \"0.2\":\"yellow\", \"0.1\":\"green\"}",
normalized_ping <= 0.4, "{\"1\":\"yellow\", \"0.6\":\"orange\", \"0.4\":\"red\", \"0.2\":\"yellow\", \"0.1\":\"green\"}",
normalized_ping <= 0.6, "{\"1\":\"blue\", \"0.6\":\"yellow\", \"0.4\":\"orange\", \"0.2\":\"red\", \"0.1\":\"green\"}",
normalized_ping > 0.6, "{\"1\":\"green\", \"0.6\":\"yellow\", \"0.4\":\"yellow\", \"0.2\":\"orange\", \"0.1\":\"red\"}"
)
i wonder if i might have to update the heatLayer.js to add another variable maybe we can add like like heatmapStatus i wonder if heatmapColorGradient is only 1 value it sees and not dynamic per drawing
https://github.com/sghaskell/maps-plus/blob/aae0cbff8c6b8bb78816fe52b927c2292c4ac511/appserver/static/visualizations/maps-plus/contrib/js/HeatLayer.js
// Example of extending the data model to include 'status'
initialize: function (latlngs, options) {
// Example latlngs format: [{lat: x, lng: y, alt: z, status: s}, ...]
this._latlngs = latlngs;
// ... rest of the initialization
},
// Example of customizing the gradient calculation based on 'status'
_redraw: function () {
// ... existing code to process points ...
for (let i = 0, len = grid.length; i < len; i++) {
// ... existing code to process grid cells ...
if (cell) {
let status = this._latlngs[i].status;
let color = this.getStatusBasedColor(status); // Custom function to determine color
data.push([
Math.round(cell[0]),
Math.round(cell[1]),
Math.min(cell[2], this._max),
color // Include color in the data
]);
}
}
// ... existing drawing code, modified to use the color ...
},
// Example of a custom function to determine color based on 'status'
getStatusBasedColor: function (status) {
// Implement logic to return a color based on the status value
// For example, return 'red' for high status, 'blue' for low status
},
Thanks for the detailed writeup. The approach here won't work as intended, but the good news is what you want is fully achievable today with a different Maps+ feature.
Why heatmapColorGradient can't do this:
The heatmap is a density visualization — heatmapColorGradient maps heat intensity to color across the entire layer. It doesn't support per-point colors. Even when set per-row in SPL, each row overwrites the previous row's gradient setting for the layer — the last row wins. There's no way to get individual point colors out of the heatmap feature.
What you actually want: a GPS path colored per-point by ping value. Here are two approaches that work today:
Option 1 — Circle markers with fillColor (simplest):
| eval markerType="circle"
| eval fillColor=case(
ping <= 60, "green",
ping <= 100, "yellow",
ping <= 300, "orange",
1=1, "red"
)
Each GPS point renders as a colored dot. Fast and easy to read.
Option 2 — Multiple path layers bucketed by ping tier:
Assign each row to a pathLayer based on ping range, then use pathColor per layer:
| eval pathLayer=case(
ping <= 60, "good",
ping <= 100, "warning",
ping <= 300, "degraded",
1=1, "bad"
)
| eval pathColor=case(
pathLayer="good", "green",
pathLayer="warning", "yellow",
pathLayer="degraded", "orange",
pathLayer="bad", "red"
)
This draws separate colored path segments per tier. Gaps will appear between tiers where ping crosses a threshold, but it gives a true path-style visualization.
Closing as this is an SPL/approach question rather than a missing feature — everything needed is already there.