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
Solved! Go to Solution.
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>
Can you post everything in your require and function?
There is nothing else, it's a simple test file that should load a custom module.
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>
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...
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.