Document Maps JavaScript API Reference Manual Amap Official Layer Buildings

Buildings

AMap.Buildings

3D layer of building blocks. Construct a 3D layer object of building blocks, and set layer properties through BuildingLayerOpts

new AMap.Buildings(opts: BuildingLayerOpts)

Parameter

opts(BuildingLayerOpts): 3D layer parameters of building blocks

Attribute

Type

Description

wallColor

Array<String> | String

The color of the building block's side surface, supports rgba, rgb, hexadecimal, etc

roofColor

Array<String> | String

The color of the building block's top surface, supports rgba, rgb, hexadecimal, etc

heightFactor

Number

The height coefficient factor of the building block, default is 1, which is the normal height

styleOpts

BuildingStyleOptions

Fence and style settings of building blocks

zooms

[Number, Number]

Layer zoom level range, value range: [16.8, 20]

opacity

Number

The transparency of the layer, value range [0 ~ 1], 1 represents completely opaque, 0 represents completely transparent, default: 1

visible

Boolean

Whether the layer is visible, default: true

zIndex

Number

The order value of layer stacking, the larger the number, the higher the layer level, 1 represents the bottom layer. Default: 4

Demo

//Create building layer
var buildings = new AMap.Buildings({
  heightFactor: 1,
  wallColor: [255, 0, 0, 1],
  roofColor: "rgba(0,0,255,0.5)",
});
//Add building layer to map
var map = new AMap.Map("container", {
  viewMode: "3D", 
  pitch: 60, 
  rotation: -35, 
  layers: [buildings], 
  zoom: 17, 
  showBuildingBlock: false,
  showOversea: true, //Enable world Map
});

Method

setStyle(styleOpts)

Set building layer style

Parameter:

Attribute

Type

Description

styleOpts

Object

Building layer style

hideWithoutStyle

Boolean

Whether to hide buildings outside the fence

areas

Array<Object>

Fence information array

rejectTexture

Boolean

Whether to block the texture of the custom map

visible

Boolean

Whether the building blocks within this fence are visible

path

Array<Number>

Fence latitude and longitude list

color1

Array<String>String

The color of the top surface of the building blocks within the fence area, supports rgba, rgb, hexadecimal, etc

color2

Array<String>String

Color of the sides of buildings within the fence area, supports rgba, rgb, hexadecimal, etc

Demo:

var options = {
  hideWithoutStyle:false,//Whether to hide buildings outside the set area
    areas:[{ //Fence 1
      //visible:false,//Whether it is visible
      rejectTexture:true,//Whether to block the texture of custom maps
      color1: 'ffffff00',//Roof color
      color2: 'ffffcc00',//Floor color
      path: [[116.473606,39.995997],[116.473005,39.995482],[116.474179,39.996516],[116.473606,39.995997]]
   }, 
   { //Fence 2
      color1: 'ff99ff00',
      color2: 'ff999900',
      path: [[116.474609,39.993478],[116.474489,39.993495],[116.47469,39.99348],[116.474609,39.993478]]
  }]
};
buildings.setStyle(options); //This color scheme has higher priority than custom mapStyle

getOptions()

Get layer parameter information

return value: (Object) Layer Parameter Information

Demo:

buildings.getOptions();

getzIndex()

Get Layer Level

return value: (Number) zIndex Layer Level

Demo:

buildings.getzIndex();

setzIndex(zIndex)

Set the layer level, the higher the number, the higher the layer level

Parameter: zIndex (Number) Layer Level Value

Demo:

buildings.setzIndex(10);

getOpacity()

Get layer opacity

return value: (Number) Layer opacity

Demo:

buildings.getOpacity();

setOpacity(opacity)

Set the layer opacity, range [0 ~ 1], 1 means completely opaque, 0 means completely transparent

Parameter: opacity(Number) Layer opacity

Demo:

buildings.setOpacity(0.5);

getZooms()

Get the display level range of the layer, the default range is [2-30]

return value: ([Number, Number]The Displayable Level Range of This Layer

Demo:

buildings.getZooms()

setZooms(zooms)

Set the Displayable Level Range of This Layer

Parameter: zooms([Number, Number]The Displayable Level Range of This Layer

Demo:

buildings.setZooms([8,12]);

show()

Set Layer to Visible

Demo:

buildings.show();

hide()

Set Layer to Hidden

Demo:

buildings.hide();

destroy()

Destroy Layer

Demo:

buildings.destroy()