Loading API modules
Before you can create a Map object you must first reference the module that provides the map functionality. This is accomplished through the use of the require() function.
Before you begin adding code to the Sandbox, please remove the following code you see listed. To ensure that you remove the correct code, look for the <script> tag that contains the call to the require() function. You need to remove everything between the opening <script> and closing </script> tags. You will write the JavaScript code to create the map yourself:
<script>
var map;
require(["esri/map", "dojo/domReady!"], function(Map) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps,
navigate to http://arcg.is/1JVo6Wd
center: [-122.45, 37.75], // longitude, latitude
zoom: 13
});
});
</script>
The require() function is used to import resources into your web page. Various resources are provided by the ArcGIS API for JavaScript including the esri/map resource, which must be referenced before you can create a map or work with geometry, graphics, and symbols. Once you have a reference to esri/map you can use the Map constructor to create the map.
The modules you want to import must be contained within a new <script> tag. Add the following lines of code to the Sandbox inside the <head> tag:
<script>
require([], function() {
});
</script>
The require() function accepts an array of module names, followed by a (usually anonymous) callback function that will be executed when the resources that the modules represent are loaded and are available to the application.
The callback function's parameters are the alias names you will use to refer to the modules in your code. Therefore the first argument to the function will refer to the first module element in the array, the second argument will refer to the second module element in the array, and so on.
The argument names used inside the require() function's callback can be named anything you'd like. However, both ESRI and Dojo provide a list of preferred argument names and we recommend adhering to those lists to make it easier for others to understand your code.
For example, in the following code that you add, we provide a reference to the esri/map resource, and then inside the anonymous function we provide a preferred argument of Map. Each module that you reference in the require() function will have an associated argument which will provide your code with access to that module, with one main exception, which we will cover as follows:
<script> require(["esri/map"], function(Map) { }); </script>
- .NET之美:.NET關(guān)鍵技術(shù)深入解析
- Java程序設(shè)計(jì)與實(shí)踐教程(第2版)
- Java Web應(yīng)用開發(fā)技術(shù)與案例教程(第2版)
- Backbone.js Blueprints
- Mastering Ext JS
- Python時間序列預(yù)測
- Salesforce Reporting and Dashboards
- Getting Started with Eclipse Juno
- JavaScript程序設(shè)計(jì)(第2版)
- ArcGIS for Desktop Cookbook
- Citrix XenServer企業(yè)運(yùn)維實(shí)戰(zhàn)
- UX Design for Mobile
- Node.js實(shí)戰(zhàn):分布式系統(tǒng)中的后端服務(wù)開發(fā)
- PHP程序設(shè)計(jì)高級教程
- 開源網(wǎng)絡(luò)地圖可視化:基于Leaflet的在線地圖開發(fā)