2

I used the below code to get the nearest one location from $feature, but I'm looking now to get nearest 4 records from $feature.

I tried with json object, arrayList, but having syntax errors. Not sure about the limitations of customization in Arcade.

var searchDist = 6000;
var storeAddress = Intersects(FeatureSetById($map, "storeAddressFeaturelayer_2246"), Buffer( $feature, searchDist, "meters"));
var cnt = Count(storeAddress); 
var x=0;
var nearestaddress;
var neardistance=0;
var addressDist=0;

for (var f in storeAddress {
  addressDist = Round(Distance(f, $feature, "meters"),3);
 if(x==0){
     neardistance=addressDist;
     nearestaddress = f.Address+",  "+f.PhoneNumber;
  }
 if(neardistance>addressDist && x==1){
     neardistance=addressDist;
     nearestaddress = f.Address +",  "+f.PhoneNumber;
  }
  x=1;
 }

return nearestaddress;
0

I did this way,it may help other

var parcel = $feature;
    var searchDist = 200;
    var storeAddress = Intersects(FeatureSetByName($map,"Parcels_And_Buildings - Tax Parcels"), Buffer( $feature, searchDist, "meters"));
    var cnt = Count(storeAddress);
    Console(cnt);

    var dct = {};
    for (var address in storeAddress) {
        var addressDist = Round(Distance(address, $feature, "meters"), 3);
        var key = Text(addressDist, "000.000");
        Console(key);
        //address.Address + ",  " + address.PhoneNumber;
        var val = address.SITEADDRESS + ",  " + address.PARCELID + " (" + addressDist + "m)";
        for (var i = 0; i < 10; i++) {
            if (HasKey(dct, key)) {
                key += Text(i);
            } else {
                // skip;
            }
        }
        dct[key] = val;
    }

    var result = "";
    var mx = Min([cnt, 4]);
    var i = 0;
    for (var key in dct) {
        if (i < mx) {
            var val = dct[key];
            result += val + TextFormatting.NewLine;
        }
        i += 1;
    }
    return result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.