Dojo and Separate JavaScript File
- by Bunch
For a project I needed to use the ArcGIS API for some mapping. To use this you need to use Dojo but in this case all it really comes down to is adding some require lines and a addOnLoad on your web page. At first everything was working great, the maps rendered and the various layers would populate as needed.
Once it was working I started moving the various javascript functions into their own files to keep everything nice and neat. Then the problems started, mainly the map would not show up any more. So that was a pretty big problem. Luckily the fix was pretty simple, just move the dojo.addOnLoad line into it’s own script tag. If I had the dojo.addOnLoad in the same script block as the various require lines it would not work as expected.
Works:
<script type="text/javascript" language="javascript" src="javascript/test.js" />
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.locator");
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.geometry");
</script>
<script type="text/javascript">
dojo.addOnLoad(init);
</script>
Does not work:
<script type="text/javascript" language="javascript" src="javascript/test.js" />
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.tasks.locator");
dojo.require("esri.tasks.query");
dojo.require("esri.tasks.geometry");
dojo.addOnLoad(init);
</script>
Technorati Tags: JavaScript,Dojo