ArcGIS API for JavaScript (1)-Introduction and Basic Web Map setup (with source)

Source: Internet
Author: User

1. Introduction

ArcGIS API for JavaScript (JavaScript API) is a set of scripts that ESRI calls the ArcGIS Server REST API interface, based on JavaScript technology. The latest version of the current edition is versions 3.17. ArcGIS API for JavaScript allows you to embed map resources provided by ArcGIS server into your Web app. ArcGIS API for JavaScript is based on the Dojo framework and uses a lot of dojo technology, so if you want to master API usage, you need to have a deep understanding of the Dojo framework! Dojo and our usual jquery are packaged JavaScript libraries, except that Dojo is a heavyweight development framework, composed of the framework core (dojo), the basic Control Library (DIJIT), the expansion pack (Dojox), and the three parts are provided by dojo officials. While jquery is a lightweight framework, it contains only the core of the framework. In a nutshell, Dojo is more like a class library, where different functions are encapsulated into different modules to form a separate JS file, which is then introduced if the function is used.

2.API and SDK acquisition and localization deployment

ArcGIS API for JavaScript provides an online version of the API, but the access speed is erratic due to the network being walled. So we're right. APIs (development packages) and SDKs (instances) for localized deployment. Localized deployment is recommended. The ArcGIS JavaScript API is available from the ESRI website, including APIs and SDKs (SDK contains API help and examples). To get the API and SDK, you need to register an ESRI global account first. Here I have found a collection of various API versions on the Internet, available to everyone to download. Baidu Network disk: Http://pan.baidu.com/s/1nuj0jix
Take IIS localization deployment as an example (arcgisjs3.16, for example, two days prior to 3.17 release with 3.16 changes not much)

There is an official deployment document in the API folder Arcgis_js_api\library\3.16\install_win.html, the process is as follows

1. Copy \arcgis_js_api\library all the folders to your Web server, such as copy to the default Web site,C:\Inetpub\wwwroot\arcgis_js_api\library
2. Localization configuration:

    • Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.16\3.16\init.js find ‘[HOSTNAME_AND_PATH_TO_JSAPI]‘ , replace with"<myserver>/arcgis_js_api/library/3.16/3.16/",例如"127.0.0.1/arcgis_js_api/library/3.16/3.16"
    • Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.16\3.16\dojo\dojo.js find ‘[HOSTNAME_AND_PATH_TO_JSAPI]‘ , replace with"<myserver>/arcgis_js_api/library/3.16/3.16/"例如"127.0.0.1/arcgis_js_api/library/3.16/3.16"

其他部署方案请参考install_win.html中官方的部署文档。

3.ArcGIS JavaScript api--Map Initialization

A. Need to introduce the base class library and style in the page

<link rel= "stylesheet" href= "Http://127.0.0.1/arcgis_js_api/library/3.16/3.16/dijit/themes/claro/claro.css"/ ><link rel= "stylesheet" type= "Text/css" href= "http://127.0.0.1/arcgis_js_api/library/3.16/3.16/esri/css/ Esri.css "/><script type=" Text/javascript "src=" Http://127.0.0.1/arcgis_js_api/library/3.16/3.16/init.js " ></script>

If you use the online API directly, you can change http://127.0.0.1/arcgis_js_api/library/3.16 tohttps://js.arcgis.com/为了大家测试方便,源码中使用在线API

B. Defining a map container

<body class= "Claro" >      <div id= "map" >      </div>  

C. Introducing the base class package for map initialization

As mentioned in the introduction, Dojo is based on modularity. Simple initialization of maps using "Esri/map" and "dojo/domready!" Introduced in the JS script

Require (["Esri/map", "dojo/domready!"], function (map) {//Initialize <DIV id= "map" ></div> map container  var map = new Map ("Map", {    Center: [ -118, 34.5],    zoom:8,    basemap: "Topo"  });

完整代码:

<! DOCTYPE html>

Effects such as:


4.ArcGIS JavaScript api--Map basic ability to achieve

Implementation features: Chinese basemap loading and satellite image switching, return to initialize map, Html5 positioning function, Eagle eye, scale.

完整代码:

<! DOCTYPE html>

Effects such as:

problem: Chinese basemap loading and satellite imagery can not coincide , I hope you point out

5.ArcGIS JavaScript api--Multi-basemap switching

Using "Esri/dijit/basemapgallery" for multi-basemap switching

完整代码:

<! DOCTYPE html>

Effects such as:

problem: basemap switch JS script will be error, I hope you point out

6. Summary

I am also a small white GIS, this time the main implementation of API deployment and basic map function implementation, the next I mainly talk about the ArcGIS Server publishing map service and call ArcGIS JavaScript API implementation Layer display and property information reading. Want to study with me GIS web development students pay attention to me!!!

Source Address: Http://pan.baidu.com/s/1dF5DHi5

Reference: API Document HTTPS://DEVELOPERS.ARCGIS.COM/JAVASCRIPT/3/

ArcGIS API for JavaScript (1)-Introduction and Basic Web Map setup (with source)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.