Using Street View Applications with ArcGIS

21907
48
07-16-2019 02:38 PM
PatrickHuls_SpatialNinja
Esri Regular Contributor
23 48 21.9K

For a variety of planning, engineering, or inspection workflows, you may want to leverage street view applications with ArcGIS in lieu of, or before sending someone to the field.  There are many options for integrating street view with ArcGIS.  In this blog we'll outline the options for using Esri Partner solutions as well as options for linking to Bing and Google within an ArcGIS web map pop-up.

Esri Partners

Esri has partners which offer integrated street view solutions with ArcGIS.  These street view solutions can be used directly in ArcGIS Enterprise/Online, ArcGIS Pro, or Web AppBuilder for ArcGIS. 

Cyclomedia - The Street SmartTM Widget for ArcGIS introduces high resolution street-level imagery to Web Apps that you build with the Web AppBuilder.

Mapillary -  With the Mapillary widget for ArcGIS, you can bring Mapillary's street-level imagery into custom web applications built with Web AppBuilder. 

GeoCam - 3D urban modeling for microwave line of sign analysis, macro/small cell RF propagation modeling, and road-based aerial fiber mapping.

Feature Pop-up Street View Hyperlinks

Using Arcade within feature pop-ups in a web map, you can dynamically build a URL hyperlink that will pass a map features coordinates to Google's Street View or Bing's StreetSide to automatically open up street view in a new browser tab and zoom you to a location. Here is how:

First, configure a pop-up for a feature layer in your web map and Add an attribute expression.

Second, use the following Arcade expression to create your hyperlink.

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

function AuxSphereToLatLon(x, y) {
Console("Converting...");
// Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
var rMajor = 6378137;
var shift = PI * rMajor;
Longitude = x / shift * 180.0;
Latitude = y / shift * 180.0;
Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
Console("4326 Spatial Reference - No Conversion Necessary");
Latitude = ArcadeY;
Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
Console("102100 Spatial Reference - Conversion Necessary");
AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

var url = "https://www.bing.com/maps?&style=x&cp=" + text(Latitude) + "~" + text(Longitude);
return url;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Let's break down the expression. The first section grabs the X and Y coordinates and the spatial reference from the feature's Geometry and stores them as variables.  Since these features are Lines, we'll grab the Centroid of the line $feature as the location we zoom to in street view.

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then we'll check the spatial reference system of the web map to see if the coordinates need converting to Lat and Long for use by Google or Bing. If the web map is in Web Mercator (102100) then the coordinates will be converted to Lat and Long.  If the web map is in WGS84 (4326) then no conversion necessary since the feature coordinates will already be in Lat and Long. 

function AuxSphereToLatLon(x, y) {
Console("Converting...");
// Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
var rMajor = 6378137;
var shift = PI * rMajor;
Longitude = x / shift * 180.0;
Latitude = y / shift * 180.0;
Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
Console("4326 Spatial Reference - No Conversion Necessary");
Latitude = ArcadeY;
Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
Console("102100 Spatial Reference - Conversion Necessary");
AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

And finally, we'll build the URL and return it as a hyperlink.  For Google, use the following syntax:

var url = "http://maps.google.com/maps?q=&layer=c&cbll=" + text(Latitude) + "," + text(Longitude);
return url;‍‍‍‍‍‍‍‍

And for Bing, use the following syntax:

var url = "https://www.bing.com/maps?&style=x&cp=" + text(Latitude) + "~" + text(Longitude);
return url;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Once you have your Arcade expression built, the X and Y geometry of the feature will be added to the street view URL.

The URL will come through as a hyperlink in your web map pop-up.

Patrick Huls

Solution Engineer Team Lead - Telecommunications

LinkedIn: Patrick Huls| Twitter: @SpatialNinja| GeoNet:Phuls-esristaff

48 Comments
RogerMesen-Delgado
Occasional Contributor

Nice blog. I'll try to do it. Thanks.

Rudolfde_Munnik
Esri Contributor

Dear Patrick,

Thank you for the great blog. There have been previous attempts to access Google Street View through WAB and other methods, but due to Google Terms and Conditions this method was not allowed. I refer to these previous posts:

https://esri.jiveon.com/docs/DOC-2991-google-street-view-widget-21-072016?commentID=60555

https://community.esri.com/thread/204535-usage-of-google-street-view-as-a-custom-widget

Has the Google Terms and Conditions changed to allowed the methods proposed through Arcade scripting? If it has changed it will be great to use legally.

Thanks

PatrickHuls_SpatialNinja
Esri Regular Contributor

Hi Rudolf de Munnik,

The Arcade expression only dynamically builds a URL hyperlink which takes you to street view in a new tab or window. The Google maps products are not being integrated with ArcGIS, unlike the previous Web AppBuilder widget.  The URL parameters to open street view at a location are supported in the Google Maps API: https://developers.google.com/maps/documentation/streetview/intro

The license terms are here: https://cloud.google.com/maps-platform/terms/

Rudolfde_Munnik
Esri Contributor

Hi Patrick Huls

Thank you for the feedback.

We have many clients that are interested in StreetView integration("loosely coupled") with the ArcGIS Platform. Now we can promote the method without having to worry about license terms.

Thank you for the post.

Regards

Rudolf

BrianShaw
New Contributor II

Hi Patrick,

Just tried this within a Web Map i have developed and it works great.

This web map feeds into a Web Application.

However the hyperlink within the popup does not carry through to the Web Application.

Just wondering if it is the case that this only works in a Web Map but, not a Web Application?

Thanks Brian

PatrickHuls_SpatialNinja
Esri Regular Contributor

It should carry through to the web app pop-up. What type of web app are you using? And ArcGIS configurable app, JS API, or something custom?

BrianShaw
New Contributor II

Patrick, 

Thanks for your reply and just to confirm the Web App is built using ArcGIS Onlines WebAppBuilder Launchpad template.

You are quite right that when you have the Feature layers visibility turned on in the Web map you can click on the Popup in the Web App and it does indeed carry through to the Web App.

I probably didn't explain the issue very well initially.

I have in this instance configured a Web App with the Query Widget enabled which allows users to select 2 values from the data and then run the Query which then zooms to and displays the features which match the query parameters.

As i only want users to see the features that match the Query results i have turned off the layers visibility on the Web Map.

However when i configure the Query Widget in the Web App to show the layers popup this does not display the GOOGLE STREET VIEW link in the popup.

The Query Widget does not seem to recognise the created Attribute Expression from the Web Map?

Hope this explains the issue a little better.

Any advice would be appreciated.

Thanks Again 

Brian

ScottShenberger
New Contributor III

Good Day

 So by using the arcade expression to pass google maps the lat long that does not violate the ToS of Google?

PatrickHuls_SpatialNinja
Esri Regular Contributor

Hi Scott, 

Here is Google's Terms of Use.

https://cloud.google.com/maps-platform/terms/#3-license

TravisBrousseau2
New Contributor III

I really like this workaround. Is there any way to filter out any interior building imagery that Google Street View sometimes has and only display the on-road imagery? Or if you have a building footprint, for it to snap to the nearest road centerline imagery?

Thanks

Travis

HughRound
New Contributor II

This works great in WAB!

However, I have not been able to get it to work in ArcGIS Pro, adding it as an expression in the pop-up configuration. The link will open Google maps but not pass the coordinates through. 

Am I missing something here?

DanielWade
New Contributor

Thanks for the write-up Patrick, we are testing this right now within our Tax Parcel layer popups on AGOL.

I have noticed a slight bug on some of the larger tax parcels. Since the script is pulling the Lat/Lon from the centroid of the parcel, most of our larger parcels (greater than 5 acres) create a link to a blank street view page even if there is street view imagery available. Does anyone have suggestions on how we could rectify this?

The attached image is an example of one of the street view links created on a large parcel. I'm assuming this is happening because the center of the parcel is so far from the road that Google assumes there is no street view available.Blank Street View link

Thanks!

AndrewThompsonTRC
New Contributor II

I thought this was a great solution until it broke a query I had configured in the WAB query widget, for a layer that wasn't even the one I had added these Arcade expressions to.  By broke, I mean nothing happened when you hit "apply." 

The funny (aggravating) thing was that I had a query set up for the layer with the Arcade expressions that worked fine.  Once I removed the Arcade expressions the query widget worked as expected for all layers.  Random.  Just putting this out there to see if anyone else has experienced this.

ColinJaeck
New Contributor

I know it's been a while but did you ever solve this issue? I'm having the same thing happen. It happens for every feature regardless of size. I've added a note for users of my app to click back onto the road section once street view opens. Still works (since its always close), but not an ideal user experience! Thanks

RickKostohryz
New Contributor

Hi Paul. I love this tool and have applied it to a few of my AGOL maps with success. However, I am getting an error when I add the code to the Arcade Attribute Expression box for a layer: 

Execution Error:Runtime Error: Cannot call member method on null. X

Had you run into this before? Any ideas?

Thanks,

Rick

RickKostohryz
New Contributor

Sorry- I meant Patrick, not Paul. Guess I conflated your name.

GaryBarden
New Contributor III

Hi Patrick, this is great. I have a custom pop-up written in HTML...how do I add this link into my custom pop-up?

PhilipClothier1
New Contributor

Hi Patrick...I would love this piece of work to be working in our ArcGIS Online environment, but as we use Ordnance Survey basemaps (WKID 27700) the on-the-fly calculation doesn't present the correct LAT/LON and opens blank Streetview page...I have struggled to find an answer to what needs changing in the code, so I was wondering if you knew...any ideas?

AdenilsonLustosa
New Contributor

Muito obrigado Patrick Huls

Você me ajudou muito com esse código e com o detalhamento dele.

Parabéns e obrigado.

Thank you very much Patrick Huls

You helped me a lot with this code and its detailing.

Congratulations and thanks.

TomManson
New Contributor III

Hi Philip,
Did you ever get this working with 27700? If not, I do have a SQL function that converts to WGS84 (required for Power BI), so I might have to cobble something together from that code. Give me a shout if you need it.
Tom

PhilipClothier1
New Contributor

Hi Tom,

 

Thanks for responding…No, I have been banging my head with this one and have still not been able to get the conversion correct. I would really appreciate if you can help and get some Arcade together to allow this conversion to calculate on the fly and project to the correct location when StreetView is launched.

 

Thanks

Phil

PhilipClothier1
New Contributor

Hi Tom,

Thanks for responding…No, I have been banging my head with this one and have still not been able to get the conversion correct.

I would really appreciate if you can help and get some Arcade together to allow this conversion to calculate on the fly.

Regards

Phil

Phil Clothier

GIS Lead

t 02392 249315

e phil.clothier@portsmouthwater.co.uk<mailto:phil.clothier@portsmouthwater.co.uk>

w www.portsmouthwater.co.uk<http://www.portsmouthwater.co.uk/>

GregoryHunt
New Contributor

@PatrickHuls_SpatialNinja - This is great! I had one of my Analysts implement this exact workflow within one of our WAB projects. I appreciate the flow and breakdown that you provide as it made it very easy to tackle. 

WennyiDing
New Contributor

HI @PhilipClothier1 , did you ever figure this out for WKID 27700? I am having the same issue with OS base maps!

Thanks,

PhilipClothier1
New Contributor

Hi WennyiDing...unfortunately not, but I have just chased Tom Manson who kindly offered to help me with this one to see if he has made any progress.

Thanks

TomManson
New Contributor III

All,

I've used this code (thanks @PatrickHuls_SpatialNinja ), with some other I found on the web, and I came up with this Arcade code that also works with OS BNG 27700 projections. Enjoy!

var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

//New functions
function BNGtoLatLng(East, North) {
/*Author: Sandy Motteram
--Date:   06 September 2012

--UDF adapted from javascript at http://www.bdcc.co.uk/LatLngToOSGB.js
--found on page http://mapki.com/wiki/Tools:Snippets

--Instructions:
--Latitude and Longitude are calculated based on BOTH the easting and northing values from the OSGB36
--This UDF takes both easting and northing values in OSGB36 projection and you must specify if a latitude or longitude co-ordinate should be returned.
--IT first converts E/N values to lat and long in OSGB36 projection, then converts those values to lat/lng in WGS84 projection

--Sample values below
--DECLARE @East INT, @North INT, @LatOrLng VARCHAR(3)
--SELECT @East = 529000, @North = 183650 --that combo should be the corner of Camden High St and Delancey St
*/
var Pi = 3.14159265358979323846;
var K0 = 0.9996012717; // grid scale factor on central meridean
var OriginLat  = 49.0;
var OriginLong = -2.0;
var OriginX =  400000; // 400 kM
var OriginY = -100000; // 100 kM
var a = 6377563.396;  // Airy Spheroid
var b = 6356256.910;

// compute interim values
a = a * K0;
b = b * K0;

var n1 = (a - b) / (a + b);
var n2 = n1 * n1;
var n3 = n2 * n1;

var lat = OriginLat * Pi / 180.0; // to radians

var e2 = (a * a - b * b) / (a * a); // first eccentricity
var ex = (a * a - b * b) / (b * b); // second eccentricity

var OriginNorthings = b * lat + b * (n1 * (1.0 + 5.0 * n1 * (1.0 + n1) / 4.0) * lat - 3.0 * n1 * (1.0 + n1 * (1.0 + 7.0 * n1 / 8.0)) * SIN(lat) * COS(lat) + (15.0 * n1 * (n1 + n2) / 8.0) * SIN(2.0 * lat) * COS(2.0 * lat) - (35.0 * n3 / 24.0) * SIN(3.0 * lat) * COS(3.0 * lat));

var northing = north - OriginY;
var easting  = east  - OriginX;

/* Evaluate M term: latitude of the northing on the centre meridian */

northing = northing + OriginNorthings;

var phid  = northing / (b*(1.0 + n1 + 5.0 * (n2 + n3) / 4.0)) - 1.0;
var phid2 = phid + 1.0;

// declaring here so not in loop
var nphid = 0;
var dnphid = 0;

    for(var i = 0; ABS(phid2 - phid) > 0.000001; i++) {
        phid = phid2;
        nphid = b * phid + b * (n1 * (1.0 + 5.0 * n1 * (1.0 + n1) / 4.0) * phid - 3.0 * n1 * (1.0 + n1 * (1.0 + 7.0 * n1 / 8.0)) * SIN(phid) * COS(phid) + (15.0 * n1 * (n1 + n2) / 8.0) * SIN(2.0 * phid) * COS(2.0 * phid) - (35.0 * n3 / 24.0) * SIN(3.0 * phid) * COS(3.0 * phid));
        dnphid = b * ((1.0 + n1 + 5.0 * (n2 + n3) / 4.0) - 3.0 * (n1 + n2 + 7.0 * n3 / 8.0) * COS(2.0 * phid) + (15.0 * (n2 + n3) / 4.0) * COS(4 * phid) - (35.0 * n3 / 8.0) * COS(6.0 * phid));
        phid2 = phid - (nphid - northing) / dnphid;
    }

var c = COS(phid);
var s = SIN(phid);
var t = TAN(phid);
var t2 = t * t;
var q2 = easting * easting;

var nu2 = (a * a) / (1.0 - e2 * s * s);
var nu = SQRT(nu2);

var nudivrho = a * a * c * c / (b * b) - c * c + 1.0;
var eta2 = nudivrho - 1;
var rho = nu / nudivrho;

var invnurho = ((1.0 - e2 * s * s) * (1.0 - e2 * s * s)) / (a * a * (1.0 - e2));

var lat = phid - t * q2 * invnurho / 2.0 + (q2 * q2 * (t / (24 * rho * nu2 * nu) * (5 + (3 * t2) + eta2 - (9 * t2 * eta2))));
var lon = (easting / (c * nu)) - (easting * q2 * ((nudivrho + 2.0 * t2) / (6.0 * nu2)) / (c * nu)) + (q2 * q2 * easting * (5 + (28 * t2) + (24 * t2 * t2)) / (120 * nu2 * nu2 * nu * c));


lat = lat * 180.0 / Pi;
lon = lon * 180.0 / Pi + OriginLong;

// Now convert the lat and long from OSGB36 to WGS84

var OGlat  = lat;
var OGlon  = lon;
var height = 24; // London's mean height above sea level is 24 metres. Adjust for other locations.

var deg2rad = Pi / 180;
var rad2deg = 180 / Pi;

// first off convert to radians
var radOGlat = OGlat * deg2rad;
var radOGlon = OGlon * deg2rad;

// these are the values for WGS84(GRS80) to OSGB36(Airy) 

var a2 = 6378137;             // WGS84_AXIS
var e2 = 0.00669438037928458; // WGS84_ECCENTRIC
var h  = height;              // height above datum (from $GPGGA sentence)
var a  = 6377563.396;         // OSGB_AXIS
var e  = 0.0066705397616;     // OSGB_ECCENTRIC
var xp = 446.448;
var yp = -125.157;
var zp = 542.06;
var xr = 0.1502;
var yr = 0.247;
var zr = 0.8421;
var s  = -20.4894;

// convert to cartesian; lat, lon are in radians
var sf = s * 0.000001;
var v = a / (sqrt(1 - (e * (SIN(radOGlat) * SIN(radOGlat)))));
var x = (v + h) * COS(radOGlat) * COS(radOGlon);
var y = (v + h) * COS(radOGlat) * SIN(radOGlon);
var z = ((1 - e) * v + h) * SIN(radOGlat);

// transform cartesian
var xrot = (xr / 3600) * deg2rad;
var yrot = (yr / 3600) * deg2rad;
var zrot = (zr / 3600) * deg2rad;
var hx = x + (x * sf) - (y * zrot) + (z * yrot) + xp;
var hy = (x * zrot) + y + (y * sf) - (z * xrot) + yp;
var hz = (-1 * x * yrot) + (y * xrot) + z + (z * sf) + zp;

// Convert back to lat, lon
var newLon = ATAN(hy / hx);
var p = SQRT((hx * hx) + (hy * hy));
var newLat = ATAN(hz / (p * (1 - e2)));
v = a2 / (SQRT(1 - e2 * (SIN(newLat) * SIN(newLat))));
var errvalue = 1.0;
var lat0 = 0;
    for(var i = 0; errvalue > 0.001; i++) {
        lat0 = ATAN((hz + e2 * v * SIN(newLat)) / p);
        errvalue = ABS(lat0 - newLat);
        newLat = lat0;
    }

    // convert back to degrees
    newLat = newLat * rad2deg;
    newLon = newLon * rad2deg;

var ReturnMe = 0;

/*    IF LatOrLng = 'Lat'
        ReturnMe = newLat
    IF LatOrLng = 'Lng'
        ReturnMe = newLon

    RETURN ReturnMe;*/
  Latitude = newLat;
  Longitude = newLon;
}

//End of new functions
function AuxSphereToLatLon(x, y) {
  Console("Converting...");
  // Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
  var rMajor = 6378137;
  var shift = PI * rMajor;
  Longitude = x / shift * 180.0;
  Latitude = y / shift * 180.0;
  Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
  Console("4326 Spatial Reference - No Conversion Necessary");
  Latitude = ArcadeY;
  Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
  Console("102100 Spatial Reference - Conversion Necessary");
  AuxSphereToLatLon(ArcadeX, ArcadeY);
} else if (ArcadeSr == 27700) {
  Console("27700 Spatial Reference - Conversion Necessary");
  BNGToLatLng(ArcadeX, ArcadeY);
} else {
  Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

var url = "https://maps.google.com/maps?q=&layer=c&cbll=" + text(Latitude) + "," + text(Longitude);
return url;

 

WennyiDing
New Contributor

Brilliant @TomManson, this worked an absolute treat.

Thank you!

Panagiotis
New Contributor II

Dear Patrick,

Many thanks for sharing this. I have been using this custom expression for the Google Street View link in a dashboard and this has been working great for Map Viewer Classic and Dashboard Classic.

However, after the recent (April 2021) updates in ArcGIS Online with the New Map Viewer and the New Dashboards, the link doesn't work and when testing it I'm getting the following message:

"Execution Error:Cannot create Geometry in this SpatialReference. Engine is using a different spatial reference."

Any ideas what might have changed and/or how the expression could be modified to work with the New Map Viewer and Dashboard?

Thank you,

Panos

kshahmmp
New Contributor II

Hi Patrick,

I tried to implement the arcade expression in the pop up but for some reason, it didn't dynamically create a hyperlink to the map coordinate that allows to click and view location in next browser tab. Did I miss anything to implement this functionality?

kshahmmp_0-1621457070108.png

 

Thanks,

Kush

kshahmmp
New Contributor II

Works now. Thanks.

AmandaBishopMCPAFL
Occasional Contributor II

@PatrickHuls_SpatialNinja 

After configuring the expression and adding to the pop-up attribute expressions list, I can add it perfectly to the default attribute pop-up.  When I try adding the expression to a custom attribute display, it doesn't work.  Any suggestions?

Amanda

kshahmmp
New Contributor II

Hi @AmandaBishopMCPAFL  - I just changed just the google url and it worked fine with the hyperlink.

var url = "https://google.com/maps/@" + text(Latitude) + "," + text(Longitude) + "," + "80m/data=!3m1!1e3";
return url;

Thanks,

Kush

Kyle_Crawford
New Contributor II

Hi @AmandaBishopMCPAFL  you will need to add the expression as a hyperlink when creating a custom attribute display. 

 

Kyle_Crawford_0-1621957996673.png

Thanks,

Kyle

AmandaBishopMCPAFL
Occasional Contributor II

@Kyle_Crawford 

I tried your suggestion and all I get is a blank screen.

AmandaBishopMCPAFL
Occasional Contributor II

@kshahmmp

I changed the url in the expression then used the expression as the hyperlink URL for the text "Google Streets View".  It takes me to the location on the aerial map view but not Streets View.  Also the location address doesn't show up in google.  Any way to correct this?

See pic attached

AmandaBishopMCPAFL_0-1621962983648.png

 

 

Kyle_Crawford
New Contributor II

@AmandaBishopMCPAFL 

The reason you are receiving a blank screen is that there is a limit to how far the location can be from the street in order to return StreetView data. In a quick test, this limitation seems to appear when the distance is greater than 135 ft. 

Kyle_Crawford
New Contributor II

Hey @Panagiotis

I have tested the custom expression for both Google StreetView and Bing using the most up-to-date map viewer and applications within ArcGIS Online and the links created do work. I suggest you check the spatial reference of your layer due to the example only supporting web maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100. Please review the spatial reference and let me know if you are still having an issue. Thanks!

AmandaBishopMCPAFL
Occasional Contributor II

@Kyle_Crawford 

I used your suggestion in combination with @kshahmmp suggestion, and it worked but I am still only seeing the aerial map view with no location populated in the results bar to the left.  See my post to kshahmmp above to view the pic example.

Thank you.

Kyle_Crawford
New Contributor II

@AmandaBishopMCPAFL 

I would suggest you test this in a different location and compare the results. At that specific location within your example, there is no street view data available in that area. 

AmandaBishopMCPAFL
Occasional Contributor II

@Kyle_Crawford 

So I just got around to testing this again and I used an address that I knew had developed streets in the neighborhood with options for google streets and the map took me to the aerial overview map with no location populated in the search bar.  See pic attached.

AmandaBishopMCPAFL_0-1622724638985.png

 

JonStahl1
New Contributor

Hi,  I am trying to add this function to a popup.  When I paste the code into the arcade window and test it, I get a "Parse Error:Line 3: Unexpected end of input"   I am new to arcade, so I am not sure what I did.  Any assistance would be appreciated.

 

Thanks,

 

Jon

Kyle_Crawford
New Contributor II

@JonStahl1  @AmandaBishopMCPAFL 

Please try placing the script below as an attribute expression and let me know the results. Thanks!

 

// Options are "Google Directions", "Google Panoramic", and "Google Pin"
var EndGoal = "Google Streetview"

var BaseUrl = Decode( EndGoal,
  "Google Streetview", " http://maps.google.com/maps?q=&layer=c&cbll=",
  "Invalid"
);

if (BaseUrl == "Invalid"){
  Console(EndGoal + " is an invalid value for EndGoal.");
}

// Convert Lines/Polygons to Points
var PointGeometry = Centroid(Geometry($feature));

var ArcadeX = PointGeometry.x;
var ArcadeY = PointGeometry.y;
var ArcadeSr = PointGeometry.spatialReference.wkid;
var Latitude, Longitude;

function AuxSphereToLatLon(x, y) {
  Console("Converting...");
  // Conversion based on http://dotnetfollower.com/wordpress/2011/07/javascript-how-to-convert-mercator-sphere-coordinates-to-latitude-and-longitude/
  var rMajor = 6378137;
  var shift = PI * rMajor;
  Longitude = x / shift * 180.0;
  Latitude = y / shift * 180.0;
  Latitude = 180 / PI * (2 * Atan(Exp(Latitude * PI / 180.0)) - PI / 2.0);
}

if (ArcadeSr == 4326) {
  Console("4326 Spatial Reference - No Conversion Necessary");
  Latitude = ArcadeY;
  Longitude = ArcadeX;
} else if (ArcadeSr == 102100) {
  Console("102100 Spatial Reference - Conversion Necessary");
  AuxSphereToLatLon(ArcadeX, ArcadeY);
} else {
  Console(ArcadeSr + " Spatial Reference is not supported - currently works with Web Maps where the basemap is in WGS84 (4326) or Web Mercator Auxiliary Sphere 102100");
}

//Build Url Link
function BuildLink(Url, Lat, Long) {
  return Url + text(Lat) + "," + text(Long);
}

BuildLink(BaseUrl, Latitude, Longitude);

 

 

 

 

AmandaBishopMCPAFL
Occasional Contributor II

@Kyle_Crawford 

I tried this in a new expression and added it to my pop-up configuration.  When I do a search for my address then find the location and click on the expression link from your code, It does take me to the location of the address but doesn't pin-point the physical address or bring up the streets view.  I have to grab the little man and hover him over the street near the house then drop him to go to street view.  I guess I was looking for a link that takes me directly to the streets view automatically.  See pics below

 

AmandaBishopMCPAFL_0-1625767387933.pngAmandaBishopMCPAFL_1-1625767454132.png

 

JonStahl1
New Contributor

@Kyle_Crawford @AmandaBishopMCPAFL 

I took the expression and tested it.  It did not return any errors like the first one I tried. (See screenshot)  I built the popup, the hyperlink does not activate.  I will continue to try it to see if there is something I missed.

 

JonStahl1_0-1625768007676.png

 

AmandaBishopMCPAFL
Occasional Contributor II

@JonStahl1 

You have to add the expression in the pop-up configuration first then add it to the pop-up.

Kyle_Crawford
New Contributor II

Here is a video that outlines the steps on how to utilize this attribute expression. If using a custom attribute expression you would add the expression name ie {expression/expr0} as a hyperlink. 

Panagiotis
New Contributor II

Hi @Kyle_Crawford,

In my web map I'm using hosted feature layers in British National Grid (27700) with Esri's basemaps in WGS84 (4326).

I can confirm that the issues I had previously with the (latest) Dashboard have been resolved after AGOL's June 2021 updates, and the script provided by @PatrickHuls_SpatialNinja in the original post works fine for me.

Thanks,

Panos

HamzaBounouidar
New Contributor

First, thanks a lot for the suggestions @PatrickHuls_SpatialNinja . 
I'm looking for an answer for a similar need (with Google Street View). So with last ToS, except the popup solution, we can't have a widget with a separate map (google), but still in the same tab, with billable key ?
Thanks in advance

About the Author
As a solutions engineer for the Telecommunications industry at Esri, I am responsible for understanding the technology needs of the telecom market, helping organizations with their geospatial strategy, and ensuring customer success with GIS. Prior to my work at Esri, I was a GIS Analyst with a consulting firm that worked closely with large utility, construction, and engineering firms on utility and telecom construction projects. There, I designed and built an enterprise wide location platform which incorporated server, desktop, web, and mobile components. Email: phuls@esri.com LinkedIn: Patrick Huls Twitter: @SpatialNinja