1

I am developing separate javascript widgets in different scripts and they work independently. However, when I try and put both scripts together, neither script works at all. So this brings me to my question, is there any way for me to easily integrate multiple Javascript ArcGIS scripts?

For example, if I only change the require statements from:

require([
        "esri/map",
        "esri/layers/FeatureLayer",
        "esri/dijit/PopupTemplate",
        "esri/request",
        "esri/geometry/Point",
        "esri/graphic",
        "dojo/on",
        "dojo/_base/array",
        "dojo/domReady!"
      ],

to:

require([
        "esri/map",
        "esri/tasks/RouteTask",
        "esri/tasks/RouteParameters",
        "esri/layers/FeatureLayer",
        "esri/dijit/PopupTemplate",
        "esri/request",
        "esri/geometry/Point",
        "esri/graphic",
        "dojo/on",
        "dojo/_base/array",
        "dojo/domReady!"
      ],

breaks all of my code. It gives me an error on the following line:

var popupTemplate = new PopupTemplate({
          title: "{title}",
          description: "{description}"
        });

In this case, when I say break I mean that the functional aspects of my code no longer work. It just shows an empty map, but none of my feature layers display anything.

  • Welcome to gis.SE. Can you provide some more details, such as the source code, a minimal example showing the problem, and details of what happens when you put them together (we know it doesn't work, but does it cause a crash, do something else, or have no apparent effect?). – BradHards Feb 10 '14 at 6:47
  • I have just edited my question! My apologies for the (previously) vague and poorly worded question. – yousuf soliman Feb 10 '14 at 9:04
  • What is the js error ? May be the order is not correct – user3120 Feb 10 '14 at 10:33
  • I am not at my machine now, but the JS error is something along the lines of no 'path' found for null. – yousuf soliman Feb 10 '14 at 15:48
  • How does the order affect the code? – yousuf soliman Feb 10 '14 at 15:49
2

My guess is although you've added additional classes to your require statement, you haven't added additional references to map them to meaning that they are mismatched. Each class you require maps to the reference you specify at the same position, so, the first required class maps to the first reference, the second to the second and so on.

I'm guessing the next part of your code looks something like this:

require([
        "esri/map",
        "esri/layers/FeatureLayer",
        "esri/dijit/PopupTemplate",
        "esri/request",
        "esri/geometry/Point",
        "esri/graphic",
        "dojo/on",
        "dojo/_base/array",
        "dojo/domReady!"
      ],
        Map,
        FeatureLayer,
        PopupTemplate,
        request,
        Point,
        graphic,
        on,
        ArrayUtils

This means that you can access the class esri/map using the reference Map. You can access the class esri/Layers/FeatureLayer using the reference FeatureLayer. And so on.

Therefore if you add some additional classes to your require statement, you need to add additional references. If you don't want / need references to a particular class, put it at the end so it doesn't misplace any others. I.e. domReady! is never mapped to a reference so it goes at the end so it won't misplace something.

Hope this helps, and if it's not the problem, post some more of your code.

  • Worked beautifully! – yousuf soliman Feb 11 '14 at 13:33
  • Glad to hear it! – Kate Feb 11 '14 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.