<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Coordinates X Y on pop up on Search Widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1256971#M80220</link>
    <description>&lt;P&gt;I found the solution, here the code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; //TEMPLATE
  const template = {
          // autocasts as new PopupTemplate()
          title: "Arrêt N° {IDARRET} - {NOMARRET}",
          lastEditInfoEnabled : false,
          expressionInfos:  [
    {
      name: "Coord",
      title: "Coordonnées XY", 
      expression: 
      `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];
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
//var url = CreateWazeURL(latlon[0], latlon[1]);
//return round(latlon[0],2)+"-------"+ round(latlon[1],2);
    var a = 6378137; //demi grand axe de l'ellipsoide (m)
    var e = 0.08181919106; //première excentricité de l'ellipsoide
    var l0 = PI /180 * 3
    var lc = l0
    var phi0 = PI / 180 * 46.5   // latitude d origine en radian
    var phi1 = PI / 180 * 44   // 1er parallele automécoïque
    var phi2 = PI / 180 * 49    // 2eme parallele automécoïque
    
    var x0 = 700000; //coordonnées à l'origine
    var y0 = 6600000; //coordonnées à l'origine
    var long = latlon[0]
    var lat = latlon[1]
    var phi = (PI / 180) * long;
    var l = (PI / 180) * lat;
       
     //calcul des grandes normales
    var gN1 = a / Sqrt(1 - e * e * Sin(phi1) * Sin(phi1));
    var gN2 = a / Sqrt(1 - e * e * Sin(phi2) * Sin(phi2));
    
    //calculs des latitudes isométriques
        var gl1 = Log(Tan(PI / 4 + phi1 / 2) * Pow((1 - e * Sin(phi1)) / (1 + e * Sin(phi1)), e / 2));
        var gl2 = Log(Tan(PI / 4 + phi2 / 2) * Pow((1 - e * Sin(phi2)) / (1 + e * Sin(phi2)), e / 2));
        var gl0 = Log(Tan(PI / 4 + phi0 / 2) * Pow((1 - e * Sin(phi0)) / (1 + e * Sin(phi0)), e / 2));
        var gl = Log(Tan(PI / 4 + phi / 2) * Pow((1 - e * Sin(phi)) / (1 + e * Sin(phi)), e / 2));
 
 //calcul de l'exposant de la projection
        var n = (Log((gN2 * Cos(phi2)) / (gN1 * Cos(phi1)))) / (gl1 - gl2);//ok
    
    //calcul de la constante de projection
        var c = ((gN1 * Cos(phi1)) / n) * Exp(n * gl1);//ok
        //calcul des coordonnées
        var ys = y0 + c * Exp(-1 * n * gl0);
 
        var $x = x0 + c * Exp(-1 * n * gl) * Sin(n * (l - lc));
       // var y93 = ys - c * Exp(-1 * n * gl) * Cos(n * (l - lc));
    //var $x= (($c*exp(-$n*($lat_iso)))*sin($n*(latlon[0]-3)/180*PI)+$xs);
    var $y = ys - c * Exp(-1 * n * gl) * Cos(n * (l - lc));
    
    return round($x,2) +TextFormatting.NewLine+ round($y,2)`

 } ],
          content:
          [
            {
              // It is also possible to set the fieldInfos outside of the content
              // directly in the popupTemplate. If no fieldInfos is specifically set
              // in the content, it defaults to whatever may be set within the popupTemplate.
              type: "fields",
              fieldInfos: [
                {
                  fieldName: "ADRESSE",
                  label: "Adresse"
                },
                {
                  fieldName: "VILLE",
                  label: "Ville",
                },
                {
                  fieldName: "MNLP_HASTUS",
                  label: "MNLP Hastus",
                },   
                {
                fieldName: "expression/Coord",
                
              }          
              ],
             // expressionInfos: arcadeExpressionInfos
            }
          ],
          
          actions: [editPROD,editPROJ1,editPROJ2]
          
        };&lt;/LI-CODE&gt;&lt;P&gt;And on the webmap:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KARIMLABIDI_0-1676036374984.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62556iD7CC75C4298981CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KARIMLABIDI_0-1676036374984.png" alt="KARIMLABIDI_0-1676036374984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2023 13:39:49 GMT</pubDate>
    <dc:creator>KARIMLABIDI</dc:creator>
    <dc:date>2023-02-10T13:39:49Z</dc:date>
    <item>
      <title>Coordinates X Y on pop up on Search Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1252814#M80097</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;I would like to get X and Y on the pop up when user search a feature. I don't know if it's better to do this with Arcade expressions or with a event function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;With Arcade, I have a little problem on the script on the $feature X.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;&amp;lt;script id="X"&amp;gt;
  
function MetersToLon(x) {

    var originShift = 2.0 * PI * 6378137.0 / 2.0;

    var lon = (x HERE THE PROBLEM / originShift) * 180.0;
        
    return Round(lon, 3);
return MetersToLon(Round(Geometry($feature).X, 6));
}

&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Could someone help me on this please?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 12:01:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1252814#M80097</guid>
      <dc:creator>KARIMLABIDI</dc:creator>
      <dc:date>2023-01-30T12:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Coordinates X Y on pop up on Search Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1254288#M80147</link>
      <description>&lt;P&gt;Nobody?&lt;/P&gt;&lt;P&gt;I would like something like that in my pop up when user find a feature. It is possible?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KARIMLABIDI_0-1675341192509.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/61940i0F70B51F3A0CFA2F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KARIMLABIDI_0-1675341192509.png" alt="KARIMLABIDI_0-1675341192509.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 12:33:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1254288#M80147</guid>
      <dc:creator>KARIMLABIDI</dc:creator>
      <dc:date>2023-02-02T12:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Coordinates X Y on pop up on Search Widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1256971#M80220</link>
      <description>&lt;P&gt;I found the solution, here the code:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; //TEMPLATE
  const template = {
          // autocasts as new PopupTemplate()
          title: "Arrêt N° {IDARRET} - {NOMARRET}",
          lastEditInfoEnabled : false,
          expressionInfos:  [
    {
      name: "Coord",
      title: "Coordonnées XY", 
      expression: 
      `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];
}

var latlon = MetersToLatLon(Geometry($feature).X, Geometry($feature).Y);
//var url = CreateWazeURL(latlon[0], latlon[1]);
//return round(latlon[0],2)+"-------"+ round(latlon[1],2);
    var a = 6378137; //demi grand axe de l'ellipsoide (m)
    var e = 0.08181919106; //première excentricité de l'ellipsoide
    var l0 = PI /180 * 3
    var lc = l0
    var phi0 = PI / 180 * 46.5   // latitude d origine en radian
    var phi1 = PI / 180 * 44   // 1er parallele automécoïque
    var phi2 = PI / 180 * 49    // 2eme parallele automécoïque
    
    var x0 = 700000; //coordonnées à l'origine
    var y0 = 6600000; //coordonnées à l'origine
    var long = latlon[0]
    var lat = latlon[1]
    var phi = (PI / 180) * long;
    var l = (PI / 180) * lat;
       
     //calcul des grandes normales
    var gN1 = a / Sqrt(1 - e * e * Sin(phi1) * Sin(phi1));
    var gN2 = a / Sqrt(1 - e * e * Sin(phi2) * Sin(phi2));
    
    //calculs des latitudes isométriques
        var gl1 = Log(Tan(PI / 4 + phi1 / 2) * Pow((1 - e * Sin(phi1)) / (1 + e * Sin(phi1)), e / 2));
        var gl2 = Log(Tan(PI / 4 + phi2 / 2) * Pow((1 - e * Sin(phi2)) / (1 + e * Sin(phi2)), e / 2));
        var gl0 = Log(Tan(PI / 4 + phi0 / 2) * Pow((1 - e * Sin(phi0)) / (1 + e * Sin(phi0)), e / 2));
        var gl = Log(Tan(PI / 4 + phi / 2) * Pow((1 - e * Sin(phi)) / (1 + e * Sin(phi)), e / 2));
 
 //calcul de l'exposant de la projection
        var n = (Log((gN2 * Cos(phi2)) / (gN1 * Cos(phi1)))) / (gl1 - gl2);//ok
    
    //calcul de la constante de projection
        var c = ((gN1 * Cos(phi1)) / n) * Exp(n * gl1);//ok
        //calcul des coordonnées
        var ys = y0 + c * Exp(-1 * n * gl0);
 
        var $x = x0 + c * Exp(-1 * n * gl) * Sin(n * (l - lc));
       // var y93 = ys - c * Exp(-1 * n * gl) * Cos(n * (l - lc));
    //var $x= (($c*exp(-$n*($lat_iso)))*sin($n*(latlon[0]-3)/180*PI)+$xs);
    var $y = ys - c * Exp(-1 * n * gl) * Cos(n * (l - lc));
    
    return round($x,2) +TextFormatting.NewLine+ round($y,2)`

 } ],
          content:
          [
            {
              // It is also possible to set the fieldInfos outside of the content
              // directly in the popupTemplate. If no fieldInfos is specifically set
              // in the content, it defaults to whatever may be set within the popupTemplate.
              type: "fields",
              fieldInfos: [
                {
                  fieldName: "ADRESSE",
                  label: "Adresse"
                },
                {
                  fieldName: "VILLE",
                  label: "Ville",
                },
                {
                  fieldName: "MNLP_HASTUS",
                  label: "MNLP Hastus",
                },   
                {
                fieldName: "expression/Coord",
                
              }          
              ],
             // expressionInfos: arcadeExpressionInfos
            }
          ],
          
          actions: [editPROD,editPROJ1,editPROJ2]
          
        };&lt;/LI-CODE&gt;&lt;P&gt;And on the webmap:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KARIMLABIDI_0-1676036374984.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/62556iD7CC75C4298981CB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KARIMLABIDI_0-1676036374984.png" alt="KARIMLABIDI_0-1676036374984.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 13:39:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/coordinates-x-y-on-pop-up-on-search-widget/m-p/1256971#M80220</guid>
      <dc:creator>KARIMLABIDI</dc:creator>
      <dc:date>2023-02-10T13:39:49Z</dc:date>
    </item>
  </channel>
</rss>

