Calculation from user input

341
1
08-05-2022 10:08 AM
Labels (2)
JoseBaene
New Contributor

Hello All!

I have a score which is calculated by combining multiple fields in the layer multiplied by a parameter for each one:

Score = a * Field1 + b*Field2 + c*Field3

Is there a way for the user to edit values of a, b and c so that the score can be recalculated on the Application and the metrics and map are updated. I'm thinking on using Data Expressions but I don't se the option of getting user input.

Thanks

1 Reply
AdamCollins4
New Contributor

Hi Jose, 

I am working on a similar issue where I would like the user to input values as weights for a multiple criteria analysis. I don't have a full solution but am thinking about using sliders in a custom app with calcite or Jimu-UI, I have put this together in the code snippet below but I am not sure how I would connect the value returned in the slider to the attributes. 

import { CalciteButton, CalciteIcon, CalciteSlider } from 'calcite-components'

const Widget = (props: AllWidgetProps<IMConfig>) => {
  const text = props.config.text

  const [sliderValue0, setSliderValue0] = React.useState(0)

  return (
    <div className="widget-calcite jimu-widget m-2">
      <div className="App">
        <h1>Hello, {text}</h1>
        <CalciteButton>Test</CalciteButton>
        <CalciteSlider
          min={0}
          max={100}
          value={sliderValue0}
          step={10}
          onCalciteSliderUpdate={(e) => setSliderValue0((e.target as 
           any).value)} />
        <p>The slider currently has a value of {sliderValue0}</p>

I think there is a solution in here but I'm not sure how it would be implemented. Hopefully my response will inspire others to discuss!  

Thanks