- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Eric Pimpler Mark Lewin
- 385字
- 2021-07-02 15:48:58
Creating the map
The creation of a new map is done through esri/Map, which is a reference to the Map class found in the esri/Map module you imported in a previous step. Inside the require() function you're going to create new Map object using a constructor function. This constructor for the Map object accepts two parameters, including a reference to the <div> tag where the map will be placed on the web page as well as an options parameter that can be used to define various map setup options. The options parameter is defined as a JSON (JavaScript Object Notation) object that contains a set of key/value pairs.
Perhaps the most visible option is basemap, which allows you to select a pre-defined basemap from ArcGIS.com. Pre-defined basemaps include streets, satellite, hybrid, topo, gray, oceans, national-geographic, and osm.
The zoom option is used to define a starting zoom level for the map and is an integer value that corresponds to a pre-defined zoom scale level. The minZoom and maxZoom options define the largest and smallest scale zoom levels for the map, respectively. The center option specifies the center point of the map that will be displayed and takes a Point object containing a latitude/longitude coordinate pair. There are a number of additional options that you can pass in as parameters to the constructor for the Map object, to alter the behavior and appearance of the map.
First we'll create a global variable called map by adding the following highlighted line of code:
<script>
var map;
require(["esri/map", "dojo/domReady!"], function(Map) {
});
</script>
Then, add the following highlighted code block to the require() function. This line of code is the constructor for the new Map object. The first parameter passed into the constructor is a reference to the id of the <div> tag in the DOM where the map will appear. We haven't defined this <div> tag yet, but we'll do so in the next step. The second parameter passed into the Map constructor is a JSON object that defines options including the geographic coordinate that will serve as the center of the map, the zoom level, and the basemap: "topo":
require(["esri/map", "dojo/domReady!"], function(Map) { map = new Map("map", { basemap: "topo", center: [-122.19, 37.94], // longitude, latitude zoom: 6 }); });
- PHP 7底層設(shè)計(jì)與源碼實(shí)現(xiàn)
- Vue.js 2 and Bootstrap 4 Web Development
- NLTK基礎(chǔ)教程:用NLTK和Python庫(kù)構(gòu)建機(jī)器學(xué)習(xí)應(yīng)用
- PHP+MySQL網(wǎng)站開(kāi)發(fā)技術(shù)項(xiàng)目式教程(第2版)
- 零基礎(chǔ)學(xué)Java程序設(shè)計(jì)
- C程序設(shè)計(jì)實(shí)踐教程
- 劍指大數(shù)據(jù):企業(yè)級(jí)數(shù)據(jù)倉(cāng)庫(kù)項(xiàng)目實(shí)戰(zhàn)(在線教育版)
- CoffeeScript Application Development Cookbook
- Regression Analysis with Python
- Mastering Elixir
- Java Web從入門到精通(第2版)
- ASP.NET Core and Angular 2
- Java 9:Building Robust Modular Applications
- Java核心技術(shù)速學(xué)版(第3版)
- Apache Kafka 1.0 Cookbook