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.
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');
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
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
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.
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
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);
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.
Husham,
This part of your code is already listening for the the user click:
$('.electionlist').on('shown.bs.collapse', function () {