bpelchat

Lat/Lon In InfoWindow Content Example

Blog Post created by bpelchat on Jan 1, 2018

Here is one way to add x,y coordinates to the popup when using 3.23 custom template, the attached zip is a modification of the sample at ArcGIS API for JavaScript Sandbox

 

 

 

 

requires webmercatorutils, and modification of getTextContent

 

   require([
      "dojo/dom",
      "dojo/dom-construct",
      "dojo/_base/lang",
      "esri/map",
      "myModules/InfoWindow",
      "esri/layers/FeatureLayer",
      "esri/InfoTemplate",
      "esri/geometry/webMercatorUtils",
      "dojo/string",
      "dojo/domReady!"
    ], function(
       dom,
       domConstruct,
       lang,
       Map,
       InfoWindow,
       FeatureLayer,
       InfoTemplate,
       webMercatorUtils,
       string
    ) {
      //create the custom info window specifying any input options
       var infoWindow = new  InfoWindow({
          domNode: domConstruct.create("div", null, dom.byId("mapDiv"))
       });

//function changed to include graphic geometry in Lat/Lat


      function getTextContent(graphic){
        var geoPt = webMercatorUtils.webMercatorToGeographic(graphic.geometry);
        var lon = (geoPt.x).toFixed(4);
        var lat = (geoPt.y).toFixed(4);
        var latLonStr="";
        latLonStr =  lat + "," + lon;

        var attr = graphic.attributes.qSpecies.replace('"',"");
        var names=attr.split("::");
        var commName = string.trim(names[1].replace('"',""));
        var hlink = names[0].split(" ");
        var sciName = hlink[0] + "_" + hlink[1];
        if(commName === ""){
          commName = names[0];
        }
       
        return "<b>" + commName + "<br><span>Lat/Lon:</span><br>" + latLonStr + "</b><br /><a target='_blank' href=https://en.wikipedia.org/wiki/" + sciName  +">Wikipedia Entry</a>";
      }

Outcomes