Select to view content in your preferred language

Combining Scripts

737
3
Jump to solution
05-15-2014 05:21 AM
JohnChurchill
New Contributor III
Hi,

     I'm just getting started with using the ArcGIS API for Javascript. I have been trying samples using the sandbox site. I've had some general trouble trying to combine the functionality of one sample with another. So what I'm looking for is some guidance in how to effectively combine these scripts.

For example, I brought up the measurement sample and I wanted to add a home button. So I added references to "esri/dijit/HomeButton" to the list in the "Require" function and added "HomeButton" to the function defined as the second argument in "Require" and then added code

var home = new HomeButton({
  map: map
}, "HomeButton");
home.startup();


at the end (before the final "});" near the end of the </script> tag.

It seems to make everything stop working if everything isn't in the right order and even putting it at the end means that it works up until that code snippet that I included runs (I can check by adding an "alert" popup and I see that it stops working).

Questions:
1. Should this work (if so, what am I doing wrong)?
2. Am I correct in assuming that listing these items (objects ?) in the wrong order will upset the script or should I be able to put that "HomeButton" anywhere in that list of arguments?

function(dom, Color, keys, parser, esriConfig, has, Map, SnappingManager, Measurement, FeatureLayer, SimpleRenderer, GeometryService, SimpleLineSymbol, SimpleFillSymbol, HomeButton){<lots of code>}
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
A good place to start is this blog, which should help you get up to speed on using AMD. I'm guessing what's going on is you have the HomeButton module out of place in the require statement. While you can leave off the arguments in the function section, any arguments will have to be in the same order as when they are called in the require part.  For example

        require([
        "esri/map", "esri/layers/FeatureLayer",
        "dojo/parser", "dijit/layout/BorderContainer", "dojo/domReady!"
        ], function (
        Map, FeatureLayer,
        parser
        ) {


I don't have an argument for "BoarderContainer, but it has to come after any modules that have an argument in the function section.

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor
A good place to start is this blog, which should help you get up to speed on using AMD. I'm guessing what's going on is you have the HomeButton module out of place in the require statement. While you can leave off the arguments in the function section, any arguments will have to be in the same order as when they are called in the require part.  For example

        require([
        "esri/map", "esri/layers/FeatureLayer",
        "dojo/parser", "dijit/layout/BorderContainer", "dojo/domReady!"
        ], function (
        Map, FeatureLayer,
        parser
        ) {


I don't have an argument for "BoarderContainer, but it has to come after any modules that have an argument in the function section.
0 Kudos
JohnChurchill
New Contributor III
Thanks Ken,

     I got it. I had to move the HomeButton directly after Map in order for it to work. I also found the blog post informative. That is the type of reading I am looking for to help me to make sense of this.
0 Kudos
KenBuja
MVP Esteemed Contributor
Glad to help. Don't forget to click the checkbox in the post to signify your question was answered. This will help others as they search for solutions for similar questions. See this page for more information.
0 Kudos