Arcade: TextFormatting.NewLine

3169
2
Jump to solution
03-10-2022 12:54 PM
JamieHoffmann
New Contributor II

Is there a way to create spacing in-between line breaks for an Arcade expression?

Below is a script

//field in the point address feature layer
var geoid = $feature.GEOID

//WV Fixed Dec2020 v1 is the related table
var fcc = FeatureSetById($map, /* WV Fixed Dec2020 v1 */ "17f74d21aeb-layer-4")

//filter function to match all addresses that share the same blockcode
var filterStatement = "BlockCode = @geoid"

//variable for related table
var providers = Filter(fcc, filterStatement)

//build out pop-up 
var popupResult = ''
for (var f in providers) {
popupResult += " - " + f.ISP + " (" + f.Technology + ") " + " (" + f.Service + ") " + TextFormatting.NewLine
}


return popupResult

 

The final result currently looks like this:

- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (Asymmetric xDSL) (Residential | Commercial)
- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (ADSL2, ADSL2+) (Residential | Commercial)
- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (VDSL) (Residential | Commercial)
- ViaSat, Inc. | Viasat Inc | ViaSat, Inc. (Satellite) (Residential | Commercial)
- UNITED STATES CELLULAR CORPORATION | United States Cellular Corporation | Telephone and Data Systems, Inc. (Fixed Wireless) (Residential)
- GCI Communication Corp. | GCI Communication Corp. | GCI Holdings LLC (Satellite) (Commercial)
- HNS License Sub, LLC | HughesNet | Hughes Network Systems, LLC (Satellite) (Residential | Commercial)
- VSAT Systems, LLC. | VSAT Systems, LLC. | VSAT Systems, LLC (Satellite) (Residential | Commercial)

 

Desired outcome would look like this:

- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (Asymmetric xDSL) (Residential | Commercial)


- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (ADSL2, ADSL2+) (Residential | Commercial)


- Frontier Communications Corporation | Frontier Communications Corporation | Frontier Communications Corporation (VDSL) (Residential | Commercial)


- ViaSat, Inc. | Viasat Inc | ViaSat, Inc. (Satellite) (Residential | Commercial)


- UNITED STATES CELLULAR CORPORATION | United States Cellular Corporation | Telephone and Data Systems, Inc. (Fixed Wireless) (Residential)


- GCI Communication Corp. | GCI Communication Corp. | GCI Holdings LLC (Satellite) (Commercial)


- HNS License Sub, LLC | HughesNet | Hughes Network Systems, LLC (Satellite) (Residential | Commercial)


- VSAT Systems, LLC. | VSAT Systems, LLC. | VSAT Systems, LLC (Satellite) (Residential | Commercial)

 

Thanks!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

First things first: don't forget about the "code sample" button on here.

jcarlson_0-1646965565864.png

Second, you can definitely add line breaks like that. You could just take the current script and include two newlines at the end of your popupResult += ... line.

However, this method is a bit less than idea, because it creates space at the end of your popup that you don't need. I would suggest making use of the Concatenate function. Instead of building the popup string in your loop, just append to an array, and then generate the string from that.

Also, I like to suggest the use of template literals whenever possible, because it's just easier to read than all those + and " characters.

//field in the point address feature layer
var geoid = $feature.GEOID

//WV Fixed Dec2020 v1 is the related table
var fcc = FeatureSetById($map, /* WV Fixed Dec2020 v1 */ "17f74d21aeb-layer-4")

//filter function to match all addresses that share the same blockcode
var filterStatement = "BlockCode = @geoid"

//variable for related table
var providers = Filter(fcc, filterStatement)

var out_arr = []

//build out pop-up 
for (var f in providers) {
    Push(
        out_arr,
        `- ${f.ISP} (${f.Technology}) (${f.Service})`
    )
}

// Return all items in array, separated by two lines each
return Concatenate(out_arr, '\n\n')

And here's me testing it on a sample layer:

jcarlson_1-1646966203623.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

First things first: don't forget about the "code sample" button on here.

jcarlson_0-1646965565864.png

Second, you can definitely add line breaks like that. You could just take the current script and include two newlines at the end of your popupResult += ... line.

However, this method is a bit less than idea, because it creates space at the end of your popup that you don't need. I would suggest making use of the Concatenate function. Instead of building the popup string in your loop, just append to an array, and then generate the string from that.

Also, I like to suggest the use of template literals whenever possible, because it's just easier to read than all those + and " characters.

//field in the point address feature layer
var geoid = $feature.GEOID

//WV Fixed Dec2020 v1 is the related table
var fcc = FeatureSetById($map, /* WV Fixed Dec2020 v1 */ "17f74d21aeb-layer-4")

//filter function to match all addresses that share the same blockcode
var filterStatement = "BlockCode = @geoid"

//variable for related table
var providers = Filter(fcc, filterStatement)

var out_arr = []

//build out pop-up 
for (var f in providers) {
    Push(
        out_arr,
        `- ${f.ISP} (${f.Technology}) (${f.Service})`
    )
}

// Return all items in array, separated by two lines each
return Concatenate(out_arr, '\n\n')

And here's me testing it on a sample layer:

jcarlson_1-1646966203623.png

 

- Josh Carlson
Kendall County GIS
JamieHoffmann
New Contributor II

Well this was great insight. Thank you Josh!