Select to view content in your preferred language

Custom Symbology Using Arcade Question Issue

682
2
02-15-2024 12:34 PM
JonJones1
Frequent Contributor

Hi everyone,

I'm working on an ArcGIS Online map and I need some assistance with creating custom symbology using Arcade expressions. I have two fields in my dataset: 'Win/Loss' and 'MARTIN_OR_BLUE_WATER'. Here's what I'm trying to achieve:

  1. I want the points to be colored blue if the 'Win/Loss' field is 'Retained' or 'Win'.
  2. If the 'Win/Loss' field is 'Bid / Not Win', 'No Bid', or 'Loss', the points should be red.
  3. Additionally, I'd like the points to have a green outline if the 'MARTIN_OR_BLUE_WATER' field value is 'BLUE'.

I received a helpful response that provided the following Arcade expression solution, but all I get are gray points on the screen:

// Determine the point color based on 'Win/Loss' field values
var color = '';
If ($feature["Win/Loss"] == 'Retained' || $feature["Win/Loss"] == 'Win') {
    color = 'blue'; // If 'Retained' or 'Win', set color to blue
} Else If ($feature["Win/Loss"] == 'Bid / Not Win' || $feature["Win/Loss"] == 'No Bid' || $feature["Win/Loss"] == 'Loss') {
    color = 'red'; // If 'Bid / Not Win', 'No Bid', or 'Loss', set color to red
} Else {
    color = 'yellow'; // Default color if none of the conditions above are met
}

// Determine if the outline should be green based on 'MARTIN_OR_BLUE_WATER' field
var outlineColor = '';
If ($feature["MARTIN_OR_BLUE_WATER"] == 'BLUE WATER') {
    outlineColor = 'green'; // If 'MARTIN_OR_BLUE_WATER' is 'BLUE WATER', set outline color to green
} Else {
    outlineColor = ''; // No outline if condition is not met
}

// Construct the symbol with the determined color and outlineColor
var symbol = {
    "type": "simple-marker", // Use a simple marker symbol
    "color": color, // Set the fill color based on 'Win/Loss' field
    "outline": {
        "color": outlineColor, // Set the outline color based on 'MARTIN_OR_BLUE_WATER' field
        "width": 1 // Set the outline width (adjust as needed)
    }
};

Return symbol;


Any idea how to fix this code to get the desired results?   





0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

Arcade cannot return symbols like that. What you'll have to do is symbolize the returned values in the legend editor.

var output;
If ($feature["Win/Loss"] == 'Retained' || $feature["Win/Loss"] == 'Win') {
  output = 'blue'; 
} Else If ($feature["Win/Loss"] == 'Bid / Not Win' || $feature["Win/Loss"] == 'No Bid' || $feature["Win/Loss"] == 'Loss') {
  output = 'red';
} Else {
  output = 'yellow '; 
}
If ($feature["MARTIN_OR_BLUE_WATER"] == 'BLUE WATER') output += ' outlined';
return output;

 

0 Kudos
Amir-Sarrafzadeh-Arasi
Frequent Contributor

Dear JonJones,

I hope you are doing great,

 

For the issue you have mentioned the best approach can be utilizing Dictionary Renderer.

You can create a simple .stylx utlizing DB Browser for SQLite, but you need a little knowledge of Arcade.

I have published a sample map with points, as you want in ArcGIS Online, please check the below link.

https://where-tech.maps.arcgis.com/apps/mapviewer/index.html?layers=7b7b9e533bb644f89add272e7e3470d7

Please check carefully the table and values, and the colors on the map.

You have lots of freedom in Symbology Renderer, you can modify size of the points dynamicly, or add dynamic text and ......

Please check my Github link in the below to see more in details symbology renderer.

https://github.com/AmirSarrafzadeh/symbology_dictionary

I also attached below some useful links to get more in deep about dictionary renderer.

https://developers.arcgis.com/javascript/latest/api-reference/esri-renderers-DictionaryRenderer.html

https://developers.arcgis.com/net/styles-and-data-visualization/display-symbols-with-a-dictionary-re...

https://pro.arcgis.com/en/pro-app/3.1/help/mapping/layer-properties/dictionary-renderer.htm

 

Hope it helps

Best wishes

Amir Sarrafzadeh Arasi
0 Kudos