Select to view content in your preferred language

Create a renderer using Arcade Expressions

1728
17
01-31-2019 09:22 AM
HushamMohamed
Occasional Contributor

I am creating simple election map,  that visualize the result over the county by  Some election races, which I listed them on accordion Panel.  I tried to follow this  example , to render the feature layer. I failed to Add the following

1- Add on Click Events on the Race Accordion header then render the map according. by replacing the field names in the Arcade Expression

(on console log I was able to get all the fields name)

2-  instead of placing the arcade expression on the HTML file (script tag)  How can I add it to my separated js file(script.js).

I do appreciate your help.

Attaching my code so far.

0 Kudos
17 Replies
XanderBakker
Esri Esteemed Contributor

When you use Decode the second parameter is an array. So please try the following expression:

            var republican = $feature.Candidate12;
            var democrat = $feature.Candidate10;
            var independent = $feature.Candidate11;
            var WriteIn = $feature.Candidate72;
            var parties = [republican, democrat, independent,WriteIn];
          
            return Decode(Max(parties),[
              republican, 'republican',
              democrat, 'democrat',
              independent, 'Libertarian'],
              'n/a');
0 Kudos
HushamMohamed
Occasional Contributor

thanks Xander,  Yes that is exactly what i have. So  Can you help with this 2 issue,

1- Add on Click Events on the Race Accordion header then render the map according,  by replacing the field names in the Arcade Expression

(on console log I was able to get all the fields name as an array)

2-  instead of placing the arcade expression on the HTML file (script tag)  How can I add it to my separated js file(script.js).

Regards

0 Kudos
XanderBakker
Esri Esteemed Contributor

I just had another look at the documentation on the Decode function and I think that my suggestion was wrong. No square brackets are used. So ,sorry for that. 

I am not a JavaScript API progarmmer, so I think best I can do is to tag someone that is: Robert Scheitlin, GISP

0 Kudos
HushamMohamed
Occasional Contributor

OH,  thank you for the correction, and tagging  Robert,

Hope to hear from him soon.

Regards

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Husham,

   I think the purpose of putting it into the HTML script tag is that the var is global in nature. I have never gone down this path but I assume you could try and attach the var to the global window var and see if that works.

0 Kudos
HushamMohamed
Occasional Contributor

Thank you,  Robert

I already tried that without any success.

I am still trying,  Please share if you came with any solution or sample.

Regards

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

You could could have your JS file inject a script tag using:

var s = document.createElement('script');
s.type = 'text/javascript';‍‍
....
document.body.appendChild(s);
HushamMohamed
Occasional Contributor

Thanks, Yes that is a clever solution, for my second Question,  so now How can fire click events to push field names to the arcade expression.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Husham,

   This part of your code is already listening for the the user click:

$('.electionlist').on('shown.bs.collapse', function () {