Coordinates X Y on pop up on Search Widget

524
2
Jump to solution
01-30-2023 04:01 AM
KARIMLABIDI
Occasional Contributor

Hello everybody,

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. 

With Arcade, I have a little problem on the script on the $feature X. 

<script id="X">
  
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));
}

</script>

 Could someone help me on this please?

0 Kudos
1 Solution

Accepted Solutions
KARIMLABIDI
Occasional Contributor

I found the solution, here the code:

 //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]
          
        };

And on the webmap:

KARIMLABIDI_0-1676036374984.png

 

View solution in original post

0 Kudos
2 Replies
KARIMLABIDI
Occasional Contributor

Nobody?

I would like something like that in my pop up when user find a feature. It is possible?

KARIMLABIDI_0-1675341192509.png

Thank you

0 Kudos
KARIMLABIDI
Occasional Contributor

I found the solution, here the code:

 //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]
          
        };

And on the webmap:

KARIMLABIDI_0-1676036374984.png

 

0 Kudos