An approach to ArcGIS API for JavaScript development--helloword

Source: Internet
Author: User
Tags map class script tag

1. Preface

The ArcGIS API for JavaScript 3.10 version uses Dojo 1.9.1. Dgrid upgrade to version 0.3.14. Put-selector version upgrade to 0.3.5 and Xstyle version upgrade to 0.1.3.

2. Build the first application Helloword

2.1. Create a simple HTML document

First, let's create a simple HTML document with examples such as:

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8">        <title>Helloword</title>    </Head>    <Body>    </Body></HTML>

2.2. Referenced ArcGIS API JavaScript

To start working with the ArcGIS API for JavaScript, add the following script and link to the tag:

<rel= "stylesheet"  href= "http://js.arcgis.com/3.12/esri/css/ Esri.css "><src=" http://js.arcgis.com/3.12/"> </script>

The script tag loads the ArcGIS API as a JavaScript library. When the version of the new JavaScript API is released, the new version number can be updated to match the new version of the API.

The ESRI.CSS style sheet contains the styles for ESRI-specific parts and components. For more information about this style sheet, see the CSS that is required on the Help topic .

The URLs for each of the different theme style sheets are as follows:

http://js.arcgis.com/3.12/dijit/themes/claro/claro.csshttp://js.arcgis.com/3.12/dijit/themes/tundra/ Tundra.csshttp://js.arcgis.com/3.12/dijit/themes/nihilo/nihilo.csshttp://js.arcgis.com/3.12/dijit/themes/soria /soria.css

2.3. Loading module

添加<SCRIPT>标签并loads the specified module from the API. The JavaScript code will be added directly within it.

< Script >     require (["esri/map"function(map) {...}); </ Script >

2.4. Make sure DOM is available

Use dojo/ domready ensure that the DOM is available before executing any code. Once the Dom is available, the function is passed to require () to run. The code for the function creates the map and adds a basemap.

 <Script>require (["Esri/map", "dojo/domready!"], function(MAP) {//code to create the map and add a basemap'll go here    }); </Script>

2.5. Create a map

By loading The map class of the Esri/map module , you can create a new map. the "Mapdiv" character is passed to map as the ID number of the div element that contains the map . and specify the properties of other maps, such as the Basemap and starting center point and zoom level, in the map initialization constructor.

var map;   " Esri/map ",  function  (map)  {       =  new  map (" Mapdiv " ,  {       Center:  [-56.049,  38.485 ],       zoom:  3 ,       basemap:  "Streets"     }    );

Other Basemap options are: "Satellite", "hybrid", "Topo", "gray", "Oceans", "OSM", "national-geographic". You can replace different basemaps by modifying the basemap in the sandbox. View additional map options to see more details about the map class.

2.6. Define page Content

Now that JavaScript has created a map in one place, the next step is to add the relevant HTML. In this example, theHTML page is very simple: the principal tag, which defines what is visible in the browser, and a single div element will be in the body of the map being created.

<class= "Claro">    <ID = "Mapdiv" ></ Div > </ Body >

2.7. Page Design

In this tutorial, the map needs to populate the browser window. To achieve this effect, you need to add the following CSS to the early page :

<style>     {      padding: 0;       margin: 0;       height: 100%;    }  

2.8. Full page code

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "Utf-8">        <title>Helloword</title>        <Linkrel= "stylesheet"href= "Http://js.arcgis.com/3.12/esri/css/esri.css">        <Scriptsrc= "http://js.arcgis.com/3.12/"></Script>        <Script>              varmap; Require (["Esri/map" ,  "dojo/domready!" ], function(map) {map=  NewMap ("Mapdiv", {center: [- 56.049 ,  38.485], zoom:3, Basemap:"Streets"                 });        }); </Script>        <style>html, body, #mapDiv{padding:0;margin:0;Height:100%;    }        </style>      </Head>    <Body>        <DivID= "Mapdiv"></Div>    </Body></HTML>
3. Reference links

Https://developers.arcgis.com/javascript/jshelp/intro_firstmap_amd.html

Https://developers.arcgis.com/javascript/jshelp/intro_firstmap.html

An approach to ArcGIS API for JavaScript development--helloword

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.