Skip to content

Commit

Permalink
Bug fix for controls with decimal numbers failing and updating the di…
Browse files Browse the repository at this point in the history
…alog with the new value.
  • Loading branch information
cherneysp committed Jul 7, 2022
1 parent 926bc20 commit cb2ede8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/cc/ws/CtrlTiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -589,7 +590,12 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes)
boolean bReg;
bReg = !(sReg == null || sReg.compareTo("on") != 0);
if (sVal != null)
nControlValue = Integer.parseInt(sVal);
{
double dVal = Double.parseDouble(sVal);
if (sUnits.length > 0)
dVal = Units.getInstance().convert(sUnits[1], sUnits[0], dVal);
nControlValue = (int)Math.round(dVal);
}
else
{
sVal = oReq.getParameter("value1");
Expand All @@ -603,11 +609,7 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes)
else
nControlValue = Integer.parseInt(sVal);
}
if (sUnits.length > 0)
{
double dVal = Units.getInstance().convert(sUnits[1], sUnits[0], nControlValue);
nControlValue = (int)Math.round(dVal);
}

String sId = oReq.getParameter("id");
String sFile = g_sCtrlDir + sId + ".bin";
TrafCtrl oOriginalCtrl;
Expand Down Expand Up @@ -670,7 +672,17 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes)
for (String sValue : sVals)
sBuf.append("\"").append(sValue).append("\",");
sBuf.setLength(sBuf.length() - 1);
sBuf.append("]}");
sBuf.append("]");
if (TrafCtrlEnums.CTRLS[oCtrlToWrite.m_nControlType].length == 1)
{
double dDisplay = Double.parseDouble(sVals.get(1));
if (sUnits.length > 0)
{
dDisplay = Units.getInstance().convert(sUnits[0], sUnits[1], dDisplay);
}
sBuf.append(",\"display\":").append(new DecimalFormat("#.##").format(dDisplay));
}
sBuf.append("}");
try (PrintWriter oOut = oRes.getWriter())
{
oOut.append(sBuf);
Expand Down
1 change: 1 addition & 0 deletions web/script/map-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ function doneSaveEdit(oData)
oMapData.features[nSelectedId].properties.reg = oData.reg;
oMapData.features[nSelectedId].properties.label = oData.label;
oMapData.features[nSelectedId].properties.vtypes = oData.vtypes;
oMapData.features[nSelectedId].properties.display = oData.display;
oSrc.setData(oMapData);
console.log(oData.id);;
refreshVectorTiles();
Expand Down

0 comments on commit cb2ede8

Please sign in to comment.