load custom modules in JSAPI 4.3

2373
5
Jump to solution
03-23-2017 12:27 PM
MaximeDemers
Occasional Contributor III

Hi,

I am new to Dojo and ArcGIS JSAPI. I am using version 4.3 and I would like to load a custom module stored in a .js file in a subdirectory.

I was trying to do just as this example: http://servicesbeta.esri.com/demos/using-classes-with-javascript/seatgeek-search/ , but it does not work. Dojo is trying to load my custom module from http://js.arcgis.com/4.3/dojo/scripts/MspTiledMapServiceLayer.js instead of using location.pathname.replace(/\/[^/]+$/, "") + "/scripts"

<script src="https://js.arcgis.com/4.3/"></script>

<script>
    var dojoConfig = {
        paths: { scripts: location.pathname.replace(/\/[^/]+$/, "") + "/scripts" }
    };
    require(["scripts/MspTiledMapServiceLayer"], function(MspTiledMapServiceLayer) {

        new MspTiledMapServiceLayer();

   });

</script>

This returns a 404 error at http://js.arcgis.com/4.3/dojo/scripts/MspTiledMapServiceLayer.js

What am I doing wrong? Thanks a lot for your help.

Maxime

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Occasional Contributor III

You need to add the dojoConfig before you the script tag for js api. like below.

<script type="text/javascript">
    var dojoConfig = {
        paths: { scripts: location.pathname.replace(/\/[^/]+$/, "") + "/scripts" }
    };
</script>
<script src="https://js.arcgis.com/4.3/"></script>
<script type="text/javascript">
   require(["scripts/MspTiledMapServiceLayer"], function(MspTiledMapServiceLayer) {
        new MspTiledMapServiceLayer();
   });
</script>

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

Can you post everything in your require and function?

0 Kudos
MaximeDemers
Occasional Contributor III

There is nothing else, it's a simple test file that should load a custom module.

0 Kudos
thejuskambi
Occasional Contributor III

You need to add the dojoConfig before you the script tag for js api. like below.

<script type="text/javascript">
    var dojoConfig = {
        paths: { scripts: location.pathname.replace(/\/[^/]+$/, "") + "/scripts" }
    };
</script>
<script src="https://js.arcgis.com/4.3/"></script>
<script type="text/javascript">
   require(["scripts/MspTiledMapServiceLayer"], function(MspTiledMapServiceLayer) {
        new MspTiledMapServiceLayer();
   });
</script>
MaximeDemers
Occasional Contributor III

Thank you for your answer.

I have an irrelevant question for you. How do you format code block like that? I can't find this option in the menu...

0 Kudos
thejuskambi
Occasional Contributor III

While editing/replying you will see a button with 3 dots, it will expand the options. In the "More" menu, select the "Syntax highlighter".

Which will open a window, where you can write your codes.