Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

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: ,
Posted on Wednesday, December 22, 2010 1:17 PM | Back to top


Comments on this post: Dojo and Separate JavaScript File

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net