Select to view content in your preferred language

Using Arcane to set CIMPrimitiveOverride with if statement

130
6
a week ago
ChaosSteve
Emerging Contributor

I am working with primitive overrides to change the image URL of for a feature. I want to set the CIMPictureMarker based on an attribute. Eventually my if statement will grow more complex, but I am starting with a basic change out of the image URL.

I have created a script tag in my HTML to return a different image based on the value of an attribute

<script type="text/javascript" id="serviceTag">
if($feature.open){
return "https://myURL/order-green.png"
}else {
return "https://myURL/order-red.png"
}
</script>

Then I reference that element and put it into my valueExpressionInfo

const serviceArcade = document.getElementById("serviceTag").text;
const serviceOrderRenderer = {
type: "simple",
symbol: new CIMSymbol({
data: {
type: 'CIMSymbolReference',
primitiveOverrides: [
{
type: 'CIMPrimitiveOverride',
primitiveName: 'imageColorOverride',
propertyName: 'url',
valueExpressionInfo: {
type: 'CIMExpressionInfo',
expression: serviceArcade,
returnType: 'Default',
},
}
],
symbol: {
type: 'CIMPointSymbol',
primativeName: "imageMarker",
symbolLayers: [
{
type: "CIMPictureMarker",
enable: true,
primitiveName: 'imageColorOverride',
},
],
},
}
})
}

It gives me an errors saying ParsingError: Unexpected identifier. Why does it say it cant parse an if statement?

0 Kudos
6 Replies
CodyPatterson
Honored Contributor

Hey @ChaosSteve 

It may be because the if statements in Arcade are slightly different, would replacing your if statement with this be fruitful?

 

 

<script type="text/javascript" id="serviceTag">
    return IIf($feature.open, "https://myURL/order-green.png", "https://myURL/order-red.png");
</script>

 

 

 Cody

0 Kudos
ChaosSteve
Emerging Contributor

It looks like an attribute cannot be a boolean, so I have it set to a string. My new code is 

<script type="text/plain" id="serviceOrderTag">
return IIf($feature.open === "true", 'https://myURL/order-green.png',
'https://myURL/order-red.png');
</script>

This is working

KenBuja
MVP Esteemed Contributor

The Arcade samples use the "text/plain" attribute generally with inline scripts and the "text/javascript" attribute with external .js files. Does this fix your parsing error?

<script type="text/plain" id="serviceTag">
        if($feature.open){
            return "https://myURL/order-green.png"
        }else {
            return "https://myURL/order-red.png"
        }
</script>
0 Kudos
ChaosSteve
Emerging Contributor

This was also part of the issue

0 Kudos
ChaosSteve
Emerging Contributor

To follow up on this I am trying to add a string builder. It tells me a comma is expected on this formatting. Not sure if there is an issue with checking for null or if arcane has a different way to check

return IIf($feature.ageCategory != null, 'url.com/order-' + $feature.age + '.png', '//url/order-0.png'
0 Kudos
ChaosSteve
Emerging Contributor

Missing ending bracket. Fixed