Hi.
My question is about ArcGIS JS Api.
For some reasons I need to run a function which inside the main function from outside of main function.
How can I do it? Is there any way to do it?
<script> require([ "esri/map", ... "dojo/domReady!" ], function( Map,... ) { var map = new Map("map", { center: [-56.049, 38.485], zoom: 3, basemap: "streets" }); function MyInnerFunction(){ //body of inner funcion } }); //End of the main function MyInnerFunction(); //Run inner function</script>
Solved! Go to Solution.
Not sure if anyone has a better approach but as long as dojo has finished loading you can use dojo.setObject() to expose the inner function.
<script> var map; require([ "esri/map", "dojo/domReady!" ], function(Map) { function myInnerFunction(){ alert("Hi from MyInnerFunction"); } dojo.setObject('myInnerFunction', myInnerFunction); map = new Map("map", { basemap: "topo", center: [-122.45, 37.75], // longitude, latitude zoom: 13 }); }); </script>
See this Simple Map with a button at the top left that calls a function within the require function.
Not sure if anyone has a better approach but as long as dojo has finished loading you can use dojo.setObject() to expose the inner function.
<script> var map; require([ "esri/map", "dojo/domReady!" ], function(Map) { function myInnerFunction(){ alert("Hi from MyInnerFunction"); } dojo.setObject('myInnerFunction', myInnerFunction); map = new Map("map", { basemap: "topo", center: [-122.45, 37.75], // longitude, latitude zoom: 13 }); }); </script>
See this Simple Map with a button at the top left that calls a function within the require function.
Thanks, Owen.
It worked perfectly for me.