Document Maps JavaScript API Advanced Tutorial Map 3D Map

3D Map

JS API 3D Map provides a new map view effect based on vector map data, offering support for map functions such as rotation and perspective tilt compared to 2D maps. The 3D map is developed based on WebGL, ensuring smoothness while adding support for functions like level-less zooming.

This chapter will introduce you to:

  • Enable 3D Map.
  • 3D Map Compatibility Instructions.

3D Map Example

User Guide

Enable 3D Map

To enable the 3D map view effect, you need to reference the JS API version 1.4.0 or above, and add the viewMode:'3D' property to the map during Map initialization.

var map = new AMap.Map('container', {
  pitch: 50, //Map pitch angle, effective range 0 degrees to 83 degrees
  viewMode: '3D', //Map mode
  rotateEnable: true, //Whether to enable map rotation interaction
  pitchEnable: true, //Whether to enable map tilt interaction
  zoom: 17, 
  showOversea: true, //Enable world Map
  rotation: -15, //Initial map clockwise rotation angle
  zooms: [2, 20], //Zoom level range displayed on the map
});
Prompt

rotateEnable and pitchEnable control the rotation and tilt interaction of the 3D map, the default value is true, see the interaction and events of the map for details.

Enable Map Zoom and Rotation Plugin

The functionality of the map can be extended by introducing plugins. This example uses AMap.plugin() for asynchronous loading. For more introduction methods, please refer to the plugin usage.

AMap.plugin(['AMap.ControlBar', 'AMap.ToolBar'], function () { //Asynchronous Loading Plugin
  var controlBar = new AMap.ControlBar({ //Map Rotation Control Plugin
      position: {
          right: '10px',
          top: '10px'
      }
  });
  map.addControl(controlBar);
  var toolBar = new AMap.ToolBar({ //Map Zoom Plugin
      position: {
          right: '40px',
          top: '110px'
      }
  });
  map.addControl(toolBar)
});
Prompt

The AMap.ControlBar and AMap.ToolBar plugins are tools for rotating and zooming the map. You can also freely choose related plugins according to your business needs. For details, see the plugin list.

3D Map Compatibility Information

  • Under the 3D map effect, if using custom raster images, it is necessary to ensure that the image resources returned by the raster image service have the Access-Control-Allow-Origin:* response Header, otherwise, custom raster images will not be able to load.
  • 3D maps are currently compatible with numerous browsers on multiple platforms such as Windows, Mac, iOS, and Android. However, since map rendering depends on front-end environments like WebGL, if the terminal environment cannot meet the requirements for 3D rendering, we will still use the original 2D view for rendering.
  • Starting from version v1.4 of JS API, 3D maps are supported. The components not supported in 3D view are as follows:

Name

Description

 PointSimplifier 

 AMmap UI Component, Mass Point Display Component

 PathSimplifier 

AMmap UI Component, Trajectory Display Component

 DistrictExplorer 

 AMmap UI Component, Administrative Division Browsing

 DistrictCluster 

 AMmap UI component, administrative district aggregation

Description of properties and methods involved in this chapter

AMap.Map

parameters/methods

Description

Type

Optional

Default

pitch

Map pitch angle, invalid in 2D map

Number

0-83

0

viewMode

Map mode

String

'2D' | '3D'

'2D'

rotateEnable

Enable map rotation interaction Interaction effect: Right mouse button + mouse circular rotation or keyboard Ctrl + mouse circular rotation

Boolean

true | false

true

pitchEnable

Enable map tilt interaction Interaction effect: Right mouse button + mouse up and down movement or keyboard Ctrl + mouse up and down movement

Boolean

true | false

true

rotation

Initial Map Clockwise Rotation Angle

Number

0-360

0

terrain

Enable Terrain Map

Boolean

true | false

false

AMap.plugin

parameters/methods

Description

Type

AMap.ControlBar()

Map Zoom Plugin

Function

AMap.ToolBar()

Map Rotation Control Plugin

Function