Skip to content

Instantly share code, notes, and snippets.

@AlexDoanTB
Created December 3, 2019 15:12
Show Gist options
  • Select an option

  • Save AlexDoanTB/c4cdef5d7cb3aa087e7a25433f7d27ba to your computer and use it in GitHub Desktop.

Select an option

Save AlexDoanTB/c4cdef5d7cb3aa087e7a25433f7d27ba to your computer and use it in GitHub Desktop.
This is a file with scripts for ThingsBoard Map widget configuration video guide
Temperature generator (for Thermometer)
var msg = { temperature: +(Math.random()*6 + 25).toFixed(1)};
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, msgType: msgType };
_____________________________________________________________
Telemetry generator (for Asset)
var msg = { temperature: +(Math.random()*6 + 25).toFixed(1)};
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, msgType: msgType };
_____________________________________________________________
Energy consumption generator (for Energy meter)
var energyValue = +(Math.random()/100).toFixed(4);
energyValue = prevMsg.energy + energyValue;
var msg = { energy: energyValue};
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, msgType: msgType };
_____________________________________________________________
Label style configuration
<div style="position: relative; white-space: nowrap; text-aling:
center; font-size: 14px; top: 5px;">
<span style="border: 2px solid #000; border-radius: 10px;
color: #000; background-color: #fff; padding-left: 5px; padding-right:
5px; padding-top: 3px; padding-bottom: 3px;">${entityName}</span>
</div>
_____________________________________________________________
Tooltip configuration
<b>${entityName}</b><br/><br/><b>Latitude:</b> ${latitude:7}<br/><b>Longitude:
</b> ${longitude:7}<br/><b>Temperature:</b> ${temperature} °C<br/>
<b>Energy:</b> ${energy:2} kW<br/><br/>
<link-act name='Sensor_details'>${entityName} details</link-act><br/>
_______________________________________________________________
Tooltip function (to show required data for different entity types on the same map)
var deviceType = dsData[dsIndex]['$datasource'].entity.type;
if (typeof deviceType !== undefined) {
if (deviceType == "energy meter") {
return '<b>${entityName}</b><br/><br/><b>Latitude:</b> ${latitude:7}<br/><b>Longitude:</b> ${longitude:7}<br/><b><b>Energy:</b> ${energy:2} kW<br/><br/><link-act name="Sensor_details">${entityName} details</link-act><br/>';
} else if (deviceType == "thermometer") {
return '<b>${entityName}</b><br/><br/><b>Latitude:</b> ${latitude:7}<br/><b>Longitude:</b> ${longitude:7}<br/><b><b>Temperature:</b> ${temperature} °C<br/><br/><link-act name="Sensor_details">${entityName} details</link-act><br/>';
}
}
________________________________________________________________
Use color function example (change marker color when the threshold is violated)
var temperature = dsData[dsIndex]['temperature']
if (temperature >=26) {
return "red";
} else {
return "green";
}
__________________________________________________________________
Polygon color function (change polygon color when the threshold is violated)
var temperature = dsData[dsIndex]['temperature']
if (temperature >=26) {
return "red";
} else {
return "green";
}
___________________________________________________________________
Use marker image function example (marker changing based on certain conditions)
var temperature = dsData[dsIndex]['temperature'];
var res = {size: 80};
if (temperature >= 26) {
res.url = images[0];
} else {
res.url = images[1];
}
return res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment