When using RequireJS to load a JavaScript library from a CDN, an example syntax is shown at https://github.com/requirejs/example-jquery-cdn:
requirejs.config({
"paths": {
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
}
});
How should the ArcGIS Server JS API be referenced? The page at https://developers.arcgis.com/javascript/ gives the syntax for a standard web page:
<script src="http://js.arcgis.com/3.12/"></script>
but when using RequireJS:
requirejs.config({
'paths': {
'arcgis': '//js.arcgis.com/3.12/'
}
});
this returns NetworkError: 404 Not Found - http://js.arcgis.com/3.12/.js
What is the correct syntax for referencing the ArcGIS Server JS API when using RequireJS?
2 Answers 2
You would do this
requirejs.config({
'paths': {
'esri': 'http://js.arcgis.com/3.12/esri',
'dojo': 'http://js.arcgis.com/3.12/dojo',
'dojox': 'http://js.arcgis.com/3.12/dojox',
'dijit': 'http://js.arcgis.com/3.12/dijit'
}
});
Then require your modules in AMD style like this
requirejs(["esri/dijit/BasemapGallery",
"dojo/dom",
"dijit/form/Button",
"dojox/grid/DataGrid"],
function(BasemapGallery, dom, Button, DataGrid){
});
Actually I found out that when I load ArcGIS API to my HTML then I can use require
like requireJS (but with '.js'
at the end)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
<link rel="stylesheet" href="css/custom_style.css">
<script src="http://js.arcgis.com/3.14/"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="app.js"></script>
<script>
require([
'dojo/parser',
'test.js',
'dijit/layout/BorderContainer', 'dijit/layout/ContentPane',
'dojo/domReady!'
], function(parser){
parser.parse();
...
});
</script>
</head>
<body class="claro">
...
</body>
</html>
And test.js is a javascript file I have on my localhost and it executes.
-
Thanks for the tip. But this question is actually about how to load the ArcGIS JS API (
http://js.arcgis.com/3.14/
) itself, not the test.js fileStephen Lead– Stephen Lead2015年07月19日 23:01:43 +00:00Commented Jul 19, 2015 at 23:01
Explore related questions
See similar questions with these tags.
define
andrequire
. Generally my experience of having to use Dojo because of the JS API's reliance on it has been bad.