Table of contents
Introduction to ArcGIS Maps SDK for JavaScript
ArcGIS Maps SDK for JavaScript is a JavaScript library developed by Esri for building interactive map applications. It provides rich map display, analysis and visualization functions and is suitable for various scenarios.
Currently, the ArcGIS Maps SDK for JavaScript is available in two main versions: 3.x and 4.x.
- ArcGIS Maps SDK for JavaScript 3.x version:
- Version 3.x is an old version of ArcGIS Maps SDK for JavaScript and is still widely used in some old projects.
- It is built based on the Dojo framework, provides powerful two-dimensional map display functions, and supports a variety of map services, layers, renderers, symbols, etc.
- Provides a wealth of map analysis tools and visualization components, including buffer analysis, path analysis, spatial query, heat map, etc.
- Version 3.x has been gradually replaced by version 4.x, and the official website has gradually stopped maintaining 3.x.
- In today's modular development, 3.x can no longer adapt to the current development model. If there are no old projects to maintain, we do not need to use 3.x. Therefore, we will focus on the 4.x version here.
- ArcGIS Maps SDK for JavaScript 4.x version:
- Version 4.x is the latest version of ArcGIS Maps SDK for JavaScript and is the main direction of future development.
- Version 4.x redesigns the architecture, uses modern Web technologies such as ES6 and TypeScript, and adopts a modular development approach.
- It provides more flexible and high-performance map display functions, supporting 2D and 3D maps.
Key features and capabilities of ArcGIS Maps SDK for JavaScript 4.x
-
Map display function:
- Supports loading of various basemaps and has interactive operations for map zooming, panning and rotation.
- Provides rich layer types, including vector layers, raster layers, dynamic layers, etc.
- Supports map symbolization, labels, and annotation.
-
Geospatial analysis capabilities:
- Provides powerful geoprocessing and analysis functions, such as buffer analysis, spatial query, route analysis, etc.
- Supports the visualization and rendering of geographical features, such as heat maps, clustering, etc.
-
3D map functions:
- Provides the ability to create and display 3D maps, and supports tilting, rotating and scaling 3D scenes.
- Supports adding 3D models, underground pipe networks, point clouds, etc. to 3D scenes.
-
User interaction and navigation features:
- Provides default map navigation controllers, including zoom controls, navigation buttons, and scale bars.
- Supports custom user interaction functions, such as map click events, drag-and-drop, etc.
-
Map style and configuration:
- Supports custom map styles, symbol libraries and color themes.
- The map's default view, initial extent, coordinate system, etc. can be set through the configuration file.
-
Map data and service integration:
- Supports loading various data sources, including geographic data formats (such as GeoJSON, KML, Shapefile, etc.) and services (such as ArcGIS Server services, WMS services, etc.).
- Supports integration with ArcGIS Online and ArcGIS Enterprise to access their rich map and data resources.
Comparison of AMD modules and ES modules
ArcGIS Maps SDK for JavaScript 4.x provides two ways to load modules: AMD modules and ES modules (supported by versions 4.17 and later). The advantages and disadvantages of the two loading methods are as follows:
-
AMD modules (asynchronous module definition):
- Pros: AMD is an asynchronous module loading mechanism for loading JavaScript modules. It is very suitable for use in legacy browsers and legacy systems, can be compatible with various browsers, and has strong cross-platform compatibility.
- Disadvantages: AMD's syntax is relatively complex and may be more cumbersome to use. It also requires an additional AMD loader library to load modules.
-
ES modules (ECMAScript modules):
- Pros: ES modules are the official modular system for JavaScript, known for their simplicity, ease of use, and static analysis. It uses standard
import
andexport
syntax to make code clearer and more maintainable, while supportingasync/await
modern JavaScript features such as . - Disadvantage: ES modules may not be fully supported in older browsers and need to be converted appropriately to provide compatibility.
- Pros: ES modules are the official modular system for JavaScript, known for their simplicity, ease of use, and static analysis. It uses standard
In Vue3, since Vue 3 uses modern browsers and ES6+ features, we recommend using ES modules. ES modules have a more concise, readable syntax and are more compatible with the Composition API in Vue 3.
Steps to use ArcGIS Maps SDK for JavaScript in Vue3
Create a Vue 3 project
1. Create a new ArcGISAPIProject folder and open it with vscode
npm create vite@latest
2. Open the terminal, enter create vite project in the terminal , enter the project name vite-vue3-arcgis
, select the vue framework, and select the JavaScript voice creation project
3. After successful creation, enter vite-vue3-arcgis
the folder and use to npm i
install dependencies
4. After the installation is successful, enter npm run dev
and run the project to check whether the basic framework is normal
Install ArcGIS Maps SDK for JavaScript
In the terminal, type npm install @arcgis/core
install ArcGIS Maps SDK for JavaScript
Create a map component
Before creating the map component, we first delete the content in App.vue provided by the framework by default, and delete the HelloWorld.vue component in the components folder. 1. Create a new
ArcGisMap.vue component in the components folder under the src folder.
2. Create a new div in the template of the ArcGisMap.vue component, set the id attribute to viewDiv, as the container of the map,
3. Import the required map module; if you want to display the map in the container, you need to import the Map and MapView modules provided by ArcGis
import Map from '@arcgis/core/Map.js';
import MapView from '@arcgis/core/views/MapView.js';
4. Create Map and MapView objects in the code and configure related parameters
Because the map is displayed in a div, our code needs to be implemented in onMounted. The code is as follows
onMounted(()=>{
initArcGisMap()
})
const initArcGisMap = () => {
const map = new Map({
basemap: "topo-vector"
});
const view = new MapView({
center: [-118.80500, 34.02700],
zoom: 13,
container: "viewDiv",
map: map
});
}
In this code, we first create a map
map object called :
new Map()
A map instance is created via .basemap: "topo-vector"
Indicates that the map uses the base map provided by ArcGIStopo-vector
, which is a vector topological map. Then, a map view object called
is created :view
new MapView()
A map view instance is created via .center: [-118.80500, 34.02700]
Indicates the initial center point position of the map view, where the longitude and latitude coordinates are set.zoom: 13
Indicates the initial zoom level of the map view, with larger values indicating closer zoom levels.container: "viewDiv"
Indicates that the map view will be rendered intoviewDiv
the HTML element with id.map: map
Indicates that the map view will use the object created abovemap
as its map instance.
5. Load the map component in App.vue
<template>
<ArcGisMap></ArcGisMap>
</template>
<script setup>
import ArcGisMap from './components/ArcGisMap.vue'
</script>
<style scoped>
</style>
When we run the program at this time, we find that the browser displays a blank space and does not load the map. This is because we did not add width and height to the div, so it displays empty. 6. Set the width and height of
viewDiv
<style scoped>
#viewDiv {
width: 100%;
height: 100vh;
}
</style>
Run the browser and you can see that we have loaded the map.
7. Clear the UI components that come with ArcGIS.
Although our map has been loaded, we found that there is a scroll bar on the right side. Pull the scroll bar down to the bottom. , we found that there is zoom-in, zoom-out and ArcGIS-related information below.
This is the information that comes with ArcGIS by default. We can view.ui.components = [];
clear this information through settings
. Add this code after the view instantiation view.ui.components = [];
to clear it .
const initArcGisMap = () => {
const map = new Map({
basemap: "topo-vector"
});
const view = new MapView({
center: [-118.80500, 34.02700],
zoom: 13,
container: "viewDiv",
map: map
});
view.ui.components = [];
}
view.ui.components = []
Used to remove default UI components in the map view
view.ui
A user interface object that represents a map view.components
The array stores the default UI components for displaying. By setting it to an empty array[]
, the default UI components are removed.
Refresh the browser, you can find that at this time our browser only has a full-screen map. At this
point, we have loaded the ArcGIS map in vue3. Okay, let’s stop here first. Let’s go into details in the next section. Learn about the properties and methods of Map and MapView used in our code in this section.