Select to view content in your preferred language

Requirements for using arcade geometry functions

167
0
10-29-2024 02:43 PM
Labels (1)
Pukawai
Emerging Contributor

I have been working on creating a link to Google StreetView with an Arcade expression. To get the bearing of the view angle i am using the NearestCoordinate function. This is working quite well when I use the function with a Street network line layer I found in ArcGIS Online, but I created my own much smaller layer by clipping out a small Area of interest from the large street network and published it from my account. When I use the same arcade expression with the  new small street layer, Arcade "crashes".

Is there some sort of requirement or something I need to do to my small dataset to make it play nice with the geometry function?

I have tried a different street layer that I also published, and it cause the same problem.

Here is a sample WebMap  I created to illustrate the problem, and the arcade expression is below. The first two lines contain the IDs for the two street layers, and the id for the point layer that the arcade is attached to is also listed for reference.

 

var strID ='9766aa6294ee40bf9ec5eadcf05105cc';    //San Bernardino County Street Network
//var strID = 'e439b5b8d3b04a4cb17c95c6d87bb982';    //BVES Street extract
//var polesID = '3943ab09f7c64cfda9fba4ee28678a96'

function MetersToLatLon(x, y) {
    // Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum
    // Fuente: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
    var originShift = 2.0 * PI * 6378137.0 / 2.0;

    var lon = (x / originShift) * 180.0;
    var lat = (y / originShift) * 180.0;

    lat = 180.0 / PI * (2.0 * Atan( Exp( lat * PI / 180.0)) - PI / 2.0);
    return [lat, lon];
}

function GetBearing(strID) {
    var roads = FeatureSetByPortalItem(
    Portal('https://www.arcgis.com'),
    strID,
    0,
    ['*'],
    true
    );

    var buf = BufferGeodetic($feature, 100, "feet")
    var intRoads = Intersects(roads, buf);
    var brg = 0.0;

    if (Count(intRoads) > 0){
        var nearestRoad = First(intRoads);
        var result = NearestCoordinate(nearestRoad, $feature);
        var coord = result.coordinate;
        brg = Bearing(coord, $feature);
    }
    
    return brg;
}


var brg = GetBearing(strID);
var x = Geometry($feature).x;
var y = Geometry($feature).y;
var coord = MetersToLatLon(x, y);

var strHTML ='<TABLE><TR>';
strHTML = strHTML + '<TD style="border: 1px solid black; background-color:#FFFFAA">';
strHTML = strHTML + '<A HREF="http://maps.google.com/maps?q=&layer=c&cbll=' + text(coord[0]) + ',' + Text(coord[1]); 
strHTML = strHTML + '&cbp=11,' + Text(brg) + ',0,0,0"> StreetView </A></TD>';

return { 
    type : 'text', 
    text : strHTML
}

 

 

0 Kudos
0 Replies