Search code examples
d3.jsarcgis-js-api

How to pass parameter from the .js file of D3 to .js file of Arcgis Api by JavaScript?


I use the D3 and ArcGIS API 3.19 to develop an interactive Web.In the.js file of ArcGis API, I use the following code to build an URL to get a .json.

    var timeinterval =geo;
    var locationURL="https://paleobiodb.org/data1.2/colls/list.json?lngmin=-125&lngmax=-60&latmin=25&latmax=50&limit=all&show=time&level=3";
    locationURL += "&"+"interval="+timeinterval;

In the .js file of D3, I ues double click to get the d.name.

var g=svg.selectAll("g")
        .data(partition.nodes(root))
         .enter().append("svg:g")
        .on("click", clicked)
        .on("dblclick",TransInterval);

In the function TransInterval, the first console.log()can get a output.but the second gets nothing.

var geo;//the global variable
function TransInterval(d){
   var wa= d.name;
   geo=wa;
   console.log(geo);
   return geo;
    };
   console.log(geo);

So,I want to know how to pass the d.name to a global variable,and can be use in .jsfile of the ArcGis API? Thank You!


Solution

  • I dont see any problem with the way you have written the code. The value from d.name will be assigned to variable geo when the function TransInterval is called.

    What you need to understand about JavaScript is, the variable are function scoped. So at the time the second console.log(geo) is executed, the function TransInterval might not have been called.